Não pode escolher mais do que 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.

Bootstrapper.cs 6.1 KiB

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