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.

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