Example #1
0
        /// <summary>
        ///     异常处理
        /// </summary>
        public override void OnException(ExceptionContext context)
        {
            base.OnException(context);

            if (context.ExceptionHandled == false)
            {
                var msg = context.Exception.Message;
                msg = msg.ReplaceHtmlTag().ToReplace().ToUrlEncode();
                msg = msg.ReplaceHtmlTag().ToEncoding();

                var path = context.HttpContext.Request.Path.ToString().Replace("/", "_");

                var fullPath = context.HttpContext.Request.Path + context.HttpContext.Request.QueryString;
                ExceptionLogs.Write(context.Exception, path, fullPath);

                ;
            }

            context.ExceptionHandled = true;

            //context.ExceptionHandled = true;
            //context.HttpContext.Response.StatusCode = 200;
            //context.Result = new Result(StateCode.Fail, context.Exception.Message);
            //// context.Result = new Result(StateCode.Fail, context.Exception.GetPrompt());
        }
        /// <summary>
        ///     异常处理
        /// </summary>
        public override void OnException(ExceptionContext context)
        {
            base.OnException(context);

            if (context.ExceptionHandled == false)
            {
                var msg = context.Exception.Message;
                msg = msg.ReplaceHtmlTag().ToReplace().ToUrlEncode();
                msg = msg.ReplaceHtmlTag().ToEncoding();

                var path = context.HttpContext.Request.Path.ToString().Replace("/", "_");

                var fullPath = context.HttpContext.Request.Path + context.HttpContext.Request.QueryString;
                ExceptionLogs.Write(context.Exception, path, fullPath);
            }

            context.ExceptionHandled = true;
        }
Example #3
0
 /// <summary>
 ///     执行
 /// </summary>
 /// <param name="context">执行上下文</param>
 public async Task Execute(Qz.IJobExecutionContext context)
 {
     using (var scope = Ioc.BeginScope()) {
         try {
             //get tenant and switch
             var jobDataMap = context.JobDetail.JobDataMap;
             var tenantName = jobDataMap.GetString(nameof(Tenant));
             if (!string.IsNullOrWhiteSpace(tenantName))
             {
                 TenantContext.SwitchDatabase(scope, tenantName);
             }
             //execute
             await Execute(context, scope);
         } catch (Exception ex) {
             var type = context.JobInstance;
             ExceptionLogs.Write(ex, type.GetType().Name);
         }
     }
 }