/// <summary> /// 应用程序结束 /// </summary> /// <param name="application">应用程序对象</param> public static void Application_End(HttpApplication application) { try { InitFactory factory = InitFactory.GetInstance(); if (factory != null) { factory.App_End(application); } } catch { } }
/// <summary> /// 应用程序启动 /// </summary> public static void Application_Start() { try { //异步处理异常处理,阻止程序崩溃 TaskScheduler.UnobservedTaskException += (sender, args) => { foreach (var ex in args.Exception.InnerExceptions) { LogOperate.AddExceptionLog(ex, string.Empty); } args.SetObserved(); }; } catch { } try { //向各数据库注册存储过程 SystemOperate.RegStoredProcedure(); //在当前数据库中自动注册外部链接数据库服务器 SystemOperate.RegCrossDbServer(); } catch { } try { //加载所有启用缓存的模块数据 if (GlobalSet.IsStartLoadCache) { SystemOperate.LoadAllModuleCache(); } } catch { } //调用自定义应用程序启动方法 try { InitFactory factory = InitFactory.GetInstance(); if (factory != null) { factory.App_Start(); } } catch { } //string msg = ToolOperate.CreateTempModelDLL(); }
/// <summary> /// 添加后台系统任务 /// </summary> /// <param name="obj"></param> /// <param name="e"></param> public static void SysBackgroundTaskAdd(object obj, EventArgs e) { //重建索引任务,已移至任务调度中心 //BackgroundTask reBuildIndexTask = new BackgroundTask((args) => //{ // if (DateTime.Now.Hour == 4 && DateTime.Now.Minute == 0) // SystemOperate.RebuildAllTableIndex(); // return true; //}, null, false, 45, false); //AutoProcessTask.AddTask(reBuildIndexTask); //添加自定义后台处理任务 try { InitFactory factory = InitFactory.GetInstance(); if (factory != null) { factory.AddBackgroundTask(); } } catch { } }
/// <summary> /// 添加后台系统任务 /// </summary> /// <param name="obj"></param> /// <param name="e"></param> public static void SysBackgroundTaskAdd(object obj, EventArgs e) { if (WebConfigHelper.GetAppSettingValue("IsRunBgTask") == "true") { try { #region 重建索引 //重建索引任务 BackgroundTask reBuildIndexTask = new BackgroundTask((args) => { if (DateTime.Now.Hour == 4 && DateTime.Now.Minute == 0) { SystemOperate.RebuildAllTableIndex(); } return(true); }, null, false, 45, false); AutoProcessTask.AddTask(reBuildIndexTask); #endregion #region 迁移历史审批数据 //审批完成后的数据迁移到待办历史数据表中,针对审批是迁移失败的处理 BackgroundTask todoStatusHandleTask = new BackgroundTask((args) => { if ((DateTime.Now.Hour == 3 && DateTime.Now.Minute == 0) || (DateTime.Now.Hour == 12 && DateTime.Now.Minute == 40)) { //审批完成数据迁移异常处理 try { string errMsg = string.Empty; int refuseStatus = (int)WorkFlowStatusEnum.Refused; int overStatus = (int)WorkFlowStatusEnum.Over; int obsoStatus = (int)WorkFlowStatusEnum.Obsoleted; List <Bpm_WorkFlowInstance> flowInsts = CommonOperate.GetEntities <Bpm_WorkFlowInstance>(out errMsg, x => x.Status == refuseStatus || x.Status == overStatus || x.Status == obsoStatus, null, false); if (flowInsts != null && flowInsts.Count > 0) { foreach (Bpm_WorkFlowInstance flowInst in flowInsts) { BpmOperate.TransferWorkToDoHistory(flowInst, null); } } } catch { } } return(true); }, null, false, 45, false); AutoProcessTask.AddTask(todoStatusHandleTask); #endregion #region 附件在线预览生成 BackgroundTask attachOnlineViewHandleTask = new BackgroundTask((args) => { if (DateTime.Now.Hour == 4 && DateTime.Now.Minute == 0) { string attachWeb = WebConfigHelper.GetAppSettingValue("AttachmentWeb"); if (!string.IsNullOrEmpty(attachWeb)) { if (!attachWeb.EndsWith("/")) { attachWeb += "/"; } string apiUrl = attachWeb + "api/AnnexApi/ExecCreateSwfTask.html"; DataMutual dataMutal = new DataMutual(apiUrl); dataMutal.Start(null); } } return(true); }, null, false, 45, false); AutoProcessTask.AddTask(attachOnlineViewHandleTask); #endregion #region 基于DB的失效分布式锁释放 BackgroundTask dbLockReleaseHandleTask = new BackgroundTask((args) => { if (WebConfigHelper.GetAppSettingValue("EnabledDistributeLock") == "true") //启用分布式锁 { string errMsg = string.Empty; double nowTimesamp = Globals.GetTimestamp(DateTime.Now);//当前时间戳 CommonOperate.DeleteRecordsByExpression <Other_DistributedLock>(x => x.Invalid_Timesamp < nowTimesamp, out errMsg); } return(true); }, null, false, 60, false); AutoProcessTask.AddTask(dbLockReleaseHandleTask); #endregion } catch { } } try { InitFactory factory = InitFactory.GetInstance(); if (factory != null) { factory.AddBackgroundTask(); } } catch { } }