Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

143 rader
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.StoreId = configer["StoreId"];
  70. DataBus.COM = configer["COM"];
  71. DataBus.TenantId = configer["TenantId"];
  72. DataBus.StartDevice = configer["StartDevice"].AsBool();
  73. DataBus.Cancel = configer["Cancel"].AsBool();
  74. DataBus.Count = configer["Count"].AsInt();
  75. DataBus.Admin= configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList();
  76. HKLib.Configer.SaasRoute = DataBus.SaasRoute;
  77. RemoteService.PullShopInfo();
  78. //初始化表
  79. DbContext.InitTable();
  80. ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push);
  81. ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push);
  82. //服务器拉取数据
  83. RemoteService.SyncTime();
  84. RemoteService.GetCardStuatas();
  85. base.Configure();
  86. }
  87. /// <summary>
  88. /// 初始化VM
  89. /// </summary>
  90. protected override void Launch()
  91. {
  92. base.Launch();
  93. }
  94. /// <summary>
  95. /// 加载首页VM
  96. /// </summary>
  97. /// <param name="rootViewModel"></param>
  98. protected override void DisplayRootView(object rootViewModel)
  99. {
  100. base.DisplayRootView(rootViewModel);
  101. }
  102. /// <summary>
  103. ///VM加载完毕
  104. /// </summary>
  105. protected override void OnLaunch()
  106. {
  107. QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
  108. {
  109. JobDetail = "定时推送订单",
  110. Cron = DataBus.Cron,
  111. JobName = "订单",
  112. JobGroup = "订单"
  113. });
  114. base.OnLaunch();
  115. }
  116. /// <summary>
  117. /// 退出
  118. /// </summary>
  119. /// <param name="e"></param>
  120. protected override void OnExit(ExitEventArgs e)
  121. {
  122. base.OnExit(e);
  123. }
  124. /// <summary>
  125. /// 全局异常捕获
  126. /// </summary>
  127. /// <param name="e"></param>
  128. protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
  129. {
  130. HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
  131. GC.Collect();
  132. }
  133. }
  134. }