25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

150 satır
5.1 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.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.Admin = configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList();
  78. HKLib.Configer.SaasRoute = DataBus.SaasRoute;
  79. RemoteService.PullShopInfo();
  80. //初始化表
  81. DbContext.InitTable();
  82. //服务器拉取数据
  83. ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push);
  84. ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push);
  85. //服务器拉取数据
  86. RemoteService.SyncTime();
  87. DataBus.UserListDto = HKLib.Interfaces.HKLibHelper.GetUserListSync("");
  88. RemoteService.GetCardStuatas();
  89. DataBus.saleLogDtos = new System.Collections.Concurrent.ConcurrentQueue<DTO.SaleLogDto>();
  90. RemoteService.GetFoodMenus();
  91. RemoteService.GetRangeCtrl();
  92. base.Configure();
  93. }
  94. /// <summary>
  95. /// 初始化VM
  96. /// </summary>
  97. protected override void Launch()
  98. {
  99. base.Launch();
  100. }
  101. /// <summary>
  102. /// 加载首页VM
  103. /// </summary>
  104. /// <param name="rootViewModel"></param>
  105. protected override void DisplayRootView(object rootViewModel)
  106. {
  107. base.DisplayRootView(rootViewModel);
  108. }
  109. /// <summary>
  110. ///VM加载完毕
  111. /// </summary>
  112. protected override void OnLaunch()
  113. {
  114. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  115. {
  116. JobDetail = "定时推送订单",
  117. Cron = DataBus.Cron,
  118. JobName = "订单",
  119. JobGroup = "订单"
  120. });
  121. base.OnLaunch();
  122. }
  123. /// <summary>
  124. /// 退出
  125. /// </summary>
  126. /// <param name="e"></param>
  127. protected override void OnExit(ExitEventArgs e)
  128. {
  129. base.OnExit(e);
  130. }
  131. /// <summary>
  132. /// 全局异常捕获
  133. /// </summary>
  134. /// <param name="e"></param>
  135. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  136. {
  137. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  138. GC.Collect();
  139. }
  140. }
  141. }