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.

141 lines
4.6 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. using HKLib.RabbitMQ.Config;
  18. using HKLib.RabbitMQ.Subscriber;
  19. namespace HKCardOUT
  20. {
  21. public class Bootstrapper : Bootstrapper<RootViewModel>
  22. {
  23. /// <summary>
  24. /// 程序启动
  25. /// </summary>
  26. protected override void OnStart()
  27. {
  28. ThreadManage.GetInstance().StartLong(new Action(() =>
  29. {
  30. try
  31. {
  32. bool ping = PingHelper.PingTest();
  33. //1.检测网络上下线
  34. bool network = HKHelpers.GetInstance().GetNetworkState();
  35. if (ping && network != DataBus.NetWordState)
  36. {
  37. DataBus.NetWordState = network && ping;
  38. if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  39. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  40. }
  41. }
  42. catch (Exception ex)
  43. {
  44. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  45. }
  46. Thread.Sleep(3000);
  47. }), "循环状态监测线程", false);
  48. HKLogImport.Init("HKCardOUT");
  49. }
  50. protected override void ConfigureIoC(IStyletIoCBuilder builder)
  51. {
  52. builder.Bind<HKCore>().ToSelf();
  53. }
  54. /// <summary>
  55. /// 初始化系统相关参数配置
  56. /// </summary>
  57. protected override void Configure()
  58. {
  59. #if DEBUG
  60. var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build();
  61. #else
  62. var configer = (new ConfigurationBuilder()).AddJsonFile("options.pro.json").Build();
  63. #endif
  64. DataBus.ConnectionString = configer.GetConnectionString("Sqlite");
  65. HKLib.Configer.MqAddress = configer["MQ"];
  66. DataBus.Cron = configer["Cron"];
  67. DataBus.SaasRoute = configer["SaasRoute"];
  68. DataBus.StoreId = configer["StoreId"];
  69. DataBus.COM = configer["COM"];
  70. DataBus.TenantId = configer["TenantId"];
  71. DataBus.StartDevice = configer["StartDevice"].AsBool();
  72. DataBus.Cancel = configer["Cancel"].AsBool();
  73. DataBus.Count = configer["Count"].AsInt();
  74. //初始化表
  75. DbContext.InitTable();
  76. ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push);
  77. ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push);
  78. HKLib.Configer.SaasRoute = DataBus.SaasRoute;
  79. //服务器拉取数据
  80. RemoteService.SyncTime();
  81. RemoteService.GetCardStuatas();
  82. RemoteService.PullShopInfo();
  83. base.Configure();
  84. }
  85. /// <summary>
  86. /// 初始化VM
  87. /// </summary>
  88. protected override void Launch()
  89. {
  90. base.Launch();
  91. }
  92. /// <summary>
  93. /// 加载首页VM
  94. /// </summary>
  95. /// <param name="rootViewModel"></param>
  96. protected override void DisplayRootView(object rootViewModel)
  97. {
  98. base.DisplayRootView(rootViewModel);
  99. }
  100. /// <summary>
  101. ///VM加载完毕
  102. /// </summary>
  103. protected override void OnLaunch()
  104. {
  105. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  106. {
  107. JobDetail = "定时推送订单",
  108. Cron = DataBus.Cron,
  109. JobName = "订单",
  110. JobGroup = "订单"
  111. });
  112. base.OnLaunch();
  113. }
  114. /// <summary>
  115. /// 退出
  116. /// </summary>
  117. /// <param name="e"></param>
  118. protected override void OnExit(ExitEventArgs e)
  119. {
  120. base.OnExit(e);
  121. }
  122. /// <summary>
  123. /// 全局异常捕获
  124. /// </summary>
  125. /// <param name="e"></param>
  126. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  127. {
  128. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  129. GC.Collect();
  130. }
  131. }
  132. }