From a82790c1f5dc6899d185f48d79b2b510f356ea02 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Mon, 11 Sep 2017 18:43:05 +0800 Subject: [PATCH] add SubscriberPage --- .../Dashboard/DashboardContext.cs | 5 + .../Dashboard/DashboardRequest.cs | 3 +- .../Dashboard/DashboardRoutes.cs | 2 +- src/DotNetCore.CAP/Dashboard/HtmlHelper.cs | 67 ++++++ .../Dashboard/IDashboardDispatcher.cs | 2 +- .../Dashboard/IMonitoringApi.cs | 2 - .../Dashboard/Pages/SubscriberPage.cshtml | 31 ++- .../Pages/SubscriberPage.generated.cs | 221 ++++++++++++++++++ src/DotNetCore.CAP/Dashboard/RazorPage.cs | 4 + src/DotNetCore.CAP/DotNetCore.CAP.csproj | 3 + 10 files changed, 325 insertions(+), 15 deletions(-) create mode 100644 src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.generated.cs diff --git a/src/DotNetCore.CAP/Dashboard/DashboardContext.cs b/src/DotNetCore.CAP/Dashboard/DashboardContext.cs index 2a99fcd..44964b6 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardContext.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardContext.cs @@ -18,12 +18,16 @@ namespace DotNetCore.CAP.Dashboard } public IStorage Storage { get; } + public DashboardOptions Options { get; } public Match UriMatch { get; set; } public DashboardRequest Request { get; protected set; } + public DashboardResponse Response { get; protected set; } + + public IServiceProvider RequestServices { get; protected set; } } public sealed class CapDashboardContext : DashboardContext @@ -39,6 +43,7 @@ namespace DotNetCore.CAP.Dashboard HttpContext = httpContext; Request = new CapDashboardRequest(httpContext); Response = new CapDashboardResponse(httpContext); + RequestServices = httpContext.RequestServices; } public HttpContext HttpContext { get; } diff --git a/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs b/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs index fe54cf0..78f37a4 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs @@ -25,7 +25,7 @@ namespace DotNetCore.CAP.Dashboard public CapDashboardRequest(HttpContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); - _context = context; + _context = context; } public override string Method => _context.Request.Method; @@ -34,7 +34,6 @@ namespace DotNetCore.CAP.Dashboard public override string LocalIpAddress => _context.Connection.LocalIpAddress.ToString(); public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.ToString(); public override string GetQuery(string key) => _context.Request.Query[key]; - public override async Task> GetFormValuesAsync(string key) { var form = await _context.Request.ReadFormAsync(); diff --git a/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs b/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs index 69a19bf..baa5bcb 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs @@ -133,7 +133,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( diff --git a/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs b/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs index ca18a45..5aee212 100644 --- a/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs +++ b/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs @@ -218,6 +218,73 @@ namespace DotNetCore.CAP.Dashboard $"{shortenedId}"); } + public NonEscapedString MethodEscaped(MethodInfo method) + { + var outputString = string.Empty; + + var @public = "public "; + + var key = Hignlight(method.ReturnType); + + var name = method.Name; + + string paramType = null; + string paramName = null; + string paramString = string.Empty; + + var @params = method.GetParameters(); + if (@params.Length == 1) + { + var firstParam = @params[0]; + var firstParamType = firstParam.ParameterType; + paramType = Hignlight(firstParamType); + paramName = firstParam.Name; + } + + if (paramType == null) + { + paramString = "(){ }"; + } + else + { + paramString = $"({paramType} {paramName}){{ }}"; + } + + + outputString = @public + key + name + paramString; + return new NonEscapedString(outputString); + } + + public string Hignlight(Type type) + { + if(type.Name == "Void") + { + return HighligthKey(type.Name.ToLower()); + } + if (Helper.IsComplexType(type)) + { + return HighligthClass(type.Name); + } + if (type.IsPrimitive || type.Equals(typeof(string)) || type.Equals(typeof(decimal))) + { + return HighligthKey(type.Name.ToLower()); + } + else + { + return HighligthClass(type.Name); + } + } + + private string HighligthClass(string key) + { + return $"{key} "; + } + + private string HighligthKey(string key) + { + return $"{key} "; + } + //private static readonly StackTraceHtmlFragments StackTraceHtmlFragments = new StackTraceHtmlFragments //{ // BeforeFrame = "" , AfterFrame = "", diff --git a/src/DotNetCore.CAP/Dashboard/IDashboardDispatcher.cs b/src/DotNetCore.CAP/Dashboard/IDashboardDispatcher.cs index fec2faa..770ce90 100644 --- a/src/DotNetCore.CAP/Dashboard/IDashboardDispatcher.cs +++ b/src/DotNetCore.CAP/Dashboard/IDashboardDispatcher.cs @@ -7,6 +7,6 @@ namespace DotNetCore.CAP.Dashboard { public interface IDashboardDispatcher { - Task Dispatch( DashboardContext context); + Task Dispatch(DashboardContext context); } } diff --git a/src/DotNetCore.CAP/Dashboard/IMonitoringApi.cs b/src/DotNetCore.CAP/Dashboard/IMonitoringApi.cs index ab65c03..ee2d3ee 100644 --- a/src/DotNetCore.CAP/Dashboard/IMonitoringApi.cs +++ b/src/DotNetCore.CAP/Dashboard/IMonitoringApi.cs @@ -6,8 +6,6 @@ namespace DotNetCore.CAP.Dashboard { public interface IMonitoringApi { - IList Subscribers(); - StatisticsDto GetStatistics(); IList Messages(MessageQueryDto queryDto); diff --git a/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.cshtml b/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.cshtml index fb3c916..787b14e 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.cshtml +++ b/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.cshtml @@ -1,15 +1,14 @@ @* Generator: Template TypeVisibility: Internal GeneratePrettyNames: True *@ -@using System -@using System.Linq +@using DotNetCore.CAP.Internal @using DotNetCore.CAP.Dashboard @using DotNetCore.CAP.Dashboard.Pages @using DotNetCore.CAP.Dashboard.Resources @inherits RazorPage @{ - Layout = new LayoutPage(Strings.ServersPage_Title); + Layout = new LayoutPage(Strings.SubscribersPage_Title); - var monitor = Storage.GetMonitoringApi(); - var subscribers = monitor.Subscribers(); + var cache = RequestServices.GetService(typeof(MethodMatcherCache)) as MethodMatcherCache; + var subscribers = cache.GetCandidatesMethodsOfGroupNameGrouped(); }
@@ -28,16 +27,30 @@ - - + + @foreach (var subscriber in subscribers) { - - + + } diff --git a/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.generated.cs b/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.generated.cs new file mode 100644 index 0000000..0190f52 --- /dev/null +++ b/src/DotNetCore.CAP/Dashboard/Pages/SubscriberPage.generated.cs @@ -0,0 +1,221 @@ +#pragma warning disable 1591 +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DotNetCore.CAP.Dashboard.Pages +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + + #line 3 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + using DotNetCore.CAP.Dashboard; + + #line default + #line hidden + + #line 4 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + using DotNetCore.CAP.Dashboard.Pages; + + #line default + #line hidden + + #line 5 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + using DotNetCore.CAP.Dashboard.Resources; + + #line default + #line hidden + + #line 2 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + using DotNetCore.CAP.Internal; + + #line default + #line hidden + + [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")] + internal partial class SubscriberPage : RazorPage + { +#line hidden + + public override void Execute() + { + + +WriteLiteral("\r\n"); + + + + + + + + + #line 7 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + + Layout = new LayoutPage(Strings.SubscribersPage_Title); + + var cache = RequestServices.GetService(typeof(MethodMatcherCache)) as MethodMatcherCache; + var subscribers = cache.GetCandidatesMethodsOfGroupNameGrouped(); + + + + #line default + #line hidden +WriteLiteral("\r\n
\r\n
\r\n

订阅列表

\r\n\r\n"); + + + + #line 18 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + if (subscribers.Count == 0) + { + + + #line default + #line hidden +WriteLiteral("
\r\n "); + + + + #line 21 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + Write(Strings.ServersPage_NoServers); + + + #line default + #line hidden +WriteLiteral("\r\n
\r\n"); + + + + #line 23 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + } + else + { + + + #line default + #line hidden +WriteLiteral(@"
+
名称方法分组 + +
@subscriber.Name@subscriber.Method@subscriber.Key + + @foreach (var column in subscriber.Value) + { + + + + + } + +
+ + + + + + + +"); + + + + #line 37 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + foreach (var subscriber in subscribers) + { + + + #line default + #line hidden +WriteLiteral(" \r\n \r\n \r\n"); + + + + #line 55 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + } + + + #line default + #line hidden +WriteLiteral(" \r\n
分组 +
名称方法
+
"); + + + + #line 40 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + Write(subscriber.Key); + + + #line default + #line hidden +WriteLiteral("\r\n " + +"\r\n"); + + + + #line 43 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + foreach (var column in subscriber.Value) + { + + + #line default + #line hidden +WriteLiteral(" \r\n " + +" \r\n \r\n " + +" \r\n"); + + + + #line 51 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + } + + + #line default + #line hidden +WriteLiteral("
"); + + + + #line 46 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + Write(column.Attribute.Name); + + + #line default + #line hidden +WriteLiteral(""); + + + + #line 47 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + Write(column.ImplTypeInfo.Name); + + + #line default + #line hidden +WriteLiteral(": \r\n "); + + + + #line 48 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + Write(Html.MethodEscaped(column.MethodInfo)); + + + #line default + #line hidden +WriteLiteral("\r\n
\r\n \r\n
\r\n
\r\n"); + + + + #line 59 "..\..\Dashboard\Pages\SubscriberPage.cshtml" + } + + + #line default + #line hidden +WriteLiteral(" \r\n"); + + + } + } +} +#pragma warning restore 1591 diff --git a/src/DotNetCore.CAP/Dashboard/RazorPage.cs b/src/DotNetCore.CAP/Dashboard/RazorPage.cs index b69b730..b7b65e3 100644 --- a/src/DotNetCore.CAP/Dashboard/RazorPage.cs +++ b/src/DotNetCore.CAP/Dashboard/RazorPage.cs @@ -41,6 +41,8 @@ namespace DotNetCore.CAP.Dashboard internal DashboardRequest Request { private get; set; } internal DashboardResponse Response { private get; set; } + internal IServiceProvider RequestServices { get; private set; } + public string RequestPath => Request.Path; /// @@ -65,6 +67,7 @@ namespace DotNetCore.CAP.Dashboard AppPath = parentPage.AppPath; StatsPollingInterval = parentPage.StatsPollingInterval; Url = parentPage.Url; + RequestServices = parentPage.RequestServices; GenerationTime = parentPage.GenerationTime; _statisticsLazy = parentPage._statisticsLazy; @@ -74,6 +77,7 @@ namespace DotNetCore.CAP.Dashboard { Request = context.Request; Response = context.Response; + RequestServices = context.RequestServices; Storage = context.Storage; AppPath = context.Options.AppPath; diff --git a/src/DotNetCore.CAP/DotNetCore.CAP.csproj b/src/DotNetCore.CAP/DotNetCore.CAP.csproj index 8ee75eb..185b57b 100644 --- a/src/DotNetCore.CAP/DotNetCore.CAP.csproj +++ b/src/DotNetCore.CAP/DotNetCore.CAP.csproj @@ -123,6 +123,9 @@ HomePage.cshtml + + SubscriberPage.cshtml +