private async static Task AddOperateListAsync()
 {
     await ExceptionUtil.LogExceptionAsync(async() =>
     {
         using (var scope = ContainerManager.BeginLeftScope())
         {
             var adminOperateLogRepository = scope.Resolve <IOperateLogRepository>();
             await adminOperateLogRepository.BulkInsertAsync(_OperateList);
         }
     }, memberName : "OperateLogDomainService-AddOperateListAsync");
 }
示例#2
0
 /// <summary>
 /// 获取option的值
 /// </summary>
 /// <typeparam name="TOptions">option类型</typeparam>
 /// <returns></returns>
 public static TOptions GetOption <TOptions>() where TOptions : class, new()
 {
     using (var scope = ContainerManager.BeginLeftScope())
     {
         var option = scope.Resolve <IOptions <TOptions> >();
         if (option != null)
         {
             return(option.Value);
         }
         return(default(TOptions));
     }
 }
示例#3
0
 public object CallMethod(RequestMessage requestMessage)
 {
     if (requestMessage == null || requestMessage.MethodCallInfo == null)
     {
         return(null);
     }
     using (var scope = ContainerManager.BeginLeftScope())
     {
         var instanceType = Type.GetTypeFromHandle(requestMessage.MethodCallInfo.TypeHandle);
         var instance     = scope.Resolve(instanceType);
         var method       = instanceType.GetMethod(requestMessage.MethodCallInfo.MethodName, requestMessage.MethodCallInfo.ArgumentTypes);
         if (method != null)
         {
             return(method.Invoke(instance, requestMessage.MethodCallInfo.Parameters));
         }
     }
     return(null);
 }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //add NLog to ASP.NET Core
            loggerFactory.AddNLog();
            loggerFactory.AddMQLog();

            app.UseHangfireServer();
            app.UseHangfireDashboard("/TaskScheduling", options: new DashboardOptions
            {
                AppPath       = Configuration.GetValue <string>("WebSite"),
                Authorization = new[] { new HangfireAuthorizationFilter() }
            });

            app.Map("/SynchroTask", r =>
            {
                r.Run(context =>
                {
                    LogUtil.Info("开始启动同步缓存任务");
                    using (var scope = ContainerManager.BeginLeftScope())
                    {
                        var sysConfigApplication   = scope.Resolve <ISysConfigApplication>();
                        var sysConfigSynchroTaskID = Guid.NewGuid().ToString("N");
                        TaskScheldulingUtil.CreateRecurringJob(sysConfigSynchroTaskID, () => sysConfigApplication.SynchroConfigAsync(), cronExpression: "0/10 * * * *");
                        var servicerApplication   = scope.Resolve <IServicerApplication>();
                        var servicerSynchroTaskID = Guid.NewGuid().ToString("N");
                        TaskScheldulingUtil.CreateRecurringJob(servicerSynchroTaskID, () => servicerApplication.SynchroServiceAsync(), cronExpression: "0/10 * * * *");
                        var projectApplication   = scope.Resolve <IProjectApplication>();
                        var projectSynchroTaskID = Guid.NewGuid().ToString("N");
                        TaskScheldulingUtil.CreateRecurringJob(projectSynchroTaskID, () => projectApplication.SynchroProjectAsync(), cronExpression: "0/10 * * * *");
                        var databaseApplication   = scope.Resolve <IDatabaseApplication>();
                        var databaseSynchroTaskID = Guid.NewGuid().ToString("N");
                        TaskScheldulingUtil.CreateRecurringJob(databaseSynchroTaskID, () => databaseApplication.SynchroDatabaseAsync(), cronExpression: "0/10 * * * *");
                        applicationLifetime.ApplicationStopping.Register(() =>
                        {
                            TaskScheldulingUtil.RemoveRecurringJobIfExists(sysConfigSynchroTaskID);
                            TaskScheldulingUtil.RemoveRecurringJobIfExists(servicerSynchroTaskID);
                            TaskScheldulingUtil.RemoveRecurringJobIfExists(projectSynchroTaskID);
                            TaskScheldulingUtil.RemoveRecurringJobIfExists(databaseSynchroTaskID);
                        });
                    }
                    LogUtil.Info("完成启动同步缓存任务");
                    return(context.Response.WriteAsync("Create SynchroConfig Success"));
                });
            });

            app.Map("/MonitorLog", r =>
            {
                r.Run(context =>
                {
                    LogUtil.Info("开始启动监听传输日志");
                    var mqFactory = ContainerManager.Resolve <IMQFactory>();
                    var client    = mqFactory.Create(MQConfig.GetConfig("MQMonitor"));
                    client.Subscribe <List <RuntimeLogModel> >((message) =>
                    {
                        if (message != null && message.Count > 0)
                        {
                            using (var scope = ContainerManager.BeginLeftScope())
                            {
                                var runtimeLogApplication = scope.Resolve <IRuntimeLogApplication>();
                                runtimeLogApplication.AddLogList(message);
                            }
                        }
                    }, "Monitor.Message", "Monitor.Message", "Monitor.LoggerMessage.*", exchangeType: MQExchangeType.TOPICS, errorActionHandle: (message, e) =>
                    {
                        LogUtil.Info("消息处理出现异常");
                        LogUtil.Error(e);
                    });
                    LogUtil.Info("启动监听传输日志完成");
                    applicationLifetime.ApplicationStopping.Register(() =>
                    {
                        client.Dispose();
                    });
                    return(context.Response.WriteAsync("Create MonitorLog Success"));
                });
            });

            app.Map("/MonitorSql", r =>
            {
                r.Run(context =>
                {
                    LogUtil.Info("开始启动监听SQL执行信息");
                    var mqFactory = ContainerManager.Resolve <IMQFactory>();
                    var client    = mqFactory.Create(MQConfig.GetConfig("MQMonitor"));
                    client.Subscribe <List <RuntimeSqlModel> >((message) =>
                    {
                        if (message != null && message.Count > 0)
                        {
                            using (var scope = ContainerManager.BeginLeftScope())
                            {
                                var runtimeSqlApplication = scope.Resolve <IRuntimeSqlApplication>();
                                runtimeSqlApplication.AddRuntimeSqlList(message);
                            }
                        }
                    }, "Monitor.Message", "Monitor.Sql", "Monitor.Sql.*", exchangeType: MQExchangeType.TOPICS, errorActionHandle: (message, e) =>
                    {
                        LogUtil.Info("消息处理出现异常");
                        LogUtil.Error(e);
                    });
                    LogUtil.Info("启动监听SQL执行信息完成");
                    applicationLifetime.ApplicationStopping.Register(() =>
                    {
                        client.Dispose();
                    });
                    return(context.Response.WriteAsync("Create MonitorSql Success"));
                });
            });

            app.Run(context =>
            {
                return(context.Response.WriteAsync("WelCome To TaskScheduling"));
            });

            applicationLifetime.RegisterRedisShutDown();
            applicationLifetime.RegisterMQShutDown();
        }