Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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