From f2af45ccd334331bc24296abd921771470e8c7ca Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Fri, 15 Sep 2017 11:35:19 +0800 Subject: [PATCH] cleanup code. --- .../Dashboard/DashboardRoutes.cs | 89 +------------------ src/DotNetCore.CAP/Dashboard/HtmlHelper.cs | 42 +-------- .../Dashboard/JobHistoryRenderer.cs | 46 ---------- .../Pages/PublishedPage1.generated.cs | 2 +- .../Dashboard/Pages/ReceivedPage.generated.cs | 2 +- 5 files changed, 6 insertions(+), 175 deletions(-) diff --git a/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs b/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs index 662ace5..57f01f8 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs @@ -87,37 +87,7 @@ namespace DotNetCore.CAP.Dashboard var id = int.Parse(x.UriMatch.Groups["Id"].Value); var message = x.Storage.GetConnection().GetReceivedMessageAsync(id).GetAwaiter().GetResult(); return message.Content; - }); - //Routes.AddRazorPage("/jobs/enqueued", x => new QueuesPage()); - //Routes.AddRazorPage( - // "/jobs/enqueued/fetched/(?.+)", - // x => new FetchedJobsPage(x.Groups["Queue"].Value)); - - //Routes.AddClientBatchCommand("/jobs/enqueued/delete", (client, jobId) => client.ChangeState(jobId, CreateDeletedState())); - //Routes.AddClientBatchCommand("/jobs/enqueued/requeue", (client, jobId) => client.ChangeState(jobId, CreateEnqueuedState())); - - //Routes.AddRazorPage( - // "/jobs/enqueued/(?.+)", - // x => new EnqueuedJobsPage(x.Groups["Queue"].Value)); - - //Routes.AddRazorPage("/jobs/processing", x => new ProcessingJobsPage()); - //Routes.AddClientBatchCommand( - // "/jobs/processing/delete", - // (client, jobId) => client.ChangeState(jobId, CreateDeletedState(), ProcessingState.StateName)); - - //Routes.AddClientBatchCommand( - // "/jobs/processing/requeue", - // (client, jobId) => client.ChangeState(jobId, CreateEnqueuedState(), ProcessingState.StateName)); - - //Routes.AddRazorPage("/jobs/scheduled", x => new ScheduledJobsPage()); - - //Routes.AddClientBatchCommand( - // "/jobs/scheduled/enqueue", - // (client, jobId) => client.ChangeState(jobId, CreateEnqueuedState(), ScheduledState.StateName)); - - //Routes.AddClientBatchCommand( - // "/jobs/scheduled/delete", - // (client, jobId) => client.ChangeState(jobId, CreateDeletedState(), ScheduledState.StateName)); + }); Routes.AddPublishBatchCommand( "/published/requeue", @@ -132,55 +102,7 @@ namespace DotNetCore.CAP.Dashboard Routes.AddRazorPage( "/received/(?.+)", x => new ReceivedPage(x.Groups["StatusName"].Value)); - Routes.AddRazorPage("/subscribers", x => new SubscriberPage()); - //Routes.AddRazorPage("/jobs/failed", x => new FailedJobsPage()); - - //Routes.AddClientBatchCommand( - // "/jobs/failed/requeue", - // (client, jobId) => client.ChangeState(jobId, CreateEnqueuedState(), FailedState.StateName)); - - //Routes.AddClientBatchCommand( - // "/jobs/failed/delete", - // (client, jobId) => client.ChangeState(jobId, CreateDeletedState(), FailedState.StateName)); - - //Routes.AddRazorPage("/jobs/deleted", x => new DeletedJobsPage()); - - //Routes.AddClientBatchCommand( - // "/jobs/deleted/requeue", - // (client, jobId) => client.ChangeState(jobId, CreateEnqueuedState(), DeletedState.StateName)); - - //Routes.AddRazorPage("/jobs/awaiting", x => new AwaitingJobsPage()); - //Routes.AddClientBatchCommand("/jobs/awaiting/enqueue", (client, jobId) => client.ChangeState( - // jobId, CreateEnqueuedState(), AwaitingState.StateName)); - //Routes.AddClientBatchCommand("/jobs/awaiting/delete", (client, jobId) => client.ChangeState( - // jobId, CreateDeletedState(), AwaitingState.StateName)); - - //Routes.AddCommand( - // "/jobs/actions/requeue/(?.+)", - // context => - // { - // var client = new BackgroundJobClient(context.Storage); - // return client.ChangeState(context.UriMatch.Groups["JobId"].Value, CreateEnqueuedState()); - // }); - - //Routes.AddCommand( - // "/jobs/actions/delete/(?.+)", - // context => - // { - // var client = new BackgroundJobClient(context.Storage); - // return client.ChangeState(context.UriMatch.Groups["JobId"].Value, CreateDeletedState()); - // }); - - //Routes.AddRazorPage("/jobs/details/(?.+)", x => new JobDetailsPage(x.Groups["JobId"].Value)); - - //Routes.AddRazorPage("/recurring", x => new RecurringJobsPage()); - //Routes.AddRecurringBatchCommand( - // "/recurring/remove", - // (manager, jobId) => manager.RemoveIfExists(jobId)); - - //Routes.AddRecurringBatchCommand( - // "/recurring/trigger", - // (manager, jobId) => manager.Trigger(jobId)); + Routes.AddRazorPage("/subscribers", x => new SubscriberPage()); //Routes.AddRazorPage("/servers", x => new ServersPage()); //Routes.AddRazorPage("/retries", x => new RetriesPage()); @@ -200,14 +122,9 @@ namespace DotNetCore.CAP.Dashboard return $"{GetContentFolderNamespace(contentFolder)}.{resourceName}"; } - //private static DeletedState CreateDeletedState() - //{ - // return new DeletedState { Reason = "Triggered via Dashboard UI" }; - //} - private static EnqueuedState CreateEnqueuedState() { - return new EnqueuedState();// { Reason = "Triggered via Dashboard UI" }; + return new EnqueuedState(); } private static Assembly GetExecutingAssembly() diff --git a/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs b/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs index d60caca..274f751 100644 --- a/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs +++ b/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs @@ -29,7 +29,7 @@ namespace DotNetCore.CAP.Dashboard return RenderPartial(new Breadcrumbs(title, items)); } - public NonEscapedString JobsSidebar(MessageType type) + public NonEscapedString MessagesSidebar(MessageType type) { if (type == MessageType.Publish) { @@ -82,24 +82,6 @@ namespace DotNetCore.CAP.Dashboard return new NonEscapedString(value); } - public NonEscapedString JobId(string jobId, bool shorten = true) - { - Guid guid; - return new NonEscapedString(Guid.TryParse(jobId, out guid) - ? (shorten ? jobId.Substring(0, 8) + "…" : jobId) - : $"#{jobId}"); - } - - public string JobName(Message job) - { - if (job == null) - { - return Strings.Common_CannotFindTargetMethod; - } - - return job.ToString(); - } - public NonEscapedString StateLabel(string stateName) { if (String.IsNullOrWhiteSpace(stateName)) @@ -110,16 +92,6 @@ namespace DotNetCore.CAP.Dashboard return Raw($"{stateName}"); } - public NonEscapedString JobIdLink(string jobId) - { - return Raw($"{JobId(jobId)}"); - } - - public NonEscapedString JobNameLink(string jobId, Message job) - { - return Raw($"{HtmlEncode(JobName(job))}"); - } - public NonEscapedString RelativeTime(DateTime value) { return Raw($"{value}"); @@ -318,18 +290,6 @@ namespace DotNetCore.CAP.Dashboard return $"{value}"; } - //private static readonly StackTraceHtmlFragments StackTraceHtmlFragments = new StackTraceHtmlFragments - //{ - // BeforeFrame = "" , AfterFrame = "", - // BeforeType = "" , AfterType = "", - // BeforeMethod = "" , AfterMethod = "", - // BeforeParameters = "" , AfterParameters = "", - // BeforeParameterType = "", AfterParameterType = "", - // BeforeParameterName = "" , AfterParameterName = "", - // BeforeFile = "" , AfterFile = "", - // BeforeLine = "" , AfterLine = "", - //}; - public NonEscapedString StackTrace(string stackTrace) { try diff --git a/src/DotNetCore.CAP/Dashboard/JobHistoryRenderer.cs b/src/DotNetCore.CAP/Dashboard/JobHistoryRenderer.cs index a7197e6..c3a1589 100644 --- a/src/DotNetCore.CAP/Dashboard/JobHistoryRenderer.cs +++ b/src/DotNetCore.CAP/Dashboard/JobHistoryRenderer.cs @@ -24,8 +24,6 @@ namespace DotNetCore.CAP.Dashboard Register(SucceededState.StateName, SucceededRenderer); Register(FailedState.StateName, FailedRenderer); Register(ProcessingState.StateName, ProcessingRenderer); - Register(EnqueuedState.StateName, EnqueuedRenderer); - Register(ScheduledState.StateName, ScheduledRenderer); BackgroundStateColors.Add(EnqueuedState.StateName, "#F5F5F5"); BackgroundStateColors.Add(SucceededState.StateName, "#EDF7ED"); @@ -204,49 +202,5 @@ namespace DotNetCore.CAP.Dashboard return new NonEscapedString(builder.ToString()); } - - private static NonEscapedString EnqueuedRenderer(HtmlHelper helper, IDictionary stateData) - { - return new NonEscapedString( - $"
Queue:
{helper.QueueLabel(stateData["Queue"])}
"); - } - - private static NonEscapedString ScheduledRenderer(HtmlHelper helper, IDictionary stateData) - { - var enqueueAt = Helper.DeserializeDateTime(stateData["EnqueueAt"]); - - return new NonEscapedString( - $"
Enqueue at:
{enqueueAt}
"); - } - - private static NonEscapedString AwaitingRenderer(HtmlHelper helper, IDictionary stateData) - { - var builder = new StringBuilder(); - - builder.Append("
"); - - if (stateData.ContainsKey("ParentId")) - { - builder.Append($"
Parent
{helper.JobIdLink(stateData["ParentId"])}
"); - } - - if (stateData.ContainsKey("NextState")) - { - var nextState = JsonConvert.DeserializeObject( - stateData["NextState"], - new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); - - builder.Append($"
Next State
{helper.StateLabel(nextState.Name)}
"); - } - - if (stateData.ContainsKey("Options")) - { - builder.Append($"
Options
{helper.HtmlEncode(stateData["Options"])}
"); - } - - builder.Append("
"); - - return new NonEscapedString(builder.ToString()); - } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Dashboard/Pages/PublishedPage1.generated.cs b/src/DotNetCore.CAP/Dashboard/Pages/PublishedPage1.generated.cs index 297f2c5..89a19bb 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/PublishedPage1.generated.cs +++ b/src/DotNetCore.CAP/Dashboard/Pages/PublishedPage1.generated.cs @@ -104,7 +104,7 @@ WriteLiteral("\r\n
\r\n
\r\n #line 35 "..\..\Dashboard\Pages\PublishedPage.cshtml" - Write(Html.JobsSidebar(MessageType.Publish)); + Write(Html.MessagesSidebar(MessageType.Publish)); #line default diff --git a/src/DotNetCore.CAP/Dashboard/Pages/ReceivedPage.generated.cs b/src/DotNetCore.CAP/Dashboard/Pages/ReceivedPage.generated.cs index 04ec764..891678b 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/ReceivedPage.generated.cs +++ b/src/DotNetCore.CAP/Dashboard/Pages/ReceivedPage.generated.cs @@ -106,7 +106,7 @@ WriteLiteral("\r\n
\r\n
\r\n #line 37 "..\..\Dashboard\Pages\ReceivedPage.cshtml" - Write(Html.JobsSidebar(MessageType.Subscribe)); + Write(Html.MessagesSidebar(MessageType.Subscribe)); #line default