diff --git a/src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs b/src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs index 829ad21..973cdab 100644 --- a/src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs +++ b/src/DotNetCore.CAP/CAP.AppBuilderExtensions.cs @@ -1,7 +1,6 @@ using System; using DotNetCore.CAP; -using DotNetCore.CAP.Dashboard.GatewayProxy.Request.Middleware; -using DotNetCore.CAP.Dashboard.GatewayProxy.Requester.Middleware; +using DotNetCore.CAP.Dashboard.GatewayProxy; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; @@ -53,10 +52,8 @@ namespace Microsoft.AspNetCore.Builder app.Map(new PathString(pathMatch), x => { - x.UseDownstreamRequestInitialiser(); - x.UseHttpRequestBuilderMiddleware(); - x.UseHttpRequesterMiddleware(); x.UseMiddleware(); + x.UseMiddleware(); }); return app; diff --git a/src/DotNetCore.CAP/Dashboard/CAP.DashboardOptionsExtensions.cs b/src/DotNetCore.CAP/Dashboard/CAP.DashboardOptionsExtensions.cs index 7eb48cc..e4afbaa 100644 --- a/src/DotNetCore.CAP/Dashboard/CAP.DashboardOptionsExtensions.cs +++ b/src/DotNetCore.CAP/Dashboard/CAP.DashboardOptionsExtensions.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace DotNetCore.CAP { @@ -26,7 +24,8 @@ namespace DotNetCore.CAP services.AddSingleton(DashboardRoutes.Routes); services.AddSingleton(); services.AddSingleton(); - + services.AddSingleton(); + //services.AddScoped(); services.AddScoped(); } } diff --git a/src/DotNetCore.CAP/Dashboard/DashboardContext.cs b/src/DotNetCore.CAP/Dashboard/DashboardContext.cs index de6dd43..e0b8ecc 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardContext.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardContext.cs @@ -25,6 +25,8 @@ namespace DotNetCore.CAP.Dashboard public DashboardResponse Response { get; protected set; } + public ISession Session { get; protected set; } + public IServiceProvider RequestServices { get; protected set; } } @@ -42,6 +44,7 @@ namespace DotNetCore.CAP.Dashboard Request = new CapDashboardRequest(httpContext); Response = new CapDashboardResponse(httpContext); RequestServices = httpContext.RequestServices; + Session = httpContext.Session; } public HttpContext HttpContext { get; } diff --git a/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs b/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs index 33f3535..264ecdb 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardRequest.cs @@ -34,8 +34,8 @@ namespace DotNetCore.CAP.Dashboard public override string PathBase => _context.Request.PathBase.Value; 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 string GetQuery(string key) => _context.Request.Query[key]; public override async Task> GetFormValuesAsync(string key) { diff --git a/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs b/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs index e34fa6b..eb23a42 100644 --- a/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs +++ b/src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs @@ -107,7 +107,8 @@ namespace DotNetCore.CAP.Dashboard Routes.AddRazorPage("/subscribers", x => new SubscriberPage()); Routes.AddRazorPage("/nodes", x => new NodePage()); - + + Routes.AddRazorPage("/nodes/node/(?.+)", x => new NodePage(x.Groups["Id"].Value)); #endregion Razor pages and commands } diff --git a/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs b/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs index 274f751..1a4c33c 100644 --- a/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs +++ b/src/DotNetCore.CAP/Dashboard/HtmlHelper.cs @@ -190,6 +190,12 @@ namespace DotNetCore.CAP.Dashboard $"{shortenedId}"); } + public NonEscapedString NodeSwitchLink(string id) + { + return Raw($"{Strings.NodePage_Switch}"); + } + + #region MethodEscaped public NonEscapedString MethodEscaped(MethodInfo method) { var outputString = string.Empty; @@ -288,7 +294,8 @@ namespace DotNetCore.CAP.Dashboard private string Span(string @class, string value) { return $"{value}"; - } + } + #endregion public NonEscapedString StackTrace(string stackTrace) { diff --git a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs index ec5fb01..0d79ca3 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs +++ b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs @@ -8,6 +8,19 @@ namespace DotNetCore.CAP.Dashboard.Pages partial class NodePage { private IList _nodes = null; + private INodeDiscoveryProvider _discoveryProvider; + + public NodePage() + { + + } + + public NodePage(string id) + { + CurrentNodeId = id; + } + + public string CurrentNodeId { get; set; } public IList Nodes { @@ -15,13 +28,8 @@ namespace DotNetCore.CAP.Dashboard.Pages { if (_nodes == null) { - var configOptions = RequestServices.GetService(); - - var factory = RequestServices.GetService(); - - var discoryProvider = factory.Create(configOptions); - - _nodes = discoryProvider.GetNodes().GetAwaiter().GetResult(); + _discoveryProvider = RequestServices.GetService(); + _nodes = _discoveryProvider.GetNodes().GetAwaiter().GetResult(); } return _nodes; } diff --git a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml index 182f30f..17e1e38 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml +++ b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml @@ -5,23 +5,28 @@ @inherits RazorPage @{ Layout = new LayoutPage(Strings.NodePage_Title); + if (CurrentNodeId != null) + { + Session.Set("cap_current_node",System.Text.Encoding.Default.GetBytes(CurrentNodeId)); + } }

@Strings.NodePage_Title

- @if (Nodes == null || Nodes.Count==0) + @if (Nodes == null || Nodes.Count == 0) {
@Strings.NodePage_NoNodes
} else - { + {
+ @@ -32,12 +37,15 @@ @foreach (var node in Nodes) { - + + - + } diff --git a/src/DotNetCore.CAP/Dashboard/Pages/NodePage1.generated.cs b/src/DotNetCore.CAP/Dashboard/Pages/NodePage1.generated.cs index e292000..ef1b43e 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/NodePage1.generated.cs +++ b/src/DotNetCore.CAP/Dashboard/Pages/NodePage1.generated.cs @@ -54,6 +54,10 @@ WriteLiteral("\r\n"); #line 6 "..\..\Dashboard\Pages\NodePage.cshtml" Layout = new LayoutPage(Strings.NodePage_Title); + if (CurrentNodeId != null) + { + Session.Set("cap_current_node",System.Text.Encoding.Default.GetBytes(CurrentNodeId)); + } @@ -63,7 +67,7 @@ WriteLiteral("
\r\n
\r\n \r\n\r\n"); - #line 13 "..\..\Dashboard\Pages\NodePage.cshtml" - if (Nodes == null || Nodes.Count==0) + #line 17 "..\..\Dashboard\Pages\NodePage.cshtml" + if (Nodes == null || Nodes.Count == 0) { @@ -84,7 +88,7 @@ WriteLiteral("
\r\n - #line 16 "..\..\Dashboard\Pages\NodePage.cshtml" + #line 20 "..\..\Dashboard\Pages\NodePage.cshtml" Write(Strings.NodePage_NoNodes); @@ -94,10 +98,10 @@ WriteLiteral("\r\n
\r\n"); - #line 18 "..\..\Dashboard\Pages\NodePage.cshtml" + #line 22 "..\..\Dashboard\Pages\NodePage.cshtml" } else - { + { #line default @@ -106,6 +110,7 @@ WriteLiteral(@"
编号 节点名称 IP地址 端口号
@node.Id @node.Name @node.Address @node.Port @node.Tags切换到 + @Html.NodeSwitchLink(node.Id) +
+ @@ -118,18 +123,38 @@ WriteLiteral(@"
- #line 33 "..\..\Dashboard\Pages\NodePage.cshtml" + #line 38 "..\..\Dashboard\Pages\NodePage.cshtml" foreach (var node in Nodes) { #line default #line hidden -WriteLiteral("
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n " + -" \r\n"); +WriteLiteral("\r\n \r\n \r\n"); + + + + #line 50 "..\..\Dashboard\Pages\NodePage.cshtml" } @@ -180,7 +215,7 @@ WriteLiteral(" \r\n
编号 节点名称 IP地址 端口号
"); +WriteLiteral("
\r\n " + +""); - #line 42 "..\..\Dashboard\Pages\NodePage.cshtml" + #line 47 "..\..\Dashboard\Pages\NodePage.cshtml" + Write(Html.NodeSwitchLink(node.Id)); + + + #line default + #line hidden +WriteLiteral("\r\n
\r\n - #line 46 "..\..\Dashboard\Pages\NodePage.cshtml" + #line 54 "..\..\Dashboard\Pages\NodePage.cshtml" } diff --git a/src/DotNetCore.CAP/Dashboard/RazorPage.cs b/src/DotNetCore.CAP/Dashboard/RazorPage.cs index cea0a1c..3485340 100644 --- a/src/DotNetCore.CAP/Dashboard/RazorPage.cs +++ b/src/DotNetCore.CAP/Dashboard/RazorPage.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Net; using System.Text; using DotNetCore.CAP.Dashboard.Monitoring; +using Microsoft.AspNetCore.Http; namespace DotNetCore.CAP.Dashboard { @@ -37,9 +38,9 @@ namespace DotNetCore.CAP.Dashboard } } - internal DashboardRequest Request { private get; set; } - internal DashboardResponse Response { private get; set; } - + protected DashboardRequest Request { private get; set; } + protected DashboardResponse Response { private get; set; } + internal ISession Session { get; private set; } internal IServiceProvider RequestServices { get; private set; } public string RequestPath => Request.Path; @@ -67,6 +68,7 @@ namespace DotNetCore.CAP.Dashboard StatsPollingInterval = parentPage.StatsPollingInterval; Url = parentPage.Url; RequestServices = parentPage.RequestServices; + Session = parentPage.Session; GenerationTime = parentPage.GenerationTime; _statisticsLazy = parentPage._statisticsLazy; @@ -77,7 +79,7 @@ namespace DotNetCore.CAP.Dashboard Request = context.Request; Response = context.Response; RequestServices = context.RequestServices; - + Session = context.Session; Storage = context.Storage; AppPath = context.Options.AppPath; StatsPollingInterval = context.Options.StatsPollingInterval; diff --git a/src/DotNetCore.CAP/Dashboard/UrlHelper.cs b/src/DotNetCore.CAP/Dashboard/UrlHelper.cs index 13a6a90..5cfb758 100644 --- a/src/DotNetCore.CAP/Dashboard/UrlHelper.cs +++ b/src/DotNetCore.CAP/Dashboard/UrlHelper.cs @@ -29,6 +29,11 @@ namespace DotNetCore.CAP.Dashboard return To("/jobs/details/" + jobId); } + public string NodeSwitch(string id) + { + return To("/nodes/node/" + id); + } + public string LinkToPublished() { return To("/published/succeeded"); diff --git a/src/DotNetCore.CAP/NodeDiscovery/CAP.DiscoveryOptionsExtensions.cs b/src/DotNetCore.CAP/NodeDiscovery/CAP.DiscoveryOptionsExtensions.cs index 7895e4c..1181b60 100644 --- a/src/DotNetCore.CAP/NodeDiscovery/CAP.DiscoveryOptionsExtensions.cs +++ b/src/DotNetCore.CAP/NodeDiscovery/CAP.DiscoveryOptionsExtensions.cs @@ -21,10 +21,16 @@ namespace DotNetCore.CAP var discoveryOptions = new DiscoveryOptions(); _options?.Invoke(discoveryOptions); - services.AddSingleton(discoveryOptions); + services.AddSingleton(discoveryOptions); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(x => + { + var configOptions = x.GetService(); + var factory = x.GetService(); + return factory.Create(configOptions); + }); } } } @@ -37,7 +43,7 @@ namespace Microsoft.Extensions.DependencyInjection { public static CapOptions UseDiscovery(this CapOptions capOptions) { - return capOptions.UseDiscovery(opt => {}); + return capOptions.UseDiscovery(opt => { }); } public static CapOptions UseDiscovery(this CapOptions capOptions, Action options) diff --git a/src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.Consul.cs b/src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.Consul.cs index a7d8ce1..1e05533 100644 --- a/src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.Consul.cs +++ b/src/DotNetCore.CAP/NodeDiscovery/INodeDiscoveryProvider.Consul.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Consul; +using System.Security.Cryptography; namespace DotNetCore.CAP.NodeDiscovery { @@ -33,7 +34,7 @@ namespace DotNetCore.CAP.NodeDiscovery var nodes = services.Response.Select(x => new Node { - Name = x.Key, + Name = x.Value.Service, Address = x.Value.Address, Port = x.Value.Port, Tags = string.Join(", ", x.Value.Tags) diff --git a/src/DotNetCore.CAP/NodeDiscovery/Node.cs b/src/DotNetCore.CAP/NodeDiscovery/Node.cs index f153189..c77d1d9 100644 --- a/src/DotNetCore.CAP/NodeDiscovery/Node.cs +++ b/src/DotNetCore.CAP/NodeDiscovery/Node.cs @@ -6,6 +6,8 @@ namespace DotNetCore.CAP.NodeDiscovery { class Node { + public string Id { get; set; } + public string Name { get; set; } public string Address { get; set; }