Global.asax 3.6 KB

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