25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
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. HKLogImport.Init("HKCardOUT");
  51. }
  52. protected override void ConfigureIoC(IStyletIoCBuilder builder)
  53. {
  54. builder.Bind<HKCore>().ToSelf();
  55. }
  56. /// <summary>
  57. /// 初始化系统相关参数配置
  58. /// </summary>
  59. protected override void Configure()
  60. {
  61. #if !DEBUG
  62. var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build();
  63. #else
  64. var configer = (new ConfigurationBuilder()).AddJsonFile("options.pro.json").Build();
  65. #endif
  66. DataBus.Entitys = new System.Collections.Concurrent.ConcurrentQueue<Logic.Model.SaleLog>();
  67. DataBus.ConnectionString = configer.GetConnectionString("Sqlite");
  68. DataBus.SaasRoute = configer["SaasRoute"];
  69. HKLib.Configer.MqAddress = configer["MQ"];
  70. DataBus.Cron = configer["Cron"];
  71. DataBus.Span = configer["Span"].AsInt();
  72. DataBus.StoreId = configer["StoreId"];
  73. DataBus.COM = configer["COM"];
  74. DataBus.TenantId = configer["TenantId"];
  75. DataBus.StartDevice = configer["StartDevice"].AsBool();
  76. DataBus.Cancel = configer["Cancel"].AsBool();
  77. DataBus.Count = configer["Count"].AsInt();
  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. base.Configure();
  96. }
  97. /// <summary>
  98. /// 初始化VM
  99. /// </summary>
  100. protected override void Launch()
  101. {
  102. base.Launch();
  103. }
  104. /// <summary>
  105. /// 加载首页VM
  106. /// </summary>
  107. /// <param name="rootViewModel"></param>
  108. protected override void DisplayRootView(object rootViewModel)
  109. {
  110. base.DisplayRootView(rootViewModel);
  111. }
  112. /// <summary>
  113. ///VM加载完毕
  114. /// </summary>
  115. protected override void OnLaunch()
  116. {
  117. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  118. {
  119. JobDetail = "定时推送订单",
  120. Cron = DataBus.Cron,
  121. JobName = "订单",
  122. JobGroup = "订单"
  123. });
  124. base.OnLaunch();
  125. }
  126. /// <summary>
  127. /// 退出
  128. /// </summary>
  129. /// <param name="e"></param>
  130. protected override void OnExit(ExitEventArgs e)
  131. {
  132. base.OnExit(e);
  133. }
  134. /// <summary>
  135. /// 全局异常捕获
  136. /// </summary>
  137. /// <param name="e"></param>
  138. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  139. {
  140. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  141. GC.Collect();
  142. }
  143. }
  144. }