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.

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