Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

199 wiersze
7.0 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. using QuartzUtil.Job;
  22. using System.Collections.Generic;
  23. using DTO;
  24. namespace HKCardOUT
  25. {
  26. public class Bootstrapper : Bootstrapper<RootViewModel>
  27. {
  28. /// <summary>
  29. /// 程序启动
  30. /// </summary>
  31. protected override void OnStart()
  32. {
  33. ThreadManage.GetInstance().StartLong(new Action(() =>
  34. {
  35. try
  36. {
  37. bool ping = PingHelper.PingTest();
  38. //1.检测网络上下线
  39. bool network = HKHelpers.GetInstance().GetNetworkState();
  40. if (ping && network != DataBus.NetWordState)
  41. {
  42. DataBus.NetWordState = network && ping;
  43. if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  44. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  50. }
  51. Thread.Sleep(3000);
  52. }), "循环状态监测线程", false);
  53. var tm = RemoteService.GetNetWorkTime();
  54. ThreadManage.GetInstance().StartLong(new Action(() =>
  55. {
  56. DataBus.TodayTime = DateTime.Now;
  57. Thread.Sleep(1000 * 60);
  58. }), "刷新时间", true);
  59. HKLogImport.Init("HKCardOUT");
  60. HKLogImport.WriteInfo("程序初始化,时间:" + DateTime.Now);
  61. }
  62. protected override void ConfigureIoC(IStyletIoCBuilder builder)
  63. {
  64. builder.Bind<HKCore>().ToSelf();
  65. }
  66. /// <summary>
  67. /// 初始化系统相关参数配置
  68. /// </summary>
  69. protected override void Configure()
  70. {
  71. #if !DEBUG
  72. var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build();
  73. #else
  74. var configer = (new ConfigurationBuilder()).AddJsonFile("options.pro.json").Build();
  75. #endif
  76. DataBus.Entitys = new System.Collections.Concurrent.ConcurrentQueue<Logic.Model.SaleLog>();
  77. DataBus.ConnectionString = configer.GetConnectionString("Sqlite");
  78. DataBus.SaasRoute = configer["SaasRoute"];
  79. HKLib.Configer.MqAddress = configer["MQ"];
  80. DataBus.Cron = configer["Cron"];
  81. DataBus.Span = configer["Span"].AsInt();
  82. DataBus.StoreId = configer["StoreId"];
  83. DataBus.COM = configer["COM"];
  84. DataBus.TenantId = configer["TenantId"];
  85. DataBus.StartDevice = configer["StartDevice"].AsBool();
  86. DataBus.Cancel = configer["Cancel"].AsBool();
  87. DataBus.Count = configer["Count"].AsInt();
  88. DataBus.MQTT = configer["MQTT"].ToString();
  89. DataBus.Admin = configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList();
  90. HKLib.Configer.SaasRoute = DataBus.SaasRoute;
  91. RemoteService.PullShopInfo();
  92. //初始化表
  93. DbContext.InitTable();
  94. //服务器拉取数据
  95. ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push);
  96. ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push);
  97. ServiceQueryExcute.QueryExcute.ExtuteMQ<FoodHandle, string>("GateFood", MQEnum.Push);
  98. ServiceQueryExcute.QueryExcute.ExtuteMQ<NewCardHandle, string>("NewCardChanged", MQEnum.Top);
  99. //服务器拉取数据
  100. RemoteService.SyncTime();
  101. DataBus.UserListDto = HKLib.Interfaces.HKLibHelper.GetUserListSync("");
  102. RemoteService.GetCardStuatas();
  103. DataBus.saleLogDtos = new System.Collections.Concurrent.ConcurrentQueue<DTO.SaleLogDto>();
  104. RemoteService.GetFoodMenus();
  105. RemoteService.GetRangeCtrl();
  106. MQTTCon.Connection();
  107. base.Configure();
  108. }
  109. /// <summary>
  110. /// 初始化VM
  111. /// </summary>
  112. protected override void Launch()
  113. {
  114. base.Launch();
  115. }
  116. /// <summary>
  117. /// 加载首页VM
  118. /// </summary>
  119. /// <param name="rootViewModel"></param>
  120. protected override void DisplayRootView(object rootViewModel)
  121. {
  122. base.DisplayRootView(rootViewModel);
  123. }
  124. /// <summary>
  125. ///VM加载完毕
  126. /// </summary>
  127. protected override void OnLaunch()
  128. {
  129. //List<SaleDto> dto = new List<SaleDto>();
  130. //Guid.TryParse("3f8861ef-0ae0-469c-8c2d-7eec8df8a6d1", out Guid t);
  131. //var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == 6)?.GateId;
  132. //dto.Add(new SaleDto()
  133. //{
  134. // CardNum = "1590198442460844032",
  135. // CreateAt = Convert.ToDateTime("2022-11-09 15:07:51.0397808"),
  136. // Id = t,
  137. // GateId = GateId,
  138. // Type = -1
  139. //});
  140. //dto.Add(new SaleDto()
  141. //{
  142. // CardNum = "1590198442460844032",
  143. // CreateAt = Convert.ToDateTime("2022-11-09 15:07:51.0397808"),
  144. // Id = t,
  145. // GateId = GateId,
  146. // Type = -1
  147. //});
  148. //RemoteService.SyncSaleLogList(dto);
  149. QuartzCoreFactory.QuartzCore().AddJob<CardJob>(new QuartzMap
  150. {
  151. JobDetail = "定时同步卡",
  152. JobName = "同步卡",
  153. JobGroup = "同步卡",
  154. Cron= "* 0/5 * * * ?"
  155. });
  156. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  157. {
  158. JobDetail = "定时推送订单",
  159. Cron = DataBus.Cron,
  160. JobName = "订单",
  161. JobGroup = "订单"
  162. });
  163. base.OnLaunch();
  164. }
  165. /// <summary>
  166. /// 退出
  167. /// </summary>
  168. /// <param name="e"></param>
  169. protected override void OnExit(ExitEventArgs e)
  170. {
  171. base.OnExit(e);
  172. }
  173. /// <summary>
  174. /// 全局异常捕获
  175. /// </summary>
  176. /// <param name="e"></param>
  177. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  178. {
  179. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  180. GC.Collect();
  181. }
  182. }
  183. }