You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
5.1 KiB

2 years ago
  1. using Euro.Transfer.Base;
  2. using System;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. namespace Euro.Transfer.Jobs.Transfer
  6. {
  7. public class Job : ServiceTask
  8. {
  9. /// <summary>
  10. /// 任务开始
  11. /// </summary>
  12. protected override void Start()
  13. {
  14. try
  15. {
  16. var sCurrTime = DateTime.Now.ToString("HH:mm");
  17. var sCurrWeekDay = DateTime.Now.DayOfWeek.ToString("d");
  18. var sTransferWeeks = Common.ConfigGetValue("", "TransferWeeks");
  19. var sTransferTime = Common.ConfigGetValue("", "TransferTime");
  20. var sIsAuto = Common.ConfigGetValue("", "IsAuto");
  21. //ServiceTools.WriteLog("", "sCurrTime:" + sCurrTime + "sCurrWeekDay:" + sCurrWeekDay + "sTransferWeeks:" + sTransferWeeks + "sTransferTime:" + sTransferTime, true);
  22. if (sIsAuto == "true" || (sTransferWeeks.IndexOf(sCurrWeekDay) > -1 && sCurrTime == sTransferTime))
  23. {
  24. //运行中
  25. this.mIsRunning = true;
  26. //执行工作项
  27. this.RunTransfer();
  28. }
  29. }
  30. catch (Exception error)
  31. {
  32. //异常日志
  33. ServiceTools.WriteLog(Errorlog_Path + @"Transfer\" + DateTime.Now.ToString("yyyyMMdd"), error.ToString(), true);
  34. }
  35. finally
  36. {
  37. //空闲
  38. this.mIsRunning = false;
  39. }
  40. }
  41. /// <summary>
  42. /// 任务停止
  43. /// </summary>
  44. protected override void Stop()
  45. {
  46. this.mIsRunning = false;
  47. }
  48. /// <summary>
  49. /// 执行代辦提醒邏輯
  50. /// </summary>
  51. protected void RunTransfer()
  52. {
  53. try
  54. {
  55. do
  56. {
  57. var sOrgID = Common.ConfigGetValue("", "TransferOrgID");
  58. var sUserID = Common.ConfigGetValue("", "TransferUserID");
  59. var user = hubClient.OnlineUsers.FirstOrDefault(u => (u.OrgId == sOrgID && u.UserId == sUserID));
  60. if (user != null)
  61. {
  62. var sIsTest = Common.ConfigGetValue("", "IsTest");//是否為測試
  63. if (sIsTest == "true")
  64. {
  65. ServiceTools.WriteLog(Debuglog_Path, "Euro.Transfer.Jobs.Transfer:" + user.OrgId + "-" + user.UserId + " " + hubClient.connection.State + " ConnectionId:" + hubClient.connection.ConnectionId, true);
  66. }
  67. if (hubClient.connection.State == Microsoft.AspNet.SignalR.Client.ConnectionState.Connected)
  68. {
  69. var sRegisterOrgID = Common.ConfigGetValue("", "RegisterOrgs");
  70. var saRegisterOrgs = sRegisterOrgID.Split(',');
  71. foreach (string org in saRegisterOrgs)
  72. {
  73. hubClient.msgProxy.Invoke("pushTransfer", org, user.UserId, "", 1);
  74. hubClient.msgProxy.Invoke("pushTransfer", org, user.UserId, "", 2);
  75. hubClient.msgProxy.Invoke("pushTransfer", org, user.UserId, "", 3);
  76. }
  77. }
  78. else
  79. {
  80. hubClient.connection.Start().ContinueWith(t =>
  81. {
  82. if (!t.IsFaulted)
  83. {
  84. //连接成功,调用Register方法
  85. hubClient.msgProxy.Invoke("Register", hubClient.clientOrgId, hubClient.clientId, hubClient.clientName, true);
  86. }
  87. else
  88. {
  89. MessageBox.Show("通訊連接失敗!! 請檢查Tracking後臺系統是否正常運行");
  90. }
  91. });
  92. }
  93. }
  94. else
  95. {
  96. hubClient.connection.Start().ContinueWith(t =>
  97. {
  98. if (!t.IsFaulted)
  99. {
  100. //连接成功,调用Register方法
  101. hubClient.msgProxy.Invoke("Register", hubClient.clientOrgId, hubClient.clientId, hubClient.clientName, true);
  102. }
  103. else
  104. {
  105. MessageBox.Show("通訊連接失敗!! 請檢查Tracking後臺系統是否正常運行");
  106. }
  107. });
  108. }
  109. } while (false);
  110. }
  111. catch (Exception error)
  112. {
  113. //写错误日志
  114. ServiceTools.WriteLog(Errorlog_Path + @"Transfer\" + DateTime.Now.ToString("yyyyMMdd"), error.ToString(), true);
  115. }
  116. }
  117. }
  118. }