protected void Application_Start() { AutofacBootstrap.CoreAutoFacInit(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // JobConfig.JobRegister(); int minWorker, minIOC; ThreadPool.GetMinThreads(out minWorker, out minIOC); LogDbHelper.LogInfo($"线程池最大工作线程数-{minWorker}/IO线程数-${minIOC}", "Global => Application_Start", OperationType.Other); if (ThreadPool.SetMinThreads(LsConstant.ThreadPoolCount, LsConstant.ThreadPoolCount)) { LogDbHelper.LogInfo("设置线程池最大工作线程数/IO线程数成功", "Global => Application_Start", OperationType.Other); } else { LogDbHelper.LogError("设置线程池最大工作线程数/IO线程数成功", "Global => Application_Start", OperationType.Other); } JobScheduler.Start(); AutoMapperConfig.RegisterMappings(); log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Server.MapPath("log4net.config"))); }
public void Execute(IJobExecutionContext context) { lock (_lock) { if (_shuttingDown) { return; } try { if (isFirstStartService) { LotteryEngine.Init(); isFirstStartService = false; LogDbHelper.LogInfo(string.Format("{0}彩种定时执行任务Job开始(First Start)", _LotteryType), GetType().FullName + "=>Start", OperationType.Job); _dataUpdateContainer.Execute(); } else { if (DateTime.Now > NextLotteryTime || NextLotteryTime - DateTime.Now < TimeSpan.FromSeconds(_lotteryUpdateConfig.Interval * 3)) { _dataUpdateContainer.Execute(); } } } catch (Exception ex) { LogDbHelper.LogFatal(ex, GetType() + "Execute", OperationType.Job); } } }
public void Stop(bool immediate) { // Locking here will wait for the lock in Execute to be released until this code can continue. lock (_lock) { _shuttingDown = true; } LogDbHelper.LogInfo(string.Format("{0}彩种定时执行任务Job结束", _LotteryType), GetType().FullName + "=>Stop", OperationType.Job); HostingEnvironment.UnregisterObject(this); }
protected virtual void WriteData <TEntity>(Func <TEntity, ValidationResult> func, TEntity entity) where TEntity : BaseEntity { BeginTransaction(); ValidationResult.Add(func(entity)); if (ValidationResult.IsValid) { if (!Commit()) { throw new LSException("数据保存失败,Data:" + entity.ToJsonString() + ",Action:" + GetType().FullName + "=>" + func.Method.Name); } if (!ValidationResult.IsSet(LsConstant.AuditLogKey) || !ValidationResult.GetData <bool>(LsConstant.AuditLogKey)) { LogDbHelper.LogInfo("数据保存成功.Data:" + entity.ToJsonString(), GetType().FullName + "=>" + func.Method.Name); } } else { LogDbHelper.LogFatal("数据保存失败,原因:" + ValidationResult.Errors.ToJsonString(), GetType().FullName + "=>" + func.Method.Name); } }
public LoginResult Login(string accountName, string password) { var userInfo = ((IUserDapperRepository)_dapperRepository).GetUserByAccountName(accountName); LoginResult loginResult = null; LoginResultType loginResultType; // 1. 判断是否存在用户 if (userInfo == null) { loginResultType = LoginResultType.InvalidUserNameAccount; loginResult = new LoginResult(loginResultType); LogDbHelper.LogWarn("登录失败,不存在用户{0}", GetType().FullName + "Login", OperationType.Account); return(loginResult); } // 2. 判断密码是否正确 else if (!AppUtils.VerifyPassword(accountName, password, userInfo.Password, userInfo.UserRegistType)) { loginResultType = LoginResultType.InvalidPassword; loginResult = new LoginResult(loginResultType); } // 3. 判断用户状态是否被激活 else if (!userInfo.IsActive) { loginResultType = LoginResultType.UserIsNotActive; loginResult = new LoginResult(loginResultType); } // 4.判断用户是否已经登录,如果登录了,提示用户不要重复登录 //else if (!string.IsNullOrWhiteSpace(userInfo.TokenId)) //{ // loginResultType = LoginResultType.UserAlreadyLogged; // loginResult = new LoginResult(loginResultType); //} else { loginResult = new LoginResult(userInfo, accountName, userInfo.UserRegistType); } try { if (loginResult.ResultType != LoginResultType.Success) { ((IUserDapperRepository)_dapperRepository).LoginFail(userInfo.Id, accountName, loginResult.ResultType); LogDbHelper.LogWarn("登录失败, 原因:" + loginResult.LoginResultMsg, GetType().FullName + "Login", OperationType.Account); } else { ((IUserDapperRepository)_dapperRepository).LoginSuccess(userInfo.Id, accountName, loginResult.ResultType, loginResult.TokenId, loginResult.LoginTime); // :todo 缓存TokenId LogDbHelper.LogInfo(loginResult.LoginResultMsg, GetType().FullName + "Login", OperationType.Account); } } catch (Exception ex) { ((IUserDapperRepository)_dapperRepository).LoginFail(userInfo.Id, accountName, loginResult.ResultType); LogDbHelper.LogError("登录失败, 原因:" + ex.ToString(), GetType().FullName + "Login", OperationType.Account); loginResult = new LoginResult(ex); } return(loginResult); }