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.

144 rivejä
4.7 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. namespace HKCardOUT
  21. {
  22. public class Bootstrapper : Bootstrapper<RootViewModel>
  23. {
  24. /// <summary>
  25. /// 程序启动
  26. /// </summary>
  27. protected override void OnStart()
  28. {
  29. ThreadManage.GetInstance().StartLong(new Action(() =>
  30. {
  31. try
  32. {
  33. bool ping = PingHelper.PingTest();
  34. //1.检测网络上下线
  35. bool network = HKHelpers.GetInstance().GetNetworkState();
  36. if (ping && network != DataBus.NetWordState)
  37. {
  38. DataBus.NetWordState = network && ping;
  39. if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  40. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  41. }
  42. }
  43. catch (Exception ex)
  44. {
  45. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  46. }
  47. Thread.Sleep(3000);
  48. }), "循环状态监测线程", false);
  49. HKLogImport.Init("HKCardOUT");
  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.ConnectionString = configer.GetConnectionString("Sqlite");
  66. DataBus.SaasRoute = configer["SaasRoute"];
  67. HKLib.Configer.MqAddress = configer["MQ"];
  68. DataBus.Cron = configer["Cron"];
  69. DataBus.Span= configer["Span"].AsInt();
  70. DataBus.StoreId = configer["StoreId"];
  71. DataBus.COM = configer["COM"];
  72. DataBus.TenantId = configer["TenantId"];
  73. DataBus.StartDevice = configer["StartDevice"].AsBool();
  74. DataBus.Cancel = configer["Cancel"].AsBool();
  75. DataBus.Count = configer["Count"].AsInt();
  76. DataBus.Admin= configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList();
  77. HKLib.Configer.SaasRoute = DataBus.SaasRoute;
  78. RemoteService.PullShopInfo();
  79. //初始化表
  80. DbContext.InitTable();
  81. ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push);
  82. ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push);
  83. //服务器拉取数据
  84. RemoteService.SyncTime();
  85. RemoteService.GetCardStuatas();
  86. base.Configure();
  87. }
  88. /// <summary>
  89. /// 初始化VM
  90. /// </summary>
  91. protected override void Launch()
  92. {
  93. base.Launch();
  94. }
  95. /// <summary>
  96. /// 加载首页VM
  97. /// </summary>
  98. /// <param name="rootViewModel"></param>
  99. protected override void DisplayRootView(object rootViewModel)
  100. {
  101. base.DisplayRootView(rootViewModel);
  102. }
  103. /// <summary>
  104. ///VM加载完毕
  105. /// </summary>
  106. protected override void OnLaunch()
  107. {
  108. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  109. {
  110. JobDetail = "定时推送订单",
  111. Cron = DataBus.Cron,
  112. JobName = "订单",
  113. JobGroup = "订单"
  114. });
  115. base.OnLaunch();
  116. }
  117. /// <summary>
  118. /// 退出
  119. /// </summary>
  120. /// <param name="e"></param>
  121. protected override void OnExit(ExitEventArgs e)
  122. {
  123. base.OnExit(e);
  124. }
  125. /// <summary>
  126. /// 全局异常捕获
  127. /// </summary>
  128. /// <param name="e"></param>
  129. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  130. {
  131. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  132. GC.Collect();
  133. }
  134. }
  135. }