Merge branch 'master' of http://118.178.224.202:3000/ewide/ewide_core
This commit is contained in:
@@ -20,9 +20,9 @@ namespace Ewide.Core
|
||||
MENU = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 按钮
|
||||
/// 功能
|
||||
/// </summary>
|
||||
[Description("按钮")]
|
||||
BTN = 2
|
||||
[Description("功能")]
|
||||
FUNCTION = 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2417,9 +2417,9 @@
|
||||
菜单
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Ewide.Core.MenuType.BTN">
|
||||
<member name="F:Ewide.Core.MenuType.FUNCTION">
|
||||
<summary>
|
||||
按钮
|
||||
功能
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Ewide.Core.MenuWeight">
|
||||
@@ -4933,7 +4933,7 @@
|
||||
路由元信息(路由附带扩展信息)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.AntDesignTreeNode.Path">
|
||||
<member name="P:Ewide.Core.Service.AntDesignTreeNode.Link">
|
||||
<summary>
|
||||
路径
|
||||
</summary>
|
||||
@@ -4943,6 +4943,11 @@
|
||||
控制路由和子路由是否显示在 sidebar
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.AntDesignTreeNode.OpenType">
|
||||
<summary>
|
||||
打开方式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Ewide.Core.Service.Meta">
|
||||
<summary>
|
||||
路由元信息内部类
|
||||
@@ -5068,6 +5073,11 @@
|
||||
菜单类型(字典 0目录 1菜单 2按钮)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.AddMenuInput.OpenType">
|
||||
<summary>
|
||||
打开方式(字典 0无 1组件 2内链 3外链)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.DeleteMenuInput.Id">
|
||||
<summary>
|
||||
菜单Id
|
||||
@@ -5138,6 +5148,16 @@
|
||||
关联显示父级
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.MenuTreeOutput.Permission">
|
||||
<summary>
|
||||
权限标识
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.MenuTreeOutput.Remark">
|
||||
<summary>
|
||||
备注
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:Ewide.Core.Service.MenuTreeOutput.Sort">
|
||||
<summary>
|
||||
排序,越小优先级越高
|
||||
|
||||
@@ -8,6 +8,8 @@ using System.Diagnostics;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using UAParser;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -34,12 +36,29 @@ namespace Ewide.Core
|
||||
var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
|
||||
var descAtt = Attribute.GetCustomAttribute(actionDescriptor.MethodInfo, typeof(DescriptionAttribute)) as DescriptionAttribute;
|
||||
|
||||
var message = "请求成功";
|
||||
if (isRequestSucceed)
|
||||
{
|
||||
var result = actionContext.Result;
|
||||
var resultType = result.GetType();
|
||||
if (resultType.Name == "ContentResult")
|
||||
{
|
||||
var resultContent = ((Microsoft.AspNetCore.Mvc.ContentResult)actionContext.Result)?.Content;
|
||||
var resultJson = JsonConvert.DeserializeObject<JObject>(resultContent);
|
||||
message = resultJson["message"]?.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message = actionContext.Exception.Message;
|
||||
}
|
||||
|
||||
var sysOpLog = new SysLogOp
|
||||
{
|
||||
Name = descAtt != null ? descAtt.Description : actionDescriptor.ActionName,
|
||||
OpType = 1,
|
||||
Success = isRequestSucceed,
|
||||
//Message = isRequestSucceed ? "成功" : "失败",
|
||||
Message = message,
|
||||
Ip = httpContext.GetRemoteIpAddressToIPv4(),
|
||||
Location = httpRequest.GetRequestUrlAddress(),
|
||||
Browser = clent.UA.Family + clent.UA.Major,
|
||||
@@ -48,13 +67,13 @@ namespace Ewide.Core
|
||||
ClassName = context.Controller.ToString(),
|
||||
MethodName = actionDescriptor.ActionName,
|
||||
ReqMethod = httpRequest.Method,
|
||||
//Param = JsonSerializerUtility.Serialize(context.ActionArguments),
|
||||
//Result = JsonSerializerUtility.Serialize(actionContext.Result),
|
||||
Param = JsonConvert.SerializeObject(context.ActionArguments),
|
||||
// Result = resultContent,
|
||||
ElapsedTime = sw.ElapsedMilliseconds,
|
||||
OpTime = DateTime.Now,
|
||||
Account = httpContext.User?.FindFirstValue(ClaimConst.CLAINM_ACCOUNT)
|
||||
};
|
||||
await sysOpLog.InsertAsync();
|
||||
await sysOpLog.InsertNowAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +93,17 @@ namespace Ewide.Core.Service.Area
|
||||
#endif
|
||||
}
|
||||
var query = cachedAreaCodes.Where(p => p.LevelType <= level);
|
||||
var resAreaCode = new List<SysAreaCode>();
|
||||
if (areaCodeList != null)
|
||||
{
|
||||
query = query.Where(p => areaCodeList.Contains(p.Code));
|
||||
foreach (var code in areaCodeList)
|
||||
{
|
||||
var queryRes = query.Where(p => p.Code.StartsWith(code));
|
||||
resAreaCode.AddRange(queryRes);
|
||||
}
|
||||
cachedAreaCodes = resAreaCode.Distinct().ToList();
|
||||
}
|
||||
cachedAreaCodes = query.ToList();
|
||||
|
||||
return new TreeBuildUtil<AreaTreeNode>().DoTreeBuild(cachedAreaCodes.Select(u => new AreaTreeNode
|
||||
{
|
||||
Code = u.Code,
|
||||
|
||||
@@ -101,6 +101,24 @@ namespace Ewide.Core.Service
|
||||
// 设置刷新Token令牌
|
||||
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
|
||||
|
||||
// 增加登录日志
|
||||
var loginOutput = user.Adapt<LoginOutput>();
|
||||
var clent = Parser.GetDefault().Parse(App.GetService<IHttpContextAccessor>().HttpContext.Request.Headers["User-Agent"]);
|
||||
loginOutput.LastLoginBrowser = clent.UA.Family + clent.UA.Major;
|
||||
loginOutput.LastLoginOs = clent.OS.Family + clent.OS.Major;
|
||||
await new SysLogVis
|
||||
{
|
||||
Name = "登录",
|
||||
Success = true,
|
||||
Message = "登录成功",
|
||||
Ip = loginOutput.LastLoginIp,
|
||||
Browser = loginOutput.LastLoginBrowser,
|
||||
Os = loginOutput.LastLoginOs,
|
||||
VisType = 1,
|
||||
VisTime = loginOutput.LastLoginTime,
|
||||
Account = loginOutput.Account
|
||||
}.InsertAsync();
|
||||
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@@ -163,20 +181,6 @@ namespace Ewide.Core.Service
|
||||
loginOutput.Menus = await _sysMenuService.GetLoginMenusAntDesign(userId, defaultActiveAppCode);
|
||||
}
|
||||
|
||||
// 增加登录日志
|
||||
//await new SysLogVis
|
||||
//{
|
||||
// Name = "登录",
|
||||
// Success = true,
|
||||
// Message = "登录成功",
|
||||
// Ip = loginOutput.LastLoginIp,
|
||||
// Browser = loginOutput.LastLoginBrowser,
|
||||
// Os = loginOutput.LastLoginOs,
|
||||
// VisType = 1,
|
||||
// VisTime = loginOutput.LastLoginTime,
|
||||
// Account = loginOutput.Account
|
||||
//}.InsertAsync();
|
||||
|
||||
return loginOutput;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Ewide.Core.Extension;
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
@@ -20,10 +21,12 @@ namespace Ewide.Core.Service
|
||||
public class SysOpLogService : ISysOpLogService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysLogOp> _sysOpLogRep; // 操作日志表仓储
|
||||
private readonly IDapperRepository<SysLogOp> _dapperRepository;
|
||||
|
||||
public SysOpLogService(IRepository<SysLogOp> sysOpLogRep)
|
||||
public SysOpLogService(IRepository<SysLogOp> sysOpLogRep, IDapperRepository<SysLogOp> dapperRepository)
|
||||
{
|
||||
_sysOpLogRep = sysOpLogRep;
|
||||
_dapperRepository = dapperRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,11 +57,7 @@ namespace Ewide.Core.Service
|
||||
[HttpPost("/sysOpLog/delete")]
|
||||
public async Task ClearOpLog()
|
||||
{
|
||||
var opLogs = await _sysOpLogRep.Entities.ToListAsync();
|
||||
opLogs.ForEach(u =>
|
||||
{
|
||||
u.Delete();
|
||||
});
|
||||
await _dapperRepository.ExecuteAsync("DELETE FROM sys_log_op");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,12 +38,17 @@
|
||||
/// <summary>
|
||||
/// 路径
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
public string Link { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 控制路由和子路由是否显示在 sidebar
|
||||
/// </summary>
|
||||
public bool Hidden { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 打开方式
|
||||
/// </summary>
|
||||
public int OpenType { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Ewide.Core.Service
|
||||
/// <summary>
|
||||
/// 菜单类型(字典 0目录 1菜单 2按钮)
|
||||
/// </summary>
|
||||
public virtual string Type { get; set; }
|
||||
public virtual int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
@@ -55,7 +55,7 @@ namespace Ewide.Core.Service
|
||||
/// <summary>
|
||||
/// 打开方式(字典 0无 1组件 2内链 3外链)
|
||||
/// </summary>
|
||||
public virtual string OpenType { get; set; }
|
||||
public virtual int OpenType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否可见(Y-是,N-否)
|
||||
@@ -99,7 +99,13 @@ namespace Ewide.Core.Service
|
||||
/// 菜单类型(字典 0目录 1菜单 2按钮)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "菜单类型不能为空")]
|
||||
public override string Type { get; set; }
|
||||
public override int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 打开方式(字典 0无 1组件 2内链 3外链)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "打开方式不能为空")]
|
||||
public override int OpenType { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteMenuInput
|
||||
|
||||
@@ -38,6 +38,16 @@ namespace Ewide.Core.Service
|
||||
/// </summary>
|
||||
public bool VisibleParent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 权限标识
|
||||
/// </summary>
|
||||
public string Permission { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序,越小优先级越高
|
||||
/// </summary>
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Ewide.Core.Service
|
||||
var roleIdList = await _sysUserRoleService.GetUserRoleIdList(userId);
|
||||
var menuIdList = await _sysRoleMenuService.GetRoleMenuIdList(roleIdList);
|
||||
permissions = await _sysMenuRep.DetachedEntities.Where(u => menuIdList.Contains(u.Id))
|
||||
.Where(u => u.Type == (int)MenuType.BTN)
|
||||
.Where(u => u.Type == (int)MenuType.FUNCTION)
|
||||
.Where(u => u.Status == (int)CommonStatus.ENABLE)
|
||||
.Select(u => u.Permission).ToListAsync();
|
||||
#if DEBUG
|
||||
@@ -83,8 +83,8 @@ namespace Ewide.Core.Service
|
||||
sysMenuList = await _sysMenuRep.DetachedEntities
|
||||
.Where(u => u.Status == (int)CommonStatus.ENABLE)
|
||||
.Where(u => u.Application == appCode)
|
||||
.Where(u => u.Type != (int)MenuType.BTN)
|
||||
//.Where(u => u.Weight != (int)MenuWeight.DEFAULT_WEIGHT)
|
||||
.Where(u => u.Type != (int)MenuType.FUNCTION)
|
||||
.Where(u => u.Weight != (int)MenuWeight.DEFAULT_WEIGHT)
|
||||
.OrderBy(u => u.Sort).ToListAsync();
|
||||
}
|
||||
else
|
||||
@@ -96,7 +96,7 @@ namespace Ewide.Core.Service
|
||||
.Where(u => menuIdList.Contains(u.Id))
|
||||
.Where(u => u.Status == (int)CommonStatus.ENABLE)
|
||||
.Where(u => u.Application == appCode)
|
||||
.Where(u => u.Type != (int)MenuType.BTN)
|
||||
.Where(u => u.Type != (int)MenuType.FUNCTION)
|
||||
.OrderBy(u => u.Sort).ToListAsync();
|
||||
}
|
||||
// 转换成登录菜单
|
||||
@@ -106,8 +106,9 @@ namespace Ewide.Core.Service
|
||||
Pid = u.Pid,
|
||||
Name = u.Code,
|
||||
Component = u.Component,
|
||||
Redirect = u.OpenType == (int)MenuOpenType.OUTER ? u.Link : u.Redirect,
|
||||
Path = u.OpenType == (int)MenuOpenType.OUTER ? u.Link : u.Router,
|
||||
Redirect = u.Redirect,
|
||||
Link = u.Link,
|
||||
OpenType = u.OpenType,
|
||||
Meta = new Meta
|
||||
{
|
||||
Title = u.Name,
|
||||
@@ -137,7 +138,7 @@ namespace Ewide.Core.Service
|
||||
var roleIdList = await _sysUserRoleService.GetUserRoleIdList(userId);
|
||||
var menuIdList = await _sysRoleMenuService.GetRoleMenuIdList(roleIdList);
|
||||
return await _sysMenuRep.DetachedEntities
|
||||
.Where(u => u.VisibleParent)
|
||||
.Where(u => (u.Type == 2 && u.VisibleParent) || u.Type < 2)
|
||||
.Where(u => menuIdList.Contains(u.Id))
|
||||
.Where(u => u.Status == (int)CommonStatus.ENABLE)
|
||||
.Select(u => u.Application).ToListAsync();
|
||||
@@ -185,7 +186,7 @@ namespace Ewide.Core.Service
|
||||
/// 增加和编辑时检查参数
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
private static void CheckMenuParam(MenuInput input)
|
||||
private async Task CheckMenuParam(MenuInput input)
|
||||
{
|
||||
var type = input.Type;
|
||||
var router = input.Router;
|
||||
@@ -195,17 +196,17 @@ namespace Ewide.Core.Service
|
||||
|
||||
if (type.Equals((int)MenuType.DIR))
|
||||
{
|
||||
if (string.IsNullOrEmpty(router))
|
||||
throw Oops.Oh(ErrorCode.D4001);
|
||||
//if (string.IsNullOrEmpty(router))
|
||||
// throw Oops.Oh(ErrorCode.D4001);
|
||||
}
|
||||
else if (type.Equals((int)MenuType.MENU))
|
||||
{
|
||||
if (string.IsNullOrEmpty(router))
|
||||
throw Oops.Oh(ErrorCode.D4001);
|
||||
if (string.IsNullOrEmpty(openType))
|
||||
throw Oops.Oh(ErrorCode.D4002);
|
||||
//if (string.IsNullOrEmpty(router))
|
||||
// throw Oops.Oh(ErrorCode.D4001);
|
||||
//if (string.IsNullOrEmpty(openType))
|
||||
// throw Oops.Oh(ErrorCode.D4002);
|
||||
}
|
||||
else if (type.Equals((int)MenuType.BTN))
|
||||
else if (type.Equals((int)MenuType.FUNCTION))
|
||||
{
|
||||
if (string.IsNullOrEmpty(permission))
|
||||
throw Oops.Oh(ErrorCode.D4003);
|
||||
@@ -217,10 +218,37 @@ namespace Ewide.Core.Service
|
||||
//if (!urlSet.Contains(permission.Replace(":","/")))
|
||||
// throw Oops.Oh(ErrorCode.meu1005);
|
||||
}
|
||||
//按钮可以设置绑定菜单
|
||||
if(!isVisibleParent && type.Equals((int)MenuType.BTN))
|
||||
|
||||
// 检查上级菜单的类型是否正确
|
||||
var pid = input.Pid;
|
||||
var flag = true;
|
||||
var empty = System.Guid.Empty.ToString();
|
||||
switch(type)
|
||||
{
|
||||
throw Oops.Oh(ErrorCode.D4004);
|
||||
// 目录必须在顶级下
|
||||
case (int)MenuType.DIR:
|
||||
flag = pid.Equals(empty);
|
||||
break;
|
||||
// 菜单必须在顶级或目录下
|
||||
case (int)MenuType.MENU:
|
||||
if (!pid.Equals(empty))
|
||||
{
|
||||
var parent = await _sysMenuRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == pid);
|
||||
flag = parent.Type.Equals((int)MenuType.DIR);
|
||||
}
|
||||
break;
|
||||
// 功能必须在菜单下
|
||||
case (int)MenuType.FUNCTION:
|
||||
{
|
||||
var parent = await _sysMenuRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == pid);
|
||||
flag = parent == null ? false : parent.Type.Equals((int)MenuType.MENU);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
throw Oops.Oh("父级菜单类型错误");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,7 +268,7 @@ namespace Ewide.Core.Service
|
||||
}
|
||||
|
||||
// 校验参数
|
||||
CheckMenuParam(input);
|
||||
await CheckMenuParam(input);
|
||||
|
||||
var menu = input.Adapt<SysMenu>();
|
||||
menu.Pids = await CreateNewPids(input.Pid);
|
||||
@@ -296,7 +324,7 @@ namespace Ewide.Core.Service
|
||||
}
|
||||
|
||||
// 校验参数
|
||||
CheckMenuParam(input);
|
||||
await CheckMenuParam(input);
|
||||
// 如果是编辑,父id不能为自己的子节点
|
||||
var childIdList = await _sysMenuRep.DetachedEntities.Where(u => u.Pids.Contains(input.Id.ToString()))
|
||||
.Select(u => u.Id).ToListAsync();
|
||||
@@ -360,7 +388,7 @@ namespace Ewide.Core.Service
|
||||
// 更新当前菜单
|
||||
oldMenu = input.Adapt<SysMenu>();
|
||||
oldMenu.Pids = newPids;
|
||||
await oldMenu.UpdateAsync(ignoreNullValues: true);
|
||||
await oldMenu.UpdateExcludeAsync(new[] { nameof(SysMenu.Type) }, ignoreNullValues: true);
|
||||
|
||||
// 清除缓存
|
||||
await _sysCacheService.DelByPatternAsync(CommonConst.CACHE_KEY_MENU);
|
||||
@@ -432,6 +460,8 @@ namespace Ewide.Core.Service
|
||||
Title = u.Name,
|
||||
Type = u.Type,
|
||||
VisibleParent = u.VisibleParent,
|
||||
Permission = u.Permission,
|
||||
Remark = u.Remark,
|
||||
Sort = u.Sort
|
||||
}).ToListAsync();
|
||||
return new TreeBuildUtil<MenuTreeOutput>().DoTreeBuild(menus);
|
||||
|
||||
@@ -86,10 +86,10 @@ namespace Ewide.Core.Service
|
||||
// emps.Add(_sysEmpService.GetEmpInfo(long.Parse(u.Id)));
|
||||
//});
|
||||
//await Task.WhenAll(emps);
|
||||
foreach (var user in users.Items)
|
||||
{
|
||||
user.SysEmpInfo = await _sysEmpService.GetEmpInfo(user.Id);
|
||||
}
|
||||
//foreach (var user in users.Items)
|
||||
//{
|
||||
// user.SysEmpInfo = await _sysEmpService.GetEmpInfo(user.Id);
|
||||
//}
|
||||
return PageDataResult<UserOutput>.PageResult(users);
|
||||
}
|
||||
|
||||
@@ -170,8 +170,17 @@ namespace Ewide.Core.Service
|
||||
if (isExist) throw Oops.Oh(ErrorCode.D1003);
|
||||
|
||||
var user = input.Adapt<SysUser>();
|
||||
await user.UpdateExcludeAsync(new[] { nameof(SysUser.Password), nameof(SysUser.Status), nameof(SysUser.AdminType) }, true);
|
||||
user.UpdateIncludeNow(new[] { nameof(SysUser.Birthday) });
|
||||
await user.UpdateIncludeAsync(new[] {
|
||||
nameof(SysUser.Account),
|
||||
nameof(SysUser.NickName),
|
||||
nameof(SysUser.Name),
|
||||
nameof(SysUser.Birthday),
|
||||
nameof(SysUser.Sex),
|
||||
nameof(SysUser.Email),
|
||||
nameof(SysUser.Phone),
|
||||
nameof(SysUser.Tel),
|
||||
}, true);
|
||||
// user.UpdateIncludeNow(new[] { nameof(SysUser.Birthday) });
|
||||
input.SysEmpParam.Id = user.Id.ToString();
|
||||
// 更新员工及附属机构职位信息
|
||||
await _sysEmpService.AddOrUpdate(input.SysEmpParam);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Furion.RemoteRequest.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -26,10 +27,8 @@ namespace Ewide.Core
|
||||
var ramInfo = GetRamInfo();
|
||||
return new
|
||||
{
|
||||
TotalRam = Math.Ceiling(ramInfo.Total / 1024).ToString() + " GB", // 总内存
|
||||
RamRate = Math.Ceiling(100 * ramInfo.Used / ramInfo.Total), // 内存使用率
|
||||
CpuRate = Math.Ceiling(double.Parse(GetCPURate())), // cpu使用率
|
||||
RunTime = GetRunTime()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,20 +39,28 @@ namespace Ewide.Core
|
||||
public static async Task<dynamic> GetMachineBaseInfo()
|
||||
{
|
||||
var assemblyName = typeof(Furion.App).Assembly.GetName();
|
||||
//var networkInfo = NetworkInfo.GetNetworkInfo();
|
||||
//var (Received, Send) = networkInfo.GetInternetSpeed(1000);
|
||||
return new
|
||||
{
|
||||
WanIp = await GetWanIpFromPCOnline(), // 外网IP
|
||||
SendAndReceived = "",// "上行" + Math.Round(networkInfo.SendLength / 1024.0 / 1024 / 1024, 2) + "GB 下行" + Math.Round(networkInfo.ReceivedLength / 1024.0 / 1024 / 1024, 2) + "GB", // 上下行流量统计
|
||||
LanIp = "",//networkInfo.AddressIpv4.ToString(), // 局域网IP
|
||||
LanIp = Dns.GetHostAddresses(string.Empty).Last().ToString(), // 局域网IP
|
||||
IpMac = "",//networkInfo.Mac, // Mac地址
|
||||
HostName = Environment.MachineName, // HostName
|
||||
CurrentDirectory = Environment.CurrentDirectory, // 系统路径
|
||||
SystemOs = RuntimeInformation.OSDescription, // 系统名称
|
||||
OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(), // 系统架构
|
||||
ProcessorCount = Environment.ProcessorCount.ToString() + "核", // CPU核心数
|
||||
ProcessorCount = Environment.ProcessorCount, // CPU核心数
|
||||
FrameworkDescription = RuntimeInformation.FrameworkDescription + " + " + assemblyName.Name.ToString() + assemblyName.Version.ToString(), // .NET和Furion版本
|
||||
NetworkSpeed = ""//"上行" + Send / 1024 + "kb/s 下行" + Received / 1024 + "kb/s" // 网络速度
|
||||
NetworkSpeed = "",//"上行" + Send / 1024 + "kb/s 下行" + Received / 1024 + "kb/s" // 网络速度
|
||||
// Cpu名称
|
||||
CpuName = GetCPUName(),
|
||||
// Cpu基准速度
|
||||
CpuBaseSpeed = GetCPUSpeed(),
|
||||
// 内存总量
|
||||
TotalRam = GetRamInfo().Total,
|
||||
// 运行时间
|
||||
RunTime = (long)(DateTime.Now - Process.GetCurrentProcess().StartTime).TotalMilliseconds,
|
||||
// 磁盘信息
|
||||
DiskInfo = GetDiskInfo(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -94,24 +101,86 @@ namespace Ewide.Core
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
|
||||
}
|
||||
|
||||
private static string GetCPUName()
|
||||
{
|
||||
string result;
|
||||
if (IsUnix())
|
||||
{
|
||||
// ??????
|
||||
var output = ShellUtil.Bash("");
|
||||
result = output.Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
var output = ShellUtil.Cmd("wmic", "cpu get Name");
|
||||
result = output.Replace("Name", string.Empty).Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetCPUSpeed()
|
||||
{
|
||||
string result;
|
||||
if (IsUnix())
|
||||
{
|
||||
// ??????
|
||||
var output = ShellUtil.Bash("");
|
||||
result = output.Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
var output = ShellUtil.Cmd("wmic", "cpu get CurrentClockSpeed");
|
||||
result = output.Replace("CurrentClockSpeed", string.Empty).Trim();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Dictionary<string, string>> GetDiskInfo()
|
||||
{
|
||||
var result = new List<Dictionary<string, string>>();
|
||||
if (IsUnix())
|
||||
{
|
||||
// ??????
|
||||
var output = ShellUtil.Bash("");
|
||||
}
|
||||
else
|
||||
{
|
||||
var output = ShellUtil.Cmd("wmic", "LOGICALDISK get Name,Description,FileSystem,Size,FreeSpace");
|
||||
var strArray = output.Replace("\r", "").Trim().Split('\n')
|
||||
.Select(p => System.Text.RegularExpressions.Regex.Replace(p.Trim(), @"\s+", ",").Split(','));
|
||||
var keyArray = strArray.First();
|
||||
var valueArray = strArray.Where((p, i) => i > 0).ToArray();
|
||||
foreach(var value in valueArray)
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
for(var i = 0;i<keyArray.Length;i++)
|
||||
{
|
||||
dict.Add(keyArray[i], value[i]);
|
||||
}
|
||||
result.Add(dict);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取CPU使用率
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static string GetCPURate()
|
||||
{
|
||||
string cpuRate;
|
||||
string result;
|
||||
if (IsUnix())
|
||||
{
|
||||
var output = ShellUtil.Bash("top -b -n1 | grep \"Cpu(s)\" | awk '{print $2 + $4}'");
|
||||
cpuRate = output.Trim();
|
||||
result = output.Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
var output = ShellUtil.Cmd("wmic", "cpu get LoadPercentage");
|
||||
cpuRate = output.Replace("LoadPercentage", string.Empty).Trim();
|
||||
result = output.Replace("LoadPercentage", string.Empty).Trim();
|
||||
}
|
||||
return cpuRate;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user