public async Task <JsonResult> GetLogMessage()
        {
            var data = ReadHelper.Read();
            await _hubContext.Clients.All.SendAsync("ReceiveLog", data);

            return(new JsonResult(0));
        }
        public static List <BaseMenu> GetMenuList()
        {
            string json = ReadHelper.Read(Application.StartupPath + "\\menu.json");

            if (string.IsNullOrEmpty(json))
            {
                throw new ArgumentNullException("菜单json字符串为空!");
            }

            return(JsonHelper.Json2List <BaseMenu>(json));
        }
        public async Task OnExceptionAsync(ExceptionContext context)
        {
            //错误
            var ex = context.Exception;
            //错误信息
            string message = ex.Message;
            //请求方法的路由
            string url = context.HttpContext?.Request.Path;
            //写入日志文件描述  注意这个地方尽量不要用中文冒号,否则读取日志文件的时候会造成信息确实,当然你可以定义自己的规则
            string logMessage = $"错误信息=>【{message}】,【请求地址=>{url}】";

            //写入日志
            _log.Error(logMessage);
            //读取日志
            var data = ReadHelper.Read();
            //发送给客户端
            await _hub.Clients.All.SendAsync("ReceiveLog", data);

            //返回一个正确的200http码,避免前端错误
            context.Result = new JsonResult(new { ErrCode = 0, ErrMsg = message, Data = true });
        }
Exemplo n.º 4
0
 public async Task ReceiveLog(object data)
 {
     data = ReadHelper.Read();
     await Clients.All.ReceiveLog(data);
 }
Exemplo n.º 5
0
    private void SetPropValue(object obj, string propName)
    {
        string[] nameParts = propName.Split('.');
        if (nameParts.Length == 1)
        {
            var field = obj.GetType().GetProperty(propName);
            field.SetValue(obj, mReadHelper.Read(field.PropertyType), null);
            return;
        }
        PropertyInfo info = null;

        foreach (string part in nameParts)
        {
            if (obj == null)
            {
                return;
            }
            Type type = obj.GetType();
            info = type.GetProperty(part);
            if (info == null)
            {
                return;
            }
            if (info.PropertyType.IsClass && info.PropertyType != typeof(String))
            {
                obj = info.GetValue(obj, null);
            }
        }
        if (info != null)
        {
            info.SetValue(obj, mReadHelper.Read(info.PropertyType), null);
        }
    }
Exemplo n.º 6
0
 public static bool Help <T>(this JSON.Object o, T value) where T : class, JSON.Readable
 {
     return(ReadHelper <T> .Read(o, ref value));
 }