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; using BPA.Helper; using QuartzUtil.Job; using System.Collections.Generic; using DTO; namespace HKCardOUT { public class Bootstrapper : Bootstrapper { /// /// 程序启动 /// 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); var tm = RemoteService.GetNetWorkTime(); ThreadManage.GetInstance().StartLong(new Action(() => { DataBus.TodayTime = DateTime.Now; Thread.Sleep(1000 * 60); }), "刷新时间", true); HKLogImport.Init("HKCardOUT"); HKLogImport.WriteInfo("程序初始化,时间:" + DateTime.Now); } protected override void ConfigureIoC(IStyletIoCBuilder builder) { builder.Bind().ToSelf(); } /// /// 初始化系统相关参数配置 /// 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.Entitys = new System.Collections.Concurrent.ConcurrentQueue(); 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.MQTT = configer["MQTT"].ToString(); DataBus.Admin = configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList(); HKLib.Configer.SaasRoute = DataBus.SaasRoute; RemoteService.PullShopInfo(); //初始化表 DbContext.InitTable(); //服务器拉取数据 ServiceQueryExcute.QueryExcute.ExtuteMQ("CardStutasChanged", MQEnum.Push); ServiceQueryExcute.QueryExcute.ExtuteMQ("TimeChanged", MQEnum.Push); ServiceQueryExcute.QueryExcute.ExtuteMQ("GateFood", MQEnum.Push); ServiceQueryExcute.QueryExcute.ExtuteMQ("NewCardChanged", MQEnum.Top); //服务器拉取数据 RemoteService.SyncTime(); DataBus.UserListDto = HKLib.Interfaces.HKLibHelper.GetUserListSync(""); RemoteService.GetCardStuatas(); DataBus.saleLogDtos = new System.Collections.Concurrent.ConcurrentQueue(); RemoteService.GetFoodMenus(); RemoteService.GetRangeCtrl(); MQTTCon.Connection(); base.Configure(); } /// /// 初始化VM /// protected override void Launch() { base.Launch(); } /// /// 加载首页VM /// /// protected override void DisplayRootView(object rootViewModel) { base.DisplayRootView(rootViewModel); } /// ///VM加载完毕 /// protected override void OnLaunch() { //List dto = new List(); //Guid.TryParse("3f8861ef-0ae0-469c-8c2d-7eec8df8a6d1", out Guid t); //var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == 6)?.GateId; //dto.Add(new SaleDto() //{ // CardNum = "1590198442460844032", // CreateAt = Convert.ToDateTime("2022-11-09 15:07:51.0397808"), // Id = t, // GateId = GateId, // Type = -1 //}); //dto.Add(new SaleDto() //{ // CardNum = "1590198442460844032", // CreateAt = Convert.ToDateTime("2022-11-09 15:07:51.0397808"), // Id = t, // GateId = GateId, // Type = -1 //}); //RemoteService.SyncSaleLogList(dto); QuartzCoreFactory.QuartzCore().AddJob(new QuartzMap { JobDetail = "定时同步卡", JobName = "同步卡", JobGroup = "同步卡", Cron= "* 0/5 * * * ?" }); QuartzCoreFactory.QuartzCore().AddJob(new QuartzMap { JobDetail = "定时推送订单", Cron = DataBus.Cron, JobName = "订单", JobGroup = "订单" }); base.OnLaunch(); } /// /// 退出 /// /// protected override void OnExit(ExitEventArgs e) { base.OnExit(e); } /// /// 全局异常捕获 /// /// protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e) { HKLog.HKLogImport.WriteError(e.Exception.InnerException != null ? e.Exception.InnerException : e.Exception); GC.Collect(); } } }