From 9ebafff39282830091fea8a4abf7cb18540ea4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Wed, 19 Apr 2023 19:40:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=87=86=E5=A4=87=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=9B=91=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Impl/MonitorServerService.cs | 62 +++++++++++++++++++ .../Rbac/SignalRHub/OnlineUserHub.cs | 45 +------------- 2 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/MonitorServerService.cs diff --git a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/MonitorServerService.cs b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/MonitorServerService.cs new file mode 100644 index 00000000..660a394d --- /dev/null +++ b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/MonitorServerService.cs @@ -0,0 +1,62 @@ +//using System; +//using System.Collections.Generic; +//using System.Diagnostics; +//using System.Linq; +//using System.Runtime.InteropServices; +//using System.Text; +//using System.Threading.Tasks; +//using Furion.Logging; +//using Microsoft.AspNetCore.Hosting; +//using Microsoft.Extensions.Hosting; +//using Microsoft.Extensions.Options; + +//namespace Yi.Furion.Application.Rbac.Services +//{ + +// public class MonitorServerService +// { +// private OptionsSetting Options; +// private IWebHostEnvironment HostEnvironment; +// private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); +// public MonitorServerService(IOptions options, IWebHostEnvironment hostEnvironment) +// { +// this.HostEnvironment = hostEnvironment; +// this.Options = options.Value; +// } +// public void GGG() +// { +// int cpuNum = Environment.ProcessorCount; +// string computerName = Environment.MachineName; +// string osName = RuntimeInformation.OSDescription; +// string osArch = RuntimeInformation.OSArchitecture.ToString(); +// string version = RuntimeInformation.FrameworkDescription; +// string appRAM = ((double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB"; +// string startTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss"); +// string sysRunTime = ComputerHelper.GetRunTime(); +// string serverIP = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP + +// var programStartTime = Process.GetCurrentProcess().StartTime; +// string programRunTime = DateTimeHelper.FormatTime((DateTime.Now - programStartTime).TotalMilliseconds.ToString().Split('.')[0].ParseToLong()); +// var data = new +// { +// cpu = ComputerHelper.GetComputerInfo(), +// disk = ComputerHelper.GetDiskInfos(), +// sys = new { cpuNum, computerName, osName, osArch, serverIP, runTime = sysRunTime }, +// app = new +// { +// name = HostEnvironment.EnvironmentName, +// rootPath = HostEnvironment.ContentRootPath, +// webRootPath = HostEnvironment.WebRootPath, +// version, +// appRAM, +// startTime, +// runTime = programRunTime, +// host = serverIP +// }, +// }; + +// return SUCCESS(data); +// } + +// } +//} diff --git a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/SignalRHub/OnlineUserHub.cs b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/SignalRHub/OnlineUserHub.cs index 87d52cc8..ad04b7bb 100644 --- a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/SignalRHub/OnlineUserHub.cs +++ b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/SignalRHub/OnlineUserHub.cs @@ -39,7 +39,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub public override Task OnConnectedAsync() { var name = _currentUser.UserName; - var loginUser = GetLoginLogInfo(_httpContext); + var loginUser = _httpContext.GetLoginLogInfo(); var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId); //判断用户是否存在,否则添加集合 if (!user) @@ -60,7 +60,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub //当有人加入,向全部客户端发送当前总数 Clients.All.SendAsync("onlineNum", clientUsers.Count); } - + //Clients.All.SendAsync(HubsConstant.OnlineUser, clientUsers); return base.OnConnectedAsync(); } @@ -89,46 +89,5 @@ namespace Yi.Furion.Application.Rbac.SignalRHub await Clients.All.SendAsync("ReceiveAllInfo", test); } - /// - /// 获取客户端信息 - /// - /// - /// - private static ClientInfo GetClientInfo(HttpContext context) - { - var str = context.GetUserAgent(); - var uaParser = Parser.GetDefault(); - ClientInfo c = uaParser.Parse(str); - return c; - } - - /// - /// 记录用户登陆信息 - /// - /// - /// - private static LoginLogEntity GetLoginLogInfo(HttpContext context) - { - var ipAddr = context.GetClientIp(); - IpInfo location; - if (ipAddr == "127.0.0.1") - { - location = new IpInfo() { Province = "本地", City = "本机" }; - } - else - { - location = IpTool.Search(ipAddr); - } - ClientInfo clientInfo = GetClientInfo(context); - LoginLogEntity entity = new() - { - Browser = clientInfo.Device.Family, - Os = clientInfo.OS.ToString(), - LoginIp = ipAddr, - LoginLocation = location.Province + "-" + location.City - }; - - return entity; - } } } \ No newline at end of file