Ejemplo n.º 1
0
 /// <summary>
 /// 初始化模块
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="options"></param>
 public UnitLoggerModule(IOptions <UnitLoggerModuleOptions> options, LoggerModule loggerModule)
 {
     this.Options      = options ?? throw new ArgumentNullException(nameof(options), "参数不能为空");
     this.LoggerModule = loggerModule ?? throw new ArgumentNullException(nameof(loggerModule), "参数不能为空");
     //检查日志目录
     if (String.IsNullOrWhiteSpace(this.Options.Value.UnitLogsDirectory))
     {
         throw new Exception("单元日志存储目录无效");
     }
     if (!Directory.Exists(this.Options.Value.UnitLogsDirectory))
     {
         try{
             _ = Directory.CreateDirectory(this.Options.Value.UnitLogsDirectory);
         }catch {
             throw;
         }
     }
     //初始化定时器
     try{
         this.Timer = new Timer(this.TimerCallback, null, 0, this.Options.Value.Period < 1000?1000:this.Options.Value.Period);
     }catch {
         throw;
     }
     //
     this.TimerEnable  = true;
     this.UnitLogQueue = new ConcurrentQueue <UnitLog>();
     loggerModule.Log(LogLevel.Warning, "Modules.UnitLoggerModule.UnitLoggerModule", "单元日志模块已初始化");
 }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime,
                              Filters.RequireUserAttribute requireUserAttribute, Filters.RequireManagerAttribute requireManageAttributer,
                              Modules.LoggerModule loggerModule, Modules.UserManageModule userManageModule)
        {
            if (Program.Settings.DevelopMode)
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Default/Error");
                app.UseMiddleware <Middlewares.ErrorHandlingMiddleware>();
            }
            app.UseCors();
            app.UseRouting();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllerRoute(name: "default", pattern: "{controller=Default}/{action=Index}/{id?}");
            });

            //生命周期
            lifetime.ApplicationStarted.Register(() => {
                loggerModule.Log(LogLevel.Warning, "Startup.Configure", "winds 服务主机已启动");
                //过滤器预热
                _ = Task.Run(() => {
                    _ = requireUserAttribute.GetHashCode();
                    _ = requireManageAttributer.GetHashCode();
                });
                //模块预热
                _ = Task.Run(() => {
                    _ = userManageModule.GetHashCode();
                    //_=unitManageModule.GetHashCode();
                    //_=unitLoggerModule.GetHashCode();
                });
            });
            lifetime.ApplicationStopping.Register(() => {
                loggerModule.Log(LogLevel.Warning, "Startup.Configure", "winds 服务主机正在停止");
                // 停止所有单元
                //unitManageModule.StopAllUnits();
                // 写完所有单元日志
                //unitLoggerModule.WriteAllLogs();
            });
            lifetime.ApplicationStopped.Register(() => {
                loggerModule.Log(LogLevel.Warning, "Startup.Configure", "winds 服务主机已停止");
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="options">配置项依赖</param>
 /// <param name="loggerModule">日志模块依赖</param>
 public UnitManageModule(IOptions <UnitManageModuleOptions> options, LoggerModule loggerModule)
 {
     this.Options      = options ?? throw new ArgumentNullException(nameof(options), "参数不能为空");
     this.LoggerModule = loggerModule ?? throw new ArgumentNullException(nameof(loggerModule), "参数不能为空");
     //检查目录
     if (String.IsNullOrWhiteSpace(this.Options.Value.UnitDirectory))
     {
         throw new Exception("单元存储目录无效");
     }
     if (!Directory.Exists(this.Options.Value.UnitDirectory))
     {
         try{
             _ = Directory.CreateDirectory(this.Options.Value.UnitDirectory);
         }catch {
             throw;
         }
     }
     //
     loggerModule.Log(LogLevel.Warning, "Modules.UnitManageModule.UnitManageModule", "单元管理模块已初始化");
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="options">配置项依赖</param>
 /// <param name="loggerModule">日志模块依赖</param>
 public UserManageModule(IOptions <UserManageModuleOptions> options, LoggerModule loggerModule)
 {
     this.Options      = options ?? throw new ArgumentNullException(nameof(options), "参数不能为空");
     this.LoggerModule = loggerModule ?? throw new ArgumentNullException(nameof(loggerModule), "参数不能为空");
     loggerModule.Log(LogLevel.Warning, "Modules.UserManageModule.UserManageModule", "用户管理模块初始化开始");
     if (String.IsNullOrWhiteSpace(options.Value.UsersDirectory) || !Directory.Exists(options.Value.UsersDirectory))
     {
         throw new ArgumentNullException("用户管理模块初始化异常", "UsersDirectory");
     }
     (Boolean success, Int32 count) = this.LoadAllUsers();
     if (success)
     {
         loggerModule.Log(LogLevel.Warning, "Modules.UserManageModule.UserManageModule", $"加载 {count} 个用户");
     }
     else
     {
         loggerModule.Log(LogLevel.Warning, "Modules.UserManageModule.UserManageModule", "加载用户失败");
     }
     loggerModule.Log(LogLevel.Warning, "Modules.UserManageModule.UserManageModule", "用户管理模块初始化完成");
 }