DispatchSystem.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using ProjectManagementSystem.Common.Config;
  2. using ProjectManagementSystem.Common.Core;
  3. using ProjectManagementSystem.Common.Dispatch;
  4. using ProjectManagementSystem.Language;
  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. using System.Windows;
  13. namespace ProjectManagementSystemView.Entrance
  14. {
  15. public class DispatchSystem
  16. {
  17. public DispatchSystem()
  18. {
  19. if (ExcelConfig.Instance == null)
  20. {
  21. KillCurrentProcess(Langs.InitFailExcelConfig);
  22. return;
  23. }
  24. if (!SystemInitialize.InitDataSource())
  25. {
  26. KillCurrentProcess(Langs.InitFailDataSource);
  27. return;
  28. }
  29. //if (RouteCalled.Instance == null)
  30. //{
  31. // KillCurrentProcess(Langs.InitFailRouteCalled);
  32. // return;
  33. //}
  34. if (PlcControl.Instance == null)
  35. {
  36. KillCurrentProcess(Langs.InitFailPlcControl);
  37. return;
  38. }
  39. if (DeviceControl.Instance == null)
  40. {
  41. KillCurrentProcess(Langs.InitFailDeviceControl);
  42. return;
  43. }
  44. if (!WebApiServerHost.Instance.StartServer())
  45. {
  46. KillCurrentProcess(Langs.InitFailWebApi);
  47. return;
  48. }
  49. SystemInitialize.InitWMS();
  50. if (SimpleProcess.Instance == null)
  51. {
  52. KillCurrentProcess("SimpleProcess init failed");
  53. return;
  54. }
  55. if (PackDispatch.Instance == null)
  56. {
  57. KillCurrentProcess("PackDispatch init failed");
  58. return;
  59. }
  60. }
  61. private void KillCurrentProcess(string logContext)
  62. {
  63. MessageBox.Show(logContext);
  64. Application.Current.Shutdown();
  65. Process[] process = Process.GetProcesses();
  66. Process currentProcess = Process.GetCurrentProcess();
  67. for (int idx = 0; idx < process.Count(); idx++)
  68. {
  69. if (process[idx].ProcessName == currentProcess.ProcessName)
  70. {
  71. process[idx].Kill();
  72. }
  73. }
  74. return;
  75. }
  76. }
  77. }