From 55eece9c697af5df8bb72a980493df6d6041322c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Sat, 26 Mar 2022 12:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=A1=86=E6=9E=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Business/HeartbeatReport.cs | 2 +- HBLConsole.Business/IotReport.cs | 4 +- HBLConsole.Business/M2MqttHelper.cs | 2 +- HBLConsole.Business/MessageServer/Base.cs | 8 +- HBLConsole.Business/ServerData.cs | 2 +- HBLConsole.Communication/ConnectHelper.cs | 2 +- .../HBLConsole.Communication.csproj | 1 - HBLConsole.Communication/ModbusTcpHelper.cs | 4 +- .../ViewModel/ViewModel_MORKIC.cs | 10 +- HBLConsole.Factory/SimpleFactory.cs | 12 +- HBLConsole.MORKD/Control_MORKD.cs | 14 +- HBLConsole.MORKIC/Control_MORKIC.cs | 12 +- HBLConsole.MORKS/Control_MORKS.cs | 12 +- HBLConsole.MainConsole/Main.cs | 4 +- HBLConsole.Model/HBLConsole.Model.csproj | 2 +- HBLConsole.Model/SQL/VariableInfo.cs | 2 +- HBLConsole.Service/ActionManage.cs | 129 +++++++++++++ HBLConsole.Service/ActionOperate.cs | 119 ------------ HBLConsole.Service/ExpandMethod.cs | 79 ++++++-- HBLConsole.Service/HBLConsole.Service.csproj | 2 +- HBLConsole.Service/Json.cs | 2 +- HBLConsole.Service/SystemHelper.cs | 3 +- HBLConsole.Service/ThreadManage.cs | 172 ++++++++++++++++++ HBLConsole.Service/ThreadOperate.cs | 153 ---------------- HBLConsole/App.xaml.cs | 4 +- .../View/DeviceManagermentSetView.xaml.cs | 8 +- .../View/SimOrderConfitView.xaml.cs | 8 +- .../DeviceManagermentSetViewModel.cs | 4 +- .../ViewModel/ListDialogViewModel.cs | 6 +- .../ViewModel/SimOrderConfitViewModel.cs | 6 +- HBLConsole/View/DeviceManageView.xaml.cs | 2 +- HBLConsole/View/VariableConfig.xaml.cs | 2 +- HBLConsole/ViewModel/DebugViewModel.cs | 10 +- HBLConsole/ViewModel/MainViewModel.cs | 4 +- .../ViewModel/ProcessMonitoringViewModel.cs | 2 +- HBLConsole/ViewModel/VariableConfig.cs | 4 +- .../ViewModel/VariableMonitorViewModel.cs | 2 +- HBLConsole/ViewModel/ViewModelBase.cs | 4 +- HBLDevice.Coffee/CoffeeMachine.cs | 8 +- HBLDevice.ICChip/HBLDevice.ICChip.csproj | 2 +- HBLDevice.ICChip/ICChipMachine.cs | 2 +- HBLDevice.IceCream/IceCreamMachine.cs | 4 +- 42 files changed, 452 insertions(+), 382 deletions(-) create mode 100644 HBLConsole.Service/ActionManage.cs delete mode 100644 HBLConsole.Service/ActionOperate.cs create mode 100644 HBLConsole.Service/ThreadManage.cs delete mode 100644 HBLConsole.Service/ThreadOperate.cs diff --git a/HBLConsole.Business/HeartbeatReport.cs b/HBLConsole.Business/HeartbeatReport.cs index 2056eff..518e5c1 100644 --- a/HBLConsole.Business/HeartbeatReport.cs +++ b/HBLConsole.Business/HeartbeatReport.cs @@ -34,7 +34,7 @@ namespace HBLConsole.Business deviceStatus.DeviceType = GeneralConfig.DeviceType; Topic = TOPIC.GetInstance.GetHeatbeatTopic(GeneralConfig.DeviceType); - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { deviceStatus.BatchingInfo = GeneralConfig.BatchingInfos; deviceStatus.Healthy = GeneralConfig.Healthy ? DeviceHealthy.Health : DeviceHealthy.UnHealth; diff --git a/HBLConsole.Business/IotReport.cs b/HBLConsole.Business/IotReport.cs index 206178f..ef84063 100644 --- a/HBLConsole.Business/IotReport.cs +++ b/HBLConsole.Business/IotReport.cs @@ -151,7 +151,7 @@ namespace HBLConsole.Business /// public void Init() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { if (IOTDev.client.IsConnected && GeneralConfig.DeviceType.ToString() == "MORKS") { @@ -173,7 +173,7 @@ namespace HBLConsole.Business { IOTCommandModel iOTCommand = Tools.JsonToObjectTools(message); if (iOTCommand.deviceName == InternetInfo.DeviceName) - ActionOperate.GetInstance.Send("IotBroadcast", iOTCommand); + ActionManage.GetInstance.Send("IotBroadcast", iOTCommand); } } #endregion diff --git a/HBLConsole.Business/M2MqttHelper.cs b/HBLConsole.Business/M2MqttHelper.cs index 8d9e9da..6b71abb 100644 --- a/HBLConsole.Business/M2MqttHelper.cs +++ b/HBLConsole.Business/M2MqttHelper.cs @@ -22,7 +22,7 @@ namespace HBLConsole.Business public void Init() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { //AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.MCUDisconnected, "单片机掉线", AlarmLevel.严重报警); //AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.IceCreamAbnormal, "冰淇淋机异常"); diff --git a/HBLConsole.Business/MessageServer/Base.cs b/HBLConsole.Business/MessageServer/Base.cs index f715b97..889b928 100644 --- a/HBLConsole.Business/MessageServer/Base.cs +++ b/HBLConsole.Business/MessageServer/Base.cs @@ -31,8 +31,8 @@ namespace HBLConsole.Business.MessageServer IsSelected = true, OrderPush = morkOrderpush }); - ActionOperate.GetInstance.Send("AddOrder", morkOrderpush); - ActionOperate.GetInstance.Send("DataParse", morkOrderpush); + ActionManage.GetInstance.Send("AddOrder", morkOrderpush); + ActionManage.GetInstance.Send("DataParse", morkOrderpush); } } } @@ -73,7 +73,7 @@ namespace HBLConsole.Business.MessageServer if (PushType == 1) { Json.Data.recipeBoms = JsonConvert.DeserializeObject(result); - ActionOperate.GetInstance.Send("recipeBom"); + ActionManage.GetInstance.Send("recipeBom"); //WritePlcData(); } else if (PushType == 0) @@ -107,7 +107,7 @@ namespace HBLConsole.Business.MessageServer { Json.Data.recipeBoms = recipeBom; MessageLog.GetInstance.Show("接收到辅料信息"); - ActionOperate.GetInstance.Send("recipeBom"); + ActionManage.GetInstance.Send("recipeBom"); } //WritePlcData(); } diff --git a/HBLConsole.Business/ServerData.cs b/HBLConsole.Business/ServerData.cs index 7ed3d28..41012c8 100644 --- a/HBLConsole.Business/ServerData.cs +++ b/HBLConsole.Business/ServerData.cs @@ -24,7 +24,7 @@ namespace HBLConsole.Business public void Init() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { while (receives.Count > 0) { diff --git a/HBLConsole.Communication/ConnectHelper.cs b/HBLConsole.Communication/ConnectHelper.cs index c547c74..89cd5f5 100644 --- a/HBLConsole.Communication/ConnectHelper.cs +++ b/HBLConsole.Communication/ConnectHelper.cs @@ -57,7 +57,7 @@ namespace HBLConsole.Communication //} } } - ActionOperate.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk"); + ActionManage.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk"); } } diff --git a/HBLConsole.Communication/HBLConsole.Communication.csproj b/HBLConsole.Communication/HBLConsole.Communication.csproj index 9148dc0..f878f0b 100644 --- a/HBLConsole.Communication/HBLConsole.Communication.csproj +++ b/HBLConsole.Communication/HBLConsole.Communication.csproj @@ -13,7 +13,6 @@ - diff --git a/HBLConsole.Communication/ModbusTcpHelper.cs b/HBLConsole.Communication/ModbusTcpHelper.cs index 08c2161..5522c86 100644 --- a/HBLConsole.Communication/ModbusTcpHelper.cs +++ b/HBLConsole.Communication/ModbusTcpHelper.cs @@ -47,8 +47,8 @@ namespace HBLConsole.Communication master.Transport.ReadTimeout = 2000;//读取超时时间 master.Transport.WriteTimeout = 2000;//写入超时时间 master.Transport.Retries = 10;//重试次数 - //ActionOperate.GetInstance.Send("ConnectOk"); - //ActionOperate.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk"); + //ActionManage.GetInstance.Send("ConnectOk"); + //ActionManage.GetInstance.Send($"{GVL.GeneralConfig.DeviceType.ToString()}/ConnectOk"); MessageLog.GetInstance.Show($"设备【{ip}:{port}】连接成功"); } diff --git a/HBLConsole.Debug/ViewModel/ViewModel_MORKIC.cs b/HBLConsole.Debug/ViewModel/ViewModel_MORKIC.cs index 052005b..fc7f1ee 100644 --- a/HBLConsole.Debug/ViewModel/ViewModel_MORKIC.cs +++ b/HBLConsole.Debug/ViewModel/ViewModel_MORKIC.cs @@ -105,11 +105,11 @@ namespace HBLConsole.Debug - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { - RobotConnected = LebaiHelper.GetInstance.IsConnected?"已连接":"未连接"; - IceCreamConnected = MorkIStatus.GetInstance().OnLine ? "已连接":"未连接"; - CoffeeConnected = MorkCStatus.GetInstance().OnLine ? "已连接": "未连接"; + RobotConnected = LebaiHelper.GetInstance.IsConnected ? "已连接" : "未连接"; + IceCreamConnected = MorkIStatus.GetInstance().OnLine ? "已连接" : "未连接"; + CoffeeConnected = MorkCStatus.GetInstance().OnLine ? "已连接" : "未连接"; @@ -126,7 +126,7 @@ namespace HBLConsole.Debug CurrentMode = MorkIStatus.GetInstance().CurrentMode; IceCreamFault = MorkIStatus.GetInstance().Fault; CXB = MorkIStatus.GetInstance().CXB; - DLCompleted = MorkIStatus.GetInstance().DLCompleted?"打料完成":"打料中"; + DLCompleted = MorkIStatus.GetInstance().DLCompleted ? "打料完成" : "打料中"; Thread.Sleep(500); }), "MORK IC-状态刷新"); } diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index bf7a6d3..24dd314 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -15,7 +15,7 @@ namespace HBLConsole.Factory private volatile static SimpleFactory _Instance; public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory()); - private SimpleFactory() { ActionOperate.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); } + private SimpleFactory() { ActionManage.GetInstance.Register(new Action(() => { GetInterfaceData(); }), "ResetProgram"); } public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer()); private AbstractMessageServer _GetAbsMessageServer; @@ -50,7 +50,7 @@ namespace HBLConsole.Factory bool res = GetAbsMessageServer.OrderStatusChange(subid, status); if (res) { - ActionOperate.GetInstance.Send("OrderStatusChange", new OrderStatusChange() + ActionManage.GetInstance.Send("OrderStatusChange", new OrderStatusChange() { CookingStatus = status, SuborderId = subid @@ -86,10 +86,10 @@ namespace HBLConsole.Factory GetBatchingInfo(); GetInterfaceData(); control?.Init(); - ActionOperate.GetInstance.Register(new Action((o) => { control?.DataParse(o); }), "DataParse"); - ActionOperate.GetInstance.Register(new Action(() => { control?.ConnectOk(); }), $"{GeneralConfig.DeviceType.ToString()}/ConnectOk"); - ActionOperate.GetInstance.Register(new Action((o) => { control?.SimOrder(o); }), "SimOrder"); - ActionOperate.GetInstance.Register(new Action((o) => { control?.IotBroadcast(o); }), "IotBroadcast"); + ActionManage.GetInstance.Register(new Action((o) => { control?.DataParse(o); }), "DataParse"); + ActionManage.GetInstance.Register(new Action(() => { control?.ConnectOk(); }), $"{GeneralConfig.DeviceType.ToString()}/ConnectOk"); + ActionManage.GetInstance.Register(new Action((o) => { control?.SimOrder(o); }), "SimOrder"); + ActionManage.GetInstance.Register(new Action((o) => { control?.IotBroadcast(o); }), "IotBroadcast"); ConnectHelper.GetInstance.Init(); } diff --git a/HBLConsole.MORKD/Control_MORKD.cs b/HBLConsole.MORKD/Control_MORKD.cs index ad6ab48..af9b9a9 100644 --- a/HBLConsole.MORKD/Control_MORKD.cs +++ b/HBLConsole.MORKD/Control_MORKD.cs @@ -55,7 +55,7 @@ namespace HBLConsole.MORKD public void Init() { - ActionOperate.GetInstance.Register(new Action(() => { mORKD.InitControl(); }), "InitCommand"); + ActionManage.GetInstance.Register(new Action(() => { mORKD.InitControl(); }), "InitCommand"); } bool Initing = false; @@ -65,17 +65,17 @@ namespace HBLConsole.MORKD /// private void ResetProgram() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { if (RTrig.GetInstance("ResetProgram").Start(Initing)) { - ThreadOperate.GetInstance.StopTask("MainTask", new Action(() => + ThreadManage.GetInstance.StopTask("MainTask", new Action(() => { - ThreadOperate.GetInstance.StopTask("ReadPLCData", new Action(() => + ThreadManage.GetInstance.StopTask("ReadPLCData", new Action(() => { mORKD = null; mORKD = new GVL_MORKD(); - ActionOperate.GetInstance.Send("ResetProgram"); + ActionManage.GetInstance.Send("ResetProgram"); ReadData(); Main(); })); @@ -88,7 +88,7 @@ namespace HBLConsole.MORKD public void Main() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { mORKD.AllowRun = mORKD.InitComplete && !mORKD.TemperatureReached; @@ -113,7 +113,7 @@ namespace HBLConsole.MORKD public void ReadData() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { ModbusTcpHelper.GetInstance.Readbool(1120, 30, new Action((bools) => { diff --git a/HBLConsole.MORKIC/Control_MORKIC.cs b/HBLConsole.MORKIC/Control_MORKIC.cs index 6fde82b..8e58c41 100644 --- a/HBLConsole.MORKIC/Control_MORKIC.cs +++ b/HBLConsole.MORKIC/Control_MORKIC.cs @@ -90,7 +90,7 @@ namespace HBLConsole.MORKIC Main(); ReadData(); - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { while (morkOrderPushes.Count > 0) { @@ -177,7 +177,7 @@ namespace HBLConsole.MORKIC //todo:先调用机器人 - ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(10002); }), "调用乐百机器人做咖啡场景"); + ThreadManage.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(10002); }), "调用乐百机器人做咖啡场景"); while (!(lebai.Ok && lebai.Value == 1)) { Thread.Sleep(5); @@ -219,7 +219,7 @@ namespace HBLConsole.MORKIC //订单状态改变:开始制作 SimpleFactory.GetInstance.OrderChanged(subOrderId, BPA.Message.Enum.ORDER_STATUS.COOKING); //todo:先调用机器人 - ThreadOperate.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(scene); }), "调用乐百机器人做冰淇淋场景"); + ThreadManage.GetInstance.Start(new Action(() => { LebaiHelper.GetInstance.Scene(scene); }), "调用乐百机器人做冰淇淋场景"); while (!(lebai.Ok && lebai.Value == 1)) { @@ -259,7 +259,7 @@ namespace HBLConsole.MORKIC new ModeSetEvent() { Mode = MORKI_MODE.制冷模式 }.Publish(); //开始心跳刷新,根据咖啡机及冰淇淋机来判断 - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { //GeneralConfig.Healthy = true; @@ -279,7 +279,7 @@ namespace HBLConsole.MORKIC public void ReadData() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { lebai = LebaiHelper.GetInstance.GetValueAsync(); LebaiHelper.GetInstance.GetRobotModeStatus(); @@ -289,7 +289,7 @@ namespace HBLConsole.MORKIC public void SimOrder(T simOrder) { - //ThreadOperate.GetInstance.Start(new Action(() => + //ThreadManage.GetInstance.Start(new Action(() => //{ // DoIceCream(); // //DoCoffee(); diff --git a/HBLConsole.MORKS/Control_MORKS.cs b/HBLConsole.MORKS/Control_MORKS.cs index 60167ba..fb2e3a3 100644 --- a/HBLConsole.MORKS/Control_MORKS.cs +++ b/HBLConsole.MORKS/Control_MORKS.cs @@ -23,8 +23,8 @@ namespace HBLConsole.MORKS GVL_MORKS mORKS = new GVL_MORKS(); public void Init() { - ActionOperate.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); - ActionOperate.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); + ActionManage.GetInstance.Register(new Action(() => { WriteRecipeBoms(); }), "recipeBom"); + ActionManage.GetInstance.Register(new Action(() => { DeviceInit(); }), "InitCommand"); } public void ConnectOk() @@ -41,11 +41,11 @@ namespace HBLConsole.MORKS /// private void ResetProgram() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { if (RTrig.GetInstance("ResetProgram").Start(mORKS.DeviceIniting)) { - ThreadOperate.GetInstance.StopTask("MainTask", new Action(() => + ThreadManage.GetInstance.StopTask("MainTask", new Action(() => { mORKS.AllowRun = false; TakeBowlId = string.Empty; @@ -68,7 +68,7 @@ namespace HBLConsole.MORKS /// public void ReadData() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { ModbusTcpHelper.GetInstance.Readbool(323, 3, new Action((bools) => { @@ -261,7 +261,7 @@ namespace HBLConsole.MORKS public void Main() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { mORKS.AllowRun = mORKS.InitComplete && !mORKS.TemperatureReached; //mORKS.AllowRun = mORKS.InitComplete && mORKS.TemperatureReached; diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index acdfc89..baa1e14 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -29,7 +29,7 @@ namespace HBLConsole.MainConsole GeneralConfig.DeviceType = DeviceClientType.MORKS; if (Enum.TryParse(deviceType, out DeviceClientType dct)) GeneralConfig.DeviceType = dct; LocaPath.GetInstance.FilePath = $"AccessFile\\{GeneralConfig.DeviceType.ToString()}\\"; - ThreadOperate.GetInstance.Start(new Action(() => { Sqlite.GetInstance.GetData(); }), "GetAlarm"); + ThreadManage.GetInstance.Start(new Action(() => { Sqlite.GetInstance.GetData(); }), "GetAlarm"); Json.Read(); Json.Read(); Json.Read(); @@ -51,7 +51,7 @@ namespace HBLConsole.MainConsole public void BusinessInit() { - ThreadOperate.GetInstance.Start(new Action(() => + ThreadManage.GetInstance.Start(new Action(() => { InternetInfo.ConfigInit();//从 consul 获取配置数据 Topics.Clear(); diff --git a/HBLConsole.Model/HBLConsole.Model.csproj b/HBLConsole.Model/HBLConsole.Model.csproj index 4b493cd..00cd4ed 100644 --- a/HBLConsole.Model/HBLConsole.Model.csproj +++ b/HBLConsole.Model/HBLConsole.Model.csproj @@ -20,7 +20,7 @@ D:\BPACommon_output\net5.0\BPA.Message.dll - ..\..\..\..\BPACommon_output\net5.0\BPA.Models.dll + D:\BPACommon_output\net5.0\BPA.Models.dll diff --git a/HBLConsole.Model/SQL/VariableInfo.cs b/HBLConsole.Model/SQL/VariableInfo.cs index b248973..bd15c4c 100644 --- a/HBLConsole.Model/SQL/VariableInfo.cs +++ b/HBLConsole.Model/SQL/VariableInfo.cs @@ -32,7 +32,7 @@ namespace HBLConsole.Model { _mVarName = value; OnPropertyChanged(); - ActionOperate.GetInstance.Send("VarNameChanged", _mID); + ActionManage.GetInstance.Send("VarNameChanged", _mID); } } private string _mVarName; diff --git a/HBLConsole.Service/ActionManage.cs b/HBLConsole.Service/ActionManage.cs new file mode 100644 index 0000000..a4ced7f --- /dev/null +++ b/HBLConsole.Service/ActionManage.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.Concurrent; + +namespace HBLConsole.Service +{ + public class ActionManage + { + + private volatile static ActionManage _Instance; + public static ActionManage GetInstance => _Instance ?? (_Instance = new ActionManage()); + private ActionManage() { } + + private static ConcurrentDictionary actions = new ConcurrentDictionary(); + + static readonly object SendLock = new object(); + static readonly object SendParLock = new object(); + static readonly object RegisterLock = new object(); + + /// + /// 注销委托 + /// + /// + public void CancelRegister(string key) + { + if (actions.ContainsKey(key)) + actions.TryRemove(key, out Delegation t); + } + + /// + /// 执行注册过的委托 + /// + /// 注册委托的key + /// 委托参数 + /// 委托回调 + public void Send(string key, object par, Action Callback = null) + { + lock (SendLock) + if (actions.ContainsKey(key)) actions[key].ActionPar.Invoke(par, Callback); + //if (actions[key].ActionPar != null) + //{ + // actions[key].ActionPar(par); + // if (Callback != null) Callback(); + //} + } + + /// + /// 执行注册过的委托 + /// + /// 注册委托的key + /// 委托回调 + public void Send(string key, Action Callback = null) + { + lock (SendLock) + if (actions.ContainsKey(key)) actions[key].ActionBus?.Invoke(Callback); + } + + public object SendResult(string key, object par = null) + { + lock (SendLock) + if (actions.ContainsKey(key)) + if (par == null) + { + if (actions[key].FuncObj != null) + return actions[key].FuncObj; + } + else + { + if (actions[key].FuncPar != null) + return actions[key].FuncPar(par); + } + return default; + } + + public void Register(T action, string key) + { + lock (RegisterLock) + { + if (action != null) + { + if (!actions.ContainsKey(key)) + { + MessageLog.GetInstance.Show($"注册委托:【{key}】"); + if (action is Action actionBus) + actions.TryAdd(key, new Delegation() { ActionBus = actionBus }); + + if (action is Action actionObj) + actions.TryAdd(key, new Delegation() { ActionPar = actionObj }); + + if (action is Func funcObj) + actions.TryAdd(key, new Delegation() { FuncObj = funcObj }); + + if (action is Func puncPar) + actions.TryAdd(key, new Delegation() { FuncPar = puncPar }); + } + } + } + + } + + } + + + internal class Delegation + { + /// + /// 带参数的委托 + /// + public Action ActionPar { get; set; } + /// + /// 无参数的委托 + /// + public Action ActionBus { get; set; } + public Action CallBack { get; set; } + /// + /// 有返回值的委托 + /// + public Func FuncObj { get; set; } + /// + /// 有返回值,有参数的委托 + /// + public Func FuncPar { get; set; } + } + + +} diff --git a/HBLConsole.Service/ActionOperate.cs b/HBLConsole.Service/ActionOperate.cs deleted file mode 100644 index 23bb12d..0000000 --- a/HBLConsole.Service/ActionOperate.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Collections.Concurrent; - -namespace HBLConsole.Service -{ - public class ActionOperate - { - - private volatile static ActionOperate _Instance; - public static ActionOperate GetInstance => _Instance ?? (_Instance = new ActionOperate()); - private ActionOperate() { } - - private static ConcurrentDictionary actions = new ConcurrentDictionary(); - - //private static ConcurrentDictionary actionManagers = new ConcurrentDictionary(); - - static readonly object SendLock = new object(); - static readonly object SendParLock = new object(); - static readonly object RegisterLock = new object(); - - /// - /// 注销委托 - /// - /// - public void CancelRegister(string name) - { - if (actions.ContainsKey(name)) - { - actions.TryRemove(name, out Delegation t); - } - } - - public void Send(string name, object token, Action action = null) - { - lock (SendLock) - if (actions.ContainsKey(name)) - if (actions[name].ActionObj != null) - { - actions[name].ActionObj(token); - if (action != null) action(); - } - } - - public void Send(string name, AsyncCallback action = null) - { - lock (SendLock) - if (actions.ContainsKey(name)) - if (actions[name].ActionBus != null) - { - if (action != null) - actions[name].ActionBus.BeginInvoke(action, null); - else - actions[name].ActionBus(); - } - - } - - public object SendResult(string name, object token = null) - { - object result = new object(); - lock (SendLock) - if (actions.ContainsKey(name)) - if (token == null) - { - if (actions[name].FuncObj != null) - result = actions[name].FuncObj; - } - else - { - if (actions[name].FuncPar != null) - result = actions[name].FuncPar(token); - } - return result; - } - - public void Register(T action, string name) - { - lock (RegisterLock) - { - if (action != null) - { - if (!actions.ContainsKey(name)) - { - if (action is Action actionBus) - actions.TryAdd(name, new Delegation() { ActionBus = actionBus }); - - if (action is Action actionObj) - actions.TryAdd(name, new Delegation() { ActionObj = actionObj }); - - if (action is Func funcObj) - actions.TryAdd(name, new Delegation() { FuncObj = funcObj }); - - if (action is Func puncPar) - actions.TryAdd(name, new Delegation() { FuncPar = puncPar }); - } - } - } - - } - - } - - - internal class Delegation - { - public Action ActionObj { get; set; } - - public Action ActionBus { get; set; } - public Action CallBack { get; set; } - public Func FuncObj { get; set; } - public Func FuncPar { get; set; } - } - - -} diff --git a/HBLConsole.Service/ExpandMethod.cs b/HBLConsole.Service/ExpandMethod.cs index 0dbc4fb..7c8ba4f 100644 --- a/HBLConsole.Service/ExpandMethod.cs +++ b/HBLConsole.Service/ExpandMethod.cs @@ -10,12 +10,24 @@ namespace HBLConsole.Service { public static class ExpandMethod { + /// + /// 获取布尔数组指定值得索引 + /// + /// 要获取索引的数组 + /// 要获取索引的值 + /// public static int GetIndex(this bool[] obj, bool value) { if (obj == null) return -1; return Array.FindIndex(obj, p => p == value); } + /// + /// 获取字符串数组指定值得索引 + /// + /// 要获取索引的数组 + /// 要获取索引的值 + /// public static int GetIndex(this string[] obj, string value) { if (obj == null || value == null) return -1; @@ -23,35 +35,66 @@ namespace HBLConsole.Service } /// - /// 保存数据 + /// 委托回调 /// - public static void Save(this T ot) + /// 要执行的委托 + /// 委托回调 + public static void Invoke(this Action action, Action callback) { - string outjson = JsonConvert.SerializeObject(ot); - var str = ot.GetType().GenericTypeArguments; - if (str != null && str.Length > 0) + if (action != null) { - File.WriteAllText(LocaPath.GetInstance.Getpath(str[0].Name), outjson); + action(); + if (callback != null) callback(); } - } /// - /// 获取保存的数据 + /// 委托回调 /// - public static void Read(this object ot) + /// 要执行的委托 + /// 要执行的委托的参数 + /// 委托回调 + public static void Invoke(this Action action, object par, Action callback) { - var str = ot.GetType().GenericTypeArguments; - if (str != null && str.Length > 0) + if (action != null) { - string pa = LocaPath.GetInstance.Getpath(str[0].Name); - if (File.Exists(pa)) - { - string JsonString = File.ReadAllText(pa); - var result = JsonConvert.DeserializeObject(JsonString); - if (result != null) { Json.Data = result; } - } + action(par); + if (callback != null) callback(); } } + + + + ///// + ///// 保存数据 + ///// + //public static void Save(this T ot) + //{ + // string outjson = JsonConvert.SerializeObject(ot); + // var str = ot.GetType().GenericTypeArguments; + // if (str != null && str.Length > 0) + // { + // File.WriteAllText(LocaPath.GetInstance.Getpath(str[0].Name), outjson); + // } + + //} + + ///// + ///// 获取保存的数据 + ///// + //public static void Read(this object ot) + //{ + // var str = ot.GetType().GenericTypeArguments; + // if (str != null && str.Length > 0) + // { + // string pa = LocaPath.GetInstance.Getpath(str[0].Name); + // if (File.Exists(pa)) + // { + // string JsonString = File.ReadAllText(pa); + // var result = JsonConvert.DeserializeObject(JsonString); + // if (result != null) { Json.Data = result; } + // } + // } + //} } } diff --git a/HBLConsole.Service/HBLConsole.Service.csproj b/HBLConsole.Service/HBLConsole.Service.csproj index 25f57f2..171825e 100644 --- a/HBLConsole.Service/HBLConsole.Service.csproj +++ b/HBLConsole.Service/HBLConsole.Service.csproj @@ -1,7 +1,7 @@ - net5.0 + netstandard2.1 diff --git a/HBLConsole.Service/Json.cs b/HBLConsole.Service/Json.cs index ddf8794..c6a3759 100644 --- a/HBLConsole.Service/Json.cs +++ b/HBLConsole.Service/Json.cs @@ -12,7 +12,7 @@ namespace HBLConsole.Service public class Json where T : class, new() { - //private static string DeviceType = ActionOperate.GetInstance.SendResult("GetDeviceType").ToString(); + //private static string DeviceType = ActionManage.GetInstance.SendResult("GetDeviceType").ToString(); //static string path //{ diff --git a/HBLConsole.Service/SystemHelper.cs b/HBLConsole.Service/SystemHelper.cs index 8d4a64e..bb79c99 100644 --- a/HBLConsole.Service/SystemHelper.cs +++ b/HBLConsole.Service/SystemHelper.cs @@ -46,9 +46,8 @@ namespace HBLConsole.Service //System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式 } WshShell shell = new WshShell(); - //快捷键方式创建的位置、名称 - IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTop + GetApplicationName + ".lnk"); + IWshShortcut shortcut = shell.CreateShortcut(deskTop + GetApplicationName + ".lnk") as IWshShortcut; shortcut.TargetPath = GetApplicationPath; //目标文件 //该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。 shortcut.WorkingDirectory = System.Environment.CurrentDirectory; diff --git a/HBLConsole.Service/ThreadManage.cs b/HBLConsole.Service/ThreadManage.cs new file mode 100644 index 0000000..2452ef0 --- /dev/null +++ b/HBLConsole.Service/ThreadManage.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.Threading; + +namespace HBLConsole.Service +{ + /// + /// 线程管理 + /// + public class ThreadManage + { + private volatile static ThreadManage _Instance; + public static ThreadManage GetInstance => _Instance ?? (_Instance = new ThreadManage()); + private ThreadManage() { } + string guid = "871d7e28-c413-4675-8d28-64e4dca4c2d3-"; + private static readonly object _lock = new object(); + StringBuilder callbackKey = new StringBuilder(); + List keys = new List(); + ConcurrentDictionary Threads = new ConcurrentDictionary(); + ConcurrentDictionary CancellationTokenSources = new ConcurrentDictionary(); + + /// + /// 停止指定任务 + /// + /// 任务名 + /// 任务结束的回调 + public void StopTask(string key, Action ExitCallback = null) + { + if (CancellationTokenSources.ContainsKey(guid + key)) + CancellationTokenSources[guid + key]?.Cancel(); + ActionManage.GetInstance.Register(ExitCallback, guid + key); + } + + //public void StopTask(string[] keys, Action ExitCallback = null) + //{ + // lock (_lock) + // if (keys != null) + // { + // for (int i = 0; i < keys.Length; i++) + // { + // this.keys.Add(keys[i]); + // callbackKey.Append(keys[i]); + // if (CancellationTokenSources.ContainsKey(guid + keys[i])) + // CancellationTokenSources[guid + keys[i]]?.Cancel(); + // } + // callbackKey.Append(guid); + // ActionManage.GetInstance.Register(ExitCallback, callbackKey.ToString()); + // } + + //} + + /// + /// 长任务,带 while true 的循环 + /// + /// + /// + public void StartLong(Action action, string key, Action RunComplete = null) + { + CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); + bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => + { + try + { + while (!CancellationTokenSources[guid + key].IsCancellationRequested) + { + if (action != null) action(); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.Show($"线程 【{key}】运行发生异常,已重启"); + CancellationTokenSources.TryRemove(guid + key, out CancellationTokenSource temp); + Threads.TryRemove(guid + key, out Task temp1); + + } + }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => + { + ThreadStatus(t, o.ToString()); + if (RunComplete != null) RunComplete(); + }), guid + key)); + MessageLog.GetInstance.Show($"启动线程 【{key}】"); + if (!result) MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName"); + + } + + + /// + /// 不带 while true 的循环任务 + /// + /// + /// + public void Start(Action action, string key) + { + CancellationTokenSources.TryAdd(guid + key, new CancellationTokenSource()); + bool result = Threads.TryAdd(guid + key, Task.Factory.StartNew(new Action(() => + { + if (action != null) action(); + }), CancellationTokenSources[guid + key].Token).ContinueWith(new Action((t, o) => + { + ThreadStatus(t, o.ToString()); + }), guid + key)); + if (!result) MessageLog.GetInstance.Show($"【{key}】任务已存在,请检查 TaskName"); + } + + private void ThreadStatus(Task task, string key) + { + bool IsRemove = false; + string name = key.Substring(key.LastIndexOf('-') + 1); + switch (task.Status) + { + case TaskStatus.RanToCompletion: + MessageLog.GetInstance.Show($"线程【{name}】执行完成"); + IsRemove = true; + break; + case TaskStatus.Faulted: + MessageLog.GetInstance.Show($"线程【{name}】执行异常,{task.Exception}"); + IsRemove = true; + break; + case TaskStatus.Canceled: + MessageLog.GetInstance.Show($"线程【{name}】已取消"); + IsRemove = true; + break; + default: + break; + } + + if (IsRemove) + { + if (Threads.ContainsKey(key)) + Threads.TryRemove(key, out Task t); + //Threads.TryRemove(Threads.FirstOrDefault(p => p.Key == TaskName)); + + + if (CancellationTokenSources.ContainsKey(key)) + CancellationTokenSources.TryRemove(key, out CancellationTokenSource cts); + //CancellationTokenSources.TryRemove(CancellationTokenSources.FirstOrDefault(p => p.Key == TaskName)); + //keys.Remove(key); + //if (keys != null && keys.Count == 0) ActionManage.GetInstance.Send(callbackKey.ToString()); + ActionManage.GetInstance.Send(key); + } + } + + /// + /// 释放所有线程资源 + /// + public void Dispose() + { + for (int i = 0; i < CancellationTokenSources.Count; i++) + { + CancellationTokenSources.ElementAt(i).Value.Cancel(); + } + } + + /// + /// 判断指定线程是否完成 + /// + /// + /// + public bool IsComplete(string key) + { + if (Threads.ContainsKey(guid + key)) return Threads[guid + key].IsCompleted; + return false; + } + + } + +} diff --git a/HBLConsole.Service/ThreadOperate.cs b/HBLConsole.Service/ThreadOperate.cs deleted file mode 100644 index cd8b0b6..0000000 --- a/HBLConsole.Service/ThreadOperate.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Collections.Concurrent; -using System.Diagnostics; -using System.Threading; - -namespace HBLConsole.Service -{ - /// - /// 线程管理 - /// - public class ThreadOperate - { - private volatile static ThreadOperate _Instance; - public static ThreadOperate GetInstance => _Instance ?? (_Instance = new ThreadOperate()); - private ThreadOperate() { } - string guid = "871d7e28-c413-4675-8d28-64e4dca4c2d3-"; - ConcurrentDictionary Threads = new ConcurrentDictionary(); - ConcurrentDictionary CancellationTokenSources = new ConcurrentDictionary(); - - /// - /// 停止指定任务 - /// - /// 任务名 - /// 任务结束的回调 - public void StopTask(string taskName, Action ExitCallback = null) - { - if (CancellationTokenSources.ContainsKey(guid + taskName)) - CancellationTokenSources[guid + taskName]?.Cancel(); - ActionOperate.GetInstance.Register(ExitCallback, guid + taskName); - } - - /// - /// 长任务,带 while true 的循环 - /// - /// - /// - public void StartLong(Action action, string TaskName, Action RunComplete = null) - { - CancellationTokenSources.TryAdd(guid + TaskName, new CancellationTokenSource()); - bool result = Threads.TryAdd(guid + TaskName, Task.Factory.StartNew(new Action(() => - { - try - { - while (!CancellationTokenSources[guid + TaskName].IsCancellationRequested) - { - if (action != null) action(); - } - } - catch (Exception ex) - { - MessageLog.GetInstance.Show($"线程 【{TaskName}】运行发生异常,已重启"); - CancellationTokenSources.TryRemove(guid + TaskName, out CancellationTokenSource temp); - Threads.TryRemove(guid + TaskName, out Task temp1); - - } - }), CancellationTokenSources[guid + TaskName].Token).ContinueWith(new Action((t, o) => - { - ThreadStatus(t, o.ToString()); - if (RunComplete != null) RunComplete(); - }), guid + TaskName)); - MessageLog.GetInstance.Show($"启动线程 【{TaskName}】"); - if (!result) MessageLog.GetInstance.Show($"【{TaskName}】任务已存在,请检查 TaskName"); - - } - - - /// - /// 不带 while true 的循环任务 - /// - /// - /// - public void Start(Action action, string TaskName) - { - CancellationTokenSources.TryAdd(guid + TaskName, new CancellationTokenSource()); - bool result = Threads.TryAdd(guid + TaskName, Task.Factory.StartNew(new Action(() => - { - action(); - }), CancellationTokenSources[guid + TaskName].Token).ContinueWith(new Action((t, o) => - { - ThreadStatus(t, o.ToString()); - }), guid + TaskName)); - if (!result) MessageLog.GetInstance.Show($"【{TaskName}】任务已存在,请检查 TaskName"); - } - - private void ThreadStatus(Task task, string TaskName) - { - bool IsRemove = false; - string name = TaskName.Substring(TaskName.LastIndexOf('-') + 1); - switch (task.Status) - { - case TaskStatus.RanToCompletion: - MessageLog.GetInstance.Show($"线程【{name}】执行完成"); - IsRemove = true; - break; - case TaskStatus.Faulted: - MessageLog.GetInstance.Show($"线程【{name}】执行异常,{task.Exception}"); - IsRemove = true; - break; - case TaskStatus.Canceled: - MessageLog.GetInstance.Show($"线程【{name}】已取消"); - IsRemove = true; - break; - default: - break; - } - - if (IsRemove) - { - if (Threads.ContainsKey(TaskName)) - Threads.TryRemove(Threads.FirstOrDefault(p => p.Key == TaskName)); - - if (CancellationTokenSources.ContainsKey(TaskName)) - CancellationTokenSources.TryRemove(CancellationTokenSources.FirstOrDefault(p => p.Key == TaskName)); - - ActionOperate.GetInstance.Send(TaskName); - } - } - - /// - /// 释放所有线程资源 - /// - public void Dispose() - { - for (int i = 0; i < CancellationTokenSources.Count; i++) - { - CancellationTokenSources.ElementAt(i).Value.Cancel(); - } - } - - /// - /// 判断指定线程是否完成 - /// - /// - /// - public bool IsComplete(string TaskName) - { - if (Threads.ContainsKey(guid + TaskName)) - { - return Threads[guid + TaskName].IsCompleted; - } - else - { - return false; - } - } - - } - -} diff --git a/HBLConsole/App.xaml.cs b/HBLConsole/App.xaml.cs index 22128f8..b2810da 100644 --- a/HBLConsole/App.xaml.cs +++ b/HBLConsole/App.xaml.cs @@ -39,7 +39,7 @@ namespace HBLConsole SystemHelper.GetInstance.CreateDesktopShortcut(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; MainConsole.Main.GetInstance.DataInit(); - ThreadOperate.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData"); + ThreadManage.GetInstance.Start(new Action(() => { SqlHelper.GetInstance.GetData(); }), "GetSqliteData"); mainView = new MainView(); mainView.Show(); SplitScreenDisplay(); @@ -104,7 +104,7 @@ namespace HBLConsole IotReport.Close(); SqlHelper.GetInstance.Save(); MainConsole.Main.GetInstance.DataSave(); - ThreadOperate.GetInstance.Dispose(); + ThreadManage.GetInstance.Dispose(); System.Environment.Exit(0); } diff --git a/HBLConsole/DialogWindow/View/DeviceManagermentSetView.xaml.cs b/HBLConsole/DialogWindow/View/DeviceManagermentSetView.xaml.cs index c738dbe..4b9ce66 100644 --- a/HBLConsole/DialogWindow/View/DeviceManagermentSetView.xaml.cs +++ b/HBLConsole/DialogWindow/View/DeviceManagermentSetView.xaml.cs @@ -34,20 +34,20 @@ namespace HBLConsole.DialogWindow.View this.MaxWidth = SystemParameters.WorkArea.Width; this.MaxHeight = SystemParameters.WorkArea.Height; - ActionOperate.GetInstance.Register(new Action((s) => + ActionManage.GetInstance.Register(new Action((s) => { //this.Tag = s; //this.DialogResult = false; - ActionOperate.GetInstance.CancelRegister("Cancel"); + ActionManage.GetInstance.CancelRegister("Cancel"); this.Close(); }), "Cancel"); - ActionOperate.GetInstance.Register(new Action((s) => + ActionManage.GetInstance.Register(new Action((s) => { //this.Tag = s; //this.DialogResult = true; - ActionOperate.GetInstance.CancelRegister("Confirm"); + ActionManage.GetInstance.CancelRegister("Confirm"); this.Close(); }), "Confirm"); diff --git a/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs b/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs index dc6a7fe..b0a3b69 100644 --- a/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs +++ b/HBLConsole/DialogWindow/View/SimOrderConfitView.xaml.cs @@ -28,15 +28,15 @@ namespace HBLConsole.DialogWindow.View this.MoveBorder.MouseLeftButtonDown += (o, e) => { this.DragMove(); }; this.ButMin.Click += (o, e) => { this.WindowState = WindowState.Minimized; }; this.ButMax.Click += (o, e) => { this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; }; - this.ButClose.Click += (o, e) => { this.Close(); ActionOperate.GetInstance.CancelRegister("SendSimData"); }; + this.ButClose.Click += (o, e) => { this.Close(); ActionManage.GetInstance.CancelRegister("SendSimData"); }; this.MaxWidth = SystemParameters.WorkArea.Width; this.MaxHeight = SystemParameters.WorkArea.Height; - ActionOperate.GetInstance.Register(new Action(() => + ActionManage.GetInstance.Register(new Action(() => { this.Close(); - ActionOperate.GetInstance.CancelRegister("SimOrderConfitViewModelExit"); - ActionOperate.GetInstance.CancelRegister("SendSimData"); + ActionManage.GetInstance.CancelRegister("SimOrderConfitViewModelExit"); + ActionManage.GetInstance.CancelRegister("SendSimData"); }), "SimOrderConfitViewModelExit"); } diff --git a/HBLConsole/DialogWindow/ViewModel/DeviceManagermentSetViewModel.cs b/HBLConsole/DialogWindow/ViewModel/DeviceManagermentSetViewModel.cs index b498835..2e9ec67 100644 --- a/HBLConsole/DialogWindow/ViewModel/DeviceManagermentSetViewModel.cs +++ b/HBLConsole/DialogWindow/ViewModel/DeviceManagermentSetViewModel.cs @@ -24,7 +24,7 @@ namespace HBLConsole.DialogWindow.ViewModel Init(); CancelCommand = new RelayCommand(() => { - ActionOperate.GetInstance.Send("Cancel", devcieManagerResult); + ActionManage.GetInstance.Send("Cancel", devcieManagerResult); }); ConfirmCommand = new RelayCommand(() => { @@ -68,7 +68,7 @@ namespace HBLConsole.DialogWindow.ViewModel { LogInfo = $"警告:设备【{devcieManagerResult.DeviceName}】已存在,请重试"; } - ActionOperate.GetInstance.Send("Confirm", devcieManagerResult); + ActionManage.GetInstance.Send("Confirm", devcieManagerResult); }); } diff --git a/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs b/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs index 0e33f4a..75b2c1f 100644 --- a/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs +++ b/HBLConsole/DialogWindow/ViewModel/ListDialogViewModel.cs @@ -58,7 +58,7 @@ namespace HBLConsole.DialogWindow.ViewModel //if (Json.Data.morkOrderPushes.Count > 0) //{ - // ThreadOperate.GetInstance.Start(new Action(() => + // ThreadManage.GetInstance.Start(new Action(() => // { // Thread.Sleep(10000); // if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close"); @@ -96,7 +96,7 @@ namespace HBLConsole.DialogWindow.ViewModel { item.OrderStatus = ORDER_STATUS.WAIT; Json.Data.orderLists.Add(item); - ActionOperate.GetInstance.Send("DataParse", item.OrderPush); + ActionManage.GetInstance.Send("DataParse", item.OrderPush); } } //} @@ -105,7 +105,7 @@ namespace HBLConsole.DialogWindow.ViewModel if (Json.Data.morkOrderPushes.Count > 0) { - ThreadOperate.GetInstance.Start(new Action(() => + ThreadManage.GetInstance.Start(new Action(() => { Thread.Sleep(10000); if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close"); diff --git a/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs b/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs index c00bf5e..f93acc0 100644 --- a/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs +++ b/HBLConsole/DialogWindow/ViewModel/SimOrderConfitViewModel.cs @@ -19,7 +19,7 @@ namespace HBLConsole.DialogWindow.ViewModel public SimOrderConfitViewModel() { DeviceType = GVL.GeneralConfig.DeviceType.ToString(); - ActionOperate.GetInstance.Register(new Action((o) => + ActionManage.GetInstance.Register(new Action((o) => { if (o != null) { @@ -65,9 +65,9 @@ namespace HBLConsole.DialogWindow.ViewModel Json.Data.simOrderConfig.ElementAt(index).IsSelected = simOrderVisibleData.IsSelected; } } - ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); + ActionManage.GetInstance.Send("SimOrderConfitViewModelExit"); }); - CancelCommand = new RelayCommand(() => { ActionOperate.GetInstance.Send("SimOrderConfitViewModelExit"); }); + CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("SimOrderConfitViewModelExit"); }); } diff --git a/HBLConsole/View/DeviceManageView.xaml.cs b/HBLConsole/View/DeviceManageView.xaml.cs index 168990f..91287bd 100644 --- a/HBLConsole/View/DeviceManageView.xaml.cs +++ b/HBLConsole/View/DeviceManageView.xaml.cs @@ -31,7 +31,7 @@ namespace HBLConsole.View { if (!obj.IsVisible) { - ActionOperate.GetInstance.Send("DataSave"); + ActionManage.GetInstance.Send("DataSave"); } } diff --git a/HBLConsole/View/VariableConfig.xaml.cs b/HBLConsole/View/VariableConfig.xaml.cs index 951ecc1..33c2f43 100644 --- a/HBLConsole/View/VariableConfig.xaml.cs +++ b/HBLConsole/View/VariableConfig.xaml.cs @@ -33,7 +33,7 @@ namespace HBLConsole.View var obj = (VariableConfig)sender; if (!obj.IsVisible) { - ActionOperate.GetInstance.Send("VariableSave"); + ActionManage.GetInstance.Send("VariableSave"); } } diff --git a/HBLConsole/ViewModel/DebugViewModel.cs b/HBLConsole/ViewModel/DebugViewModel.cs index 71062df..bf7fa60 100644 --- a/HBLConsole/ViewModel/DebugViewModel.cs +++ b/HBLConsole/ViewModel/DebugViewModel.cs @@ -48,12 +48,12 @@ namespace HBLConsole.ViewModel } - ActionOperate.GetInstance.Send("SimOrder", locs); + ActionManage.GetInstance.Send("SimOrder", locs); }); InitCommand = new RelayCommand(() => { - ActionOperate.GetInstance.Send("InitCommand"); + ActionManage.GetInstance.Send("InitCommand"); }); LoopSimOrderCommand = new RelayCommand(() => @@ -61,7 +61,7 @@ namespace HBLConsole.ViewModel LoopButton = LoopButton == "循环跑单" ? "停止跑单" : "循环跑单"; }); - //ThreadOperate.GetInstance.StartLong(new Action(() => + //ThreadManage.GetInstance.StartLong(new Action(() => //{ // //try // //{ @@ -73,7 +73,7 @@ namespace HBLConsole.ViewModel // // if (simOrderVisibleDatas.ElementAt(0).IsSelected) // // simOrderVisibleDatas.ElementAt(0).Loc = (ushort)(new Random().Next(1,6)); - // // ActionOperate.GetInstance.Send("SimOrder",new SimOrderData() + // // ActionManage.GetInstance.Send("SimOrder",new SimOrderData() // // { // // NoodleLoc = simOrderVisibleDatas.ElementAt(0).Loc, // // SoupLoc = simOrderVisibleDatas.ElementAt(1).Loc, @@ -103,7 +103,7 @@ namespace HBLConsole.ViewModel { SimOrderConfitView simOrderConfitView = new SimOrderConfitView(); simOrderConfitView.Show(); - ActionOperate.GetInstance.Send("SendSimData", res); + ActionManage.GetInstance.Send("SendSimData", res); } //} } diff --git a/HBLConsole/ViewModel/MainViewModel.cs b/HBLConsole/ViewModel/MainViewModel.cs index 8bfdbc3..8f38625 100644 --- a/HBLConsole/ViewModel/MainViewModel.cs +++ b/HBLConsole/ViewModel/MainViewModel.cs @@ -25,7 +25,7 @@ namespace HBLConsole.ViewModel MqttReceive(); DoNavChanged("MessageLogView"); NavChangedCommand = new RelayCommand(DoNavChanged); - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { InternetInfo.NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState(); NetworkConnectState = InternetInfo.NetworkConnectState; @@ -37,7 +37,7 @@ namespace HBLConsole.ViewModel private void AlarmMonitoring() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { if (SimpleFactory.GetInstance.Alarm != null) { diff --git a/HBLConsole/ViewModel/ProcessMonitoringViewModel.cs b/HBLConsole/ViewModel/ProcessMonitoringViewModel.cs index bce1023..797a49b 100644 --- a/HBLConsole/ViewModel/ProcessMonitoringViewModel.cs +++ b/HBLConsole/ViewModel/ProcessMonitoringViewModel.cs @@ -83,7 +83,7 @@ namespace HBLConsole.ViewModel private static void UpdateProcess() { if (SimpleFactory.GetInstance.GVL == null) return; - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) { diff --git a/HBLConsole/ViewModel/VariableConfig.cs b/HBLConsole/ViewModel/VariableConfig.cs index 9df6122..4383987 100644 --- a/HBLConsole/ViewModel/VariableConfig.cs +++ b/HBLConsole/ViewModel/VariableConfig.cs @@ -17,8 +17,8 @@ namespace HBLConsole.ViewModel { public VariableConfig() { - ActionOperate.GetInstance.Register(new Action(() => { SaveDataAsync(); }), "VariableSave"); - ActionOperate.GetInstance.Register(new Action((o) => + ActionManage.GetInstance.Register(new Action(() => { SaveDataAsync(); }), "VariableSave"); + ActionManage.GetInstance.Register(new Action((o) => { if (o is int p) { diff --git a/HBLConsole/ViewModel/VariableMonitorViewModel.cs b/HBLConsole/ViewModel/VariableMonitorViewModel.cs index 03bc02e..63e25e8 100644 --- a/HBLConsole/ViewModel/VariableMonitorViewModel.cs +++ b/HBLConsole/ViewModel/VariableMonitorViewModel.cs @@ -128,7 +128,7 @@ namespace HBLConsole.ViewModel private static void UpdateValue() { if (SimpleFactory.GetInstance.GVL == null) return; - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { foreach (var item in SimpleFactory.GetInstance.GVL.GetType().GetProperties()) { diff --git a/HBLConsole/ViewModel/ViewModelBase.cs b/HBLConsole/ViewModel/ViewModelBase.cs index d2b9eb7..9587783 100644 --- a/HBLConsole/ViewModel/ViewModelBase.cs +++ b/HBLConsole/ViewModel/ViewModelBase.cs @@ -138,7 +138,7 @@ namespace HBLConsole.ViewModel public void MqttReceive() { Test(); - ActionOperate.GetInstance.Register(new Action((o) => + ActionManage.GetInstance.Register(new Action((o) => { if (o is MorkOrderPush morkOrderpush) { @@ -161,7 +161,7 @@ namespace HBLConsole.ViewModel } }), "AddOrder"); - ActionOperate.GetInstance.Register(new Action((o) => + ActionManage.GetInstance.Register(new Action((o) => { if (o is OrderStatusChange orderStatusChange) { diff --git a/HBLDevice.Coffee/CoffeeMachine.cs b/HBLDevice.Coffee/CoffeeMachine.cs index bfabd42..d7f7de5 100644 --- a/HBLDevice.Coffee/CoffeeMachine.cs +++ b/HBLDevice.Coffee/CoffeeMachine.cs @@ -14,7 +14,7 @@ namespace HBLDevice.Coffee /// /// 咖啡机 /// - public class CoffeeMachine + public class CoffeeMachine { //通讯代理 SerialPortClient commProxy = null; @@ -123,7 +123,7 @@ namespace HBLDevice.Coffee /// private void MainLoop() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { if (free) { @@ -146,7 +146,7 @@ namespace HBLDevice.Coffee //}, "咖啡机询问线程"); - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { List temp = new List(); //一系列解包 @@ -224,6 +224,6 @@ namespace HBLDevice.Coffee //}, "咖啡机解析线程"); } - + } } diff --git a/HBLDevice.ICChip/HBLDevice.ICChip.csproj b/HBLDevice.ICChip/HBLDevice.ICChip.csproj index aff9e11..ad510d8 100644 --- a/HBLDevice.ICChip/HBLDevice.ICChip.csproj +++ b/HBLDevice.ICChip/HBLDevice.ICChip.csproj @@ -10,7 +10,7 @@ - ..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll + D:\BPACommon_output\net5.0\BPA.Utility.dll diff --git a/HBLDevice.ICChip/ICChipMachine.cs b/HBLDevice.ICChip/ICChipMachine.cs index 26cc527..a31250d 100644 --- a/HBLDevice.ICChip/ICChipMachine.cs +++ b/HBLDevice.ICChip/ICChipMachine.cs @@ -44,7 +44,7 @@ namespace HBLDevice.ICChip private void MainLoop() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { ResolveMsg(); //Thread.Sleep(2000); diff --git a/HBLDevice.IceCream/IceCreamMachine.cs b/HBLDevice.IceCream/IceCreamMachine.cs index 169163b..9e5c7bf 100644 --- a/HBLDevice.IceCream/IceCreamMachine.cs +++ b/HBLDevice.IceCream/IceCreamMachine.cs @@ -51,7 +51,7 @@ namespace HBLDevice.IceCream private MSG_RESOLVE_STEP currentStep; private void MainLoop() { - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { if (free) { @@ -61,7 +61,7 @@ namespace HBLDevice.IceCream Thread.Sleep(500); }), "冰淇淋询问线程"); - ThreadOperate.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance.StartLong(new Action(() => { ResolveMsg(); //Thread.Sleep(2000);