SystemEntranceV2.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using ProjectManagementSystem.Common.Config;
  2. using ProjectManagementSystem.Common.Core;
  3. using ProjectManagementSystem.Common.TaskBookEvent;
  4. using ProjectManagementSystem.Common.TaskEvent;
  5. using ProjectManagementSystem.WebApi.Service;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ProjectManagementSystem.Enterance
  13. {
  14. public class SystemEntranceV2
  15. {
  16. public WebApiServerHost webApiServerHost = new WebApiServerHost();
  17. public SystemEntranceV2()
  18. {
  19. if (ExcelConfig.Instance == null)
  20. {
  21. string logContext = "Excel配置加载失败,启动失败";
  22. KillCurrentProcess(logContext);
  23. return;
  24. }
  25. if (!SystemInitialize.InitDataSource())
  26. {
  27. string logContext = "数据库初始化失败,启动失败";
  28. KillCurrentProcess(logContext);
  29. return;
  30. }
  31. //if (RouteCalled.Instance == null)
  32. //{
  33. // string logContext = "初始化RouteCalled失败,启动失败";
  34. // KillCurrentProcess(logContext);
  35. // return;
  36. //}
  37. if (PlcControl.Instance == null)
  38. {
  39. string logContext = "初始化Plc失败,启动失败";
  40. KillCurrentProcess(logContext);
  41. return;
  42. }
  43. if (DeviceControl.Instance == null)
  44. {
  45. string logContext = "初始化DeviceControl失败,启动失败";
  46. KillCurrentProcess(logContext);
  47. return;
  48. }
  49. //if (!webApiServerHost.StartServer())
  50. //{
  51. // string logContext = "初始化WebApi失败,启动失败";
  52. // KillCurrentProcess(logContext);
  53. // return;
  54. //}
  55. if (TaskBehavior.Instance == null)
  56. {
  57. string logContext = "初始化TaskBehavior失败,启动失败";
  58. KillCurrentProcess(logContext);
  59. return;
  60. }
  61. if (PackControl.Instance == null)
  62. {
  63. string logContext = "初始化PackControl失败,启动失败";
  64. KillCurrentProcess(logContext);
  65. return;
  66. }
  67. TaskBookRegister taskBookRegister = new TaskBookRegister();
  68. Task.Factory.StartNew(() =>
  69. {
  70. SystemInitialize.SystemStarted();
  71. SystemInitialize.InitWMS();
  72. SystemInitialize.InitWareHouse();
  73. SystemInitialize.InitOperate();
  74. SystemInitialize.InitAsyncBehavior();
  75. //SystemInitialize.InitLocationXY();
  76. //SystemInitialize.InitPmsAutoupdateXml();
  77. CTaskEvent taskEvent = new CTaskEvent();
  78. });
  79. }
  80. private void KillCurrentProcess(string logContext)
  81. {
  82. System.Windows.Forms.MessageBox.Show(logContext);
  83. System.Windows.Forms.Application.Exit();
  84. Process[] process = Process.GetProcesses();
  85. Process currentProcess = Process.GetCurrentProcess();
  86. for (int idx = 0; idx < process.Count(); idx++)
  87. {
  88. if (process[idx].ProcessName == currentProcess.ProcessName)
  89. {
  90. process[idx].Kill();
  91. }
  92. }
  93. return;
  94. }
  95. }
  96. }