|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using HKCardOUT.ViewModels;
- using Stylet;
- using StyletIoC;
- using System;
- using System.Windows.Threading;
- using System.Windows;
- using Microsoft.Extensions.Configuration;
- using HKCardOUT.Helper;
- using HKCardOUT.QuartzUtil.Job;
- using HKCardOUT.QuartzUtil;
- using HKCardOUT.Logic;
- using HKCardOUT.Logic.Service;
- using ImTools;
- using XExten.Advance.LinqFramework;
- using System.Threading;
- using HKLog;
- using HKLib.RabbitMQ.Config;
- using HKLib.RabbitMQ.Subscriber;
- using System.Linq;
-
- namespace HKCardOUT
- {
- public class Bootstrapper : Bootstrapper<RootViewModel>
- {
- /// <summary>
- /// 程序启动
- /// </summary>
- protected override void OnStart()
- {
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- try
- {
- bool ping = PingHelper.PingTest();
- //1.检测网络上下线
- bool network = HKHelpers.GetInstance().GetNetworkState();
- if (ping && network != DataBus.NetWordState)
- {
- DataBus.NetWordState = network && ping;
- if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
- else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
- }
- }
- catch (Exception ex)
- {
- HandyControl.Controls.Growl.InfoGlobal(ex.Message);
- }
- Thread.Sleep(3000);
- }), "循环状态监测线程", false);
- HKLogImport.Init("HKCardOUT");
- }
-
- protected override void ConfigureIoC(IStyletIoCBuilder builder)
- {
- builder.Bind<HKCore>().ToSelf();
- }
-
- /// <summary>
- /// 初始化系统相关参数配置
- /// </summary>
- protected override void Configure()
- {
- #if DEBUG
- var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build();
- #else
- var configer = (new ConfigurationBuilder()).AddJsonFile("options.pro.json").Build();
- #endif
- DataBus.ConnectionString = configer.GetConnectionString("Sqlite");
- DataBus.SaasRoute = configer["SaasRoute"];
- HKLib.Configer.MqAddress = configer["MQ"];
- DataBus.Cron = configer["Cron"];
- DataBus.Span= configer["Span"].AsInt();
- DataBus.StoreId = configer["StoreId"];
- DataBus.COM = configer["COM"];
- DataBus.TenantId = configer["TenantId"];
- DataBus.StartDevice = configer["StartDevice"].AsBool();
- DataBus.Cancel = configer["Cancel"].AsBool();
- DataBus.Count = configer["Count"].AsInt();
- DataBus.Admin= configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList();
- HKLib.Configer.SaasRoute = DataBus.SaasRoute;
- RemoteService.PullShopInfo();
- //初始化表
- DbContext.InitTable();
- ServiceQueryExcute.QueryExcute.ExtuteMQ<CardHandle, string>("CardStutasChanged", MQEnum.Push);
- ServiceQueryExcute.QueryExcute.ExtuteMQ<TimeHandle, string>("TimeChanged", MQEnum.Push);
- //服务器拉取数据
- RemoteService.SyncTime();
- RemoteService.GetCardStuatas();
- base.Configure();
- }
-
- /// <summary>
- /// 初始化VM
- /// </summary>
- protected override void Launch()
- {
- base.Launch();
- }
-
- /// <summary>
- /// 加载首页VM
- /// </summary>
- /// <param name="rootViewModel"></param>
- protected override void DisplayRootView(object rootViewModel)
- {
- base.DisplayRootView(rootViewModel);
- }
-
- /// <summary>
- ///VM加载完毕
- /// </summary>
- protected override void OnLaunch()
- {
- QuartzCoreFactory.QuartzCore().AddJob<QuartzJob>(new QuartzMap
- {
- JobDetail = "定时推送订单",
- Cron = DataBus.Cron,
- JobName = "订单",
- JobGroup = "订单"
- });
- base.OnLaunch();
- }
-
- /// <summary>
- /// 退出
- /// </summary>
- /// <param name="e"></param>
- protected override void OnExit(ExitEventArgs e)
- {
- base.OnExit(e);
- }
-
- /// <summary>
- /// 全局异常捕获
- /// </summary>
- /// <param name="e"></param>
- protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
- {
- HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception);
- GC.Collect();
- }
- }
- }
|