Global.asax 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <%@ Application Language="C#" %>
  2. <%@ Import Namespace="Curtain.DataAccess" %>
  3. <%@ Import Namespace="Curtain.Log" %>
  4. <%@ Import Namespace="DK.XuWei.WebMes" %>
  5. <script RunAt="server">
  6. // 定时器
  7. System.Timers.Timer tr = null;
  8. void Application_Start(object sender, EventArgs e)
  9. {
  10. // 在应用程序启动时运行的代码
  11. string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  12. DataAccess.DefaultParameterType = SQLParameterType.CDA;
  13. DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
  14. DataAccess.DefaultConnectionString = connStr;
  15. string timerLoadFlag = ConfigurationManager.AppSettings["TimerLoadFlag"].ToString();
  16. if ("1".Equals(timerLoadFlag))
  17. {
  18. // 设置定时器
  19. tr_Load();
  20. }
  21. }
  22. /// <summary>
  23. /// 设置定时器
  24. /// </summary>
  25. void tr_Load()
  26. {
  27. Logger.Debug("$$$定时器已启动$$$");
  28. //设置timer
  29. tr = new System.Timers.Timer(60000);
  30. tr.Elapsed += new System.Timers.ElapsedEventHandler(tr_Timer);
  31. tr.Enabled = true;
  32. tr.AutoReset = true;
  33. }
  34. /// <summary>
  35. /// 定时器要执行的任务
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. void tr_Timer(object sender, EventArgs e)
  40. {
  41. // 中台任务
  42. zhongtai_task();
  43. }
  44. /// <summary>
  45. /// 中台任务
  46. /// </summary>
  47. void zhongtai_task()
  48. {
  49. DateTime now = System.DateTime.Now;
  50. string currTime = now.ToString("HH:mm");
  51. //Logger.Debug("当前时间:" + currTime + ",分钟:" + now.Minute);
  52. if (now.Minute == 5 || now.Minute == 15 || now.Minute == 25 || now.Minute == 35 || now.Minute == 45 || now.Minute == 55)
  53. {
  54. Logger.Debug("自动同步中台:定时触发开始");
  55. string msg = SyncZhongTai.SyncFinishedProduct(now.Date, false);
  56. Logger.Debug("自动同步中台:定时触发结束,结果:\n" + msg);
  57. }
  58. // 如果现在是00点10分,把昨天剩余的全都同步过去
  59. if ("00:10".Equals(currTime))
  60. {
  61. Logger.Debug("自动同步中台_剩余条码:定时触发开始");
  62. string msg = SyncZhongTai.SyncFinishedProduct(now.Date.AddDays(-1), true);
  63. Logger.Debug("自动同步中台_剩余条码:定时触发结束,结果:\n" + msg);
  64. }
  65. }
  66. void Application_End(object sender, EventArgs e)
  67. {
  68. // 在应用程序关闭时运行的代码
  69. Logger.Debug("$$$定时器被关闭$$$");
  70. if (tr != null)
  71. {
  72. tr.Dispose();
  73. }
  74. // 重新唤醒当前应用
  75. ReworkHttp.Rework();
  76. }
  77. void Application_Error(object sender, EventArgs e)
  78. {
  79. // 在出现未处理的错误时运行的代码
  80. Exception error = Server.GetLastError().GetBaseException();
  81. if (error != null)
  82. {
  83. //记录日志
  84. Logger.Error(error);
  85. //输出错误信息
  86. //2022-11-15 冯林勇 出现错误不弹出日志
  87. //HttpContext.Current.Response.Write(new JsonResult(JsonStatus.otherError).ToJson());
  88. //2022-11-15 冯林勇 出现错误不弹出日志
  89. }
  90. Server.ClearError();
  91. }
  92. void Session_Start(object sender, EventArgs e)
  93. {
  94. // 在新会话启动时运行的代码
  95. }
  96. void Session_End(object sender, EventArgs e)
  97. {
  98. // 在会话结束时运行的代码。
  99. // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
  100. // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
  101. // 或 SQLServer,则不引发该事件。
  102. }
  103. </script>