Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

131 linhas
4.1 KiB

  1. using HKCardOUT.ViewModels;
  2. using Stylet;
  3. using StyletIoC;
  4. using System;
  5. using System.Windows.Threading;
  6. using System.Windows;
  7. using Microsoft.Extensions.Configuration;
  8. using HKCardOUT.Helper;
  9. using HKCardOUT.QuartzUtil.Job;
  10. using HKCardOUT.QuartzUtil;
  11. using HKCardOUT.Logic;
  12. using HKCardOUT.Logic.Service;
  13. using ImTools;
  14. using XExten.Advance.LinqFramework;
  15. using System.Threading;
  16. using HKLog;
  17. namespace HKCardOUT
  18. {
  19. public class Bootstrapper : Bootstrapper<RootViewModel>
  20. {
  21. /// <summary>
  22. /// 程序启动
  23. /// </summary>
  24. protected override void OnStart()
  25. {
  26. ThreadManage.GetInstance().StartLong(new Action(() =>
  27. {
  28. try
  29. {
  30. bool ping = PingHelper.PingTest();
  31. //1.检测网络上下线
  32. bool network = HKHelpers.GetInstance().GetNetworkState();
  33. if (ping && network != DataBus.NetWordState)
  34. {
  35. DataBus.NetWordState = network && ping;
  36. if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  37. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  38. }
  39. }
  40. catch (Exception ex)
  41. {
  42. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  43. }
  44. Thread.Sleep(3000);
  45. }), "循环状态监测线程", false);
  46. HKLog.HKLogImport.Init("HKCardOUT");
  47. }
  48. protected override void ConfigureIoC(IStyletIoCBuilder builder)
  49. {
  50. builder.Bind<HKCore>().ToSelf();
  51. }
  52. /// <summary>
  53. /// 初始化系统相关参数配置
  54. /// </summary>
  55. protected override void Configure()
  56. {
  57. var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build();
  58. DataBus.ConnectionString = configer.GetConnectionString("Sqlite");
  59. DataBus.Cron = configer["Cron"];
  60. DataBus.SaasRoute = configer["SaasRoute"];
  61. DataBus.StoreId = configer["StoreId"];
  62. DataBus.COM = configer["COM"];
  63. DataBus.StartDevice = configer["StartDevice"].AsBool();
  64. DataBus.Cancel = configer["Cancel"].AsBool();
  65. DataBus.AM = configer["AM"];
  66. DataBus.PM = configer["PM"];
  67. DataBus.Count = configer["Count"].AsInt();
  68. DataBus.AT = configer["AT"];
  69. HKLib.Configer.SaasRoute = DataBus.SaasRoute;
  70. HKLib.Configer.MqAddress = configer["MQ"];
  71. DbContext.InitTable();
  72. RemoteService.PullShopInfo();
  73. base.Configure();
  74. }
  75. /// <summary>
  76. /// 初始化VM
  77. /// </summary>
  78. protected override void Launch()
  79. {
  80. base.Launch();
  81. }
  82. /// <summary>
  83. /// 加载首页VM
  84. /// </summary>
  85. /// <param name="rootViewModel"></param>
  86. protected override void DisplayRootView(object rootViewModel)
  87. {
  88. base.DisplayRootView(rootViewModel);
  89. }
  90. /// <summary>
  91. ///VM加载完毕
  92. /// </summary>
  93. protected override void OnLaunch()
  94. {
  95. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  96. {
  97. JobDetail = "定时推送订单",
  98. Cron = DataBus.Cron,
  99. JobName = "订单",
  100. JobGroup = "订单"
  101. });
  102. base.OnLaunch();
  103. }
  104. /// <summary>
  105. /// 退出
  106. /// </summary>
  107. /// <param name="e"></param>
  108. protected override void OnExit(ExitEventArgs e)
  109. {
  110. base.OnExit(e);
  111. }
  112. /// <summary>
  113. /// 全局异常捕获
  114. /// </summary>
  115. /// <param name="e"></param>
  116. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  117. {
  118. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  119. GC.Collect();
  120. }
  121. }
  122. }