@@ -16,10 +16,10 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
<Reference Include="BPA.Utility"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -18,7 +18,12 @@ namespace HBLConsole.Business | |||
if (orderInfo == null) return; | |||
if (orderInfo is MorkOrderPush morkOrderpush) | |||
{ | |||
ActionManagerment.GetInstance.Send("orderSend", morkOrderpush); | |||
Json<MorkOrderPushPar>.GetInstance.Base.morkOrderPushes.Add(new OrderData() | |||
{ | |||
OrderStatus = ORDER_STATUS.WAIT, | |||
IsSelected = true, | |||
OrderPush = morkOrderpush | |||
}); | |||
} | |||
} | |||
@@ -37,33 +37,19 @@ namespace HBLConsole.Communication | |||
/// </summary> | |||
public Action Reconnection { get; set; } | |||
Action UseDisconnectedAction; | |||
public async void MqttInitAsync(string UserName, string pass, string IP, int port, string clientID) | |||
{ | |||
p1: | |||
options = new MqttClientOptionsBuilder().WithTcpServer(IP, port).WithClientId(clientID).WithCredentials(UserName, pass).Build(); | |||
client = new MqttFactory().CreateMqttClient(); | |||
client.UseDisconnectedHandler(async c => | |||
client.UseDisconnectedHandler(c => | |||
{ | |||
Thread.Sleep(2000); | |||
while (!InternetInfo.GetInstance.NetworkConnectState) | |||
{ | |||
Thread.Sleep(2000); | |||
} | |||
MessageLog.GetInstance.Show($"断开连接"); | |||
try | |||
{ | |||
MessageLog.GetInstance.Show($"重连中"); | |||
await client.ConnectAsync(options); | |||
} | |||
catch (Exception ex) | |||
{ | |||
MessageLog.GetInstance.Show(ex.ToString()); | |||
} | |||
if (client.IsConnected) | |||
if (UseDisconnectedAction == null) | |||
{ | |||
MessageLog.GetInstance.Show("MQTT重连成功!"); | |||
if (Reconnection != null) Reconnection(); | |||
Reconnect(); | |||
UseDisconnectedAction(); | |||
} | |||
}).UseApplicationMessageReceivedHandler(c => | |||
@@ -74,20 +60,55 @@ namespace HBLConsole.Communication | |||
MessageLog.GetInstance.Show($"连接成功"); | |||
}); | |||
try | |||
{ | |||
await client.ConnectAsync(options); | |||
} | |||
catch (Exception ex) { MessageLog.GetInstance.Show(ex.Message); } | |||
if (!client.IsConnected) | |||
catch (Exception ex) | |||
{ | |||
Thread.Sleep(2000); | |||
MessageLog.GetInstance.Show(ex.Message); | |||
MessageLog.GetInstance.Show("mqtt连接失败!重连执行中"); | |||
goto p1; | |||
} | |||
MessageLog.GetInstance.Show("MQTT连接成功!"); | |||
if (ConnectOk != null) ConnectOk(); | |||
if (client.IsConnected) | |||
{ | |||
MessageLog.GetInstance.Show("MQTT连接成功!"); | |||
if (ConnectOk != null) ConnectOk(); | |||
} | |||
} | |||
private void Reconnect() | |||
{ | |||
UseDisconnectedAction = new Action(() => | |||
{ | |||
Thread.Sleep(2000); | |||
while (!InternetInfo.GetInstance.NetworkConnectState) | |||
{ | |||
Thread.Sleep(2000); | |||
} | |||
MessageLog.GetInstance.Show($"断开连接"); | |||
while (!client.IsConnected) | |||
{ | |||
try | |||
{ | |||
MessageLog.GetInstance.Show($"重连中"); | |||
client.ConnectAsync(options).Wait(); | |||
} | |||
catch (Exception ex) | |||
{ | |||
MessageLog.GetInstance.Show(ex.ToString()); | |||
} | |||
Thread.Sleep(30000); | |||
} | |||
if (client.IsConnected) | |||
{ | |||
MessageLog.GetInstance.Show("MQTT重连成功!"); | |||
if (Reconnection != null) Reconnection(); | |||
} | |||
UseDisconnectedAction = null; | |||
}); | |||
} | |||
/// <summary> | |||
@@ -12,7 +12,7 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -18,10 +18,10 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
<Reference Include="BPA.Utility"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Utility.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -33,14 +33,22 @@ namespace HBLConsole.GVL | |||
ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"]; | |||
ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]); | |||
try | |||
{ | |||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000); | |||
IConfiguration config = configurationBuilder.Build(); | |||
MqttUserName = config["MQTT:TcpAccount"]; | |||
MqttPassword = config["MQTT:TcpPwd"]; | |||
MqttAddress = config["MQTT:MqttAddress"]; | |||
MqttPort = int.Parse(config["MQTT:MqttPort"]); | |||
OrderStatusChange = config["API:robotstatuschange"]; | |||
} | |||
catch (Exception ex) | |||
{ | |||
MessageLog.GetInstance.Show(ex.ToString()); | |||
} | |||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000); | |||
IConfiguration config = configurationBuilder.Build(); | |||
MqttUserName = config["MQTT:TcpAccount"]; | |||
MqttPassword = config["MQTT:TcpPwd"]; | |||
MqttAddress = config["MQTT:MqttAddress"]; | |||
MqttPort = int.Parse(config["MQTT:MqttPort"]); | |||
OrderStatusChange = config["API:robotstatuschange"]; | |||
} | |||
/// <summary> | |||
@@ -10,7 +10,7 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -14,7 +14,10 @@ | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
<Reference Include="BPA.Models"> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Models.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -14,6 +14,7 @@ using HBLConsole.GVL; | |||
using BPA.Message; | |||
using HBLConsole.Communication; | |||
using BPA.Message.Enum; | |||
using BPA.Models.Robot; | |||
//using Communication.MQTT; | |||
//using BPA.Message.Kafka; | |||
//using Model.Enums; | |||
@@ -21,6 +21,16 @@ namespace HBLConsole.MainConsole | |||
List<string> Topics = new List<string>(); | |||
public void DataInit() | |||
{ | |||
Json<MorkOrderPushPar>.GetInstance.Read(); | |||
} | |||
public void DataSave() | |||
{ | |||
Json<MorkOrderPushPar>.GetInstance.Save(); | |||
} | |||
public void BusinessInit() | |||
{ | |||
Topics.Clear(); | |||
@@ -4,9 +4,13 @@ | |||
<TargetFramework>net5.0</TargetFramework> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Reference Include="BPA.Message"> | |||
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
<HintPath>D:\BPACommon_output\net5.0\BPA.Message.dll</HintPath> | |||
</Reference> | |||
</ItemGroup> | |||
@@ -5,7 +5,7 @@ using System.Text; | |||
using System.Threading.Tasks; | |||
using BPA.Message; | |||
namespace HBLConsole | |||
namespace HBLConsole.Model | |||
{ | |||
public class MorkOrderPushPar | |||
{ |
@@ -8,7 +8,7 @@ using BPA.Message.Enum; | |||
using Microsoft.Toolkit.Mvvm.ComponentModel; | |||
using Microsoft.Toolkit.Mvvm.Input; | |||
namespace HBLConsole | |||
namespace HBLConsole.Model | |||
{ | |||
public class OrderData : ObservableObject | |||
{ | |||
@@ -21,5 +21,16 @@ namespace HBLConsole | |||
public ORDER_STATUS OrderStatus { get { return _mOrderStatus; } set { _mOrderStatus = value; OnPropertyChanged(); } } | |||
private ORDER_STATUS _mOrderStatus; | |||
public string StartDate { get { return _mStartDate; } set { _mStartDate = value; OnPropertyChanged(); } } | |||
private string _mStartDate; | |||
public string EndDate { get { return _mEndDate; } set { _mEndDate = value; OnPropertyChanged(); } } | |||
private string _mEndDate; | |||
public string CompleteDate { get { return _mCompleteDate; } set { _mCompleteDate = value; OnPropertyChanged(); } } | |||
private string _mCompleteDate; | |||
} | |||
} |
@@ -25,10 +25,12 @@ namespace HBLConsole | |||
protected override void OnStartup(StartupEventArgs e) | |||
{ | |||
base.OnStartup(e); | |||
//listDialogView = new ListDialogView(); | |||
//listDialogView.ShowDialog(); | |||
SystemHelper.GetInstance.AutoStart(false); | |||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | |||
InitService.GetInstance.Register(); | |||
InitService.GetInstance.DataInit(); | |||
//InitService.GetInstance.Register(); | |||
MainConsole.Main.GetInstance.DataInit(); | |||
mainView.Show(); | |||
if (Json<MorkOrderPushPar>.GetInstance.Base.morkOrderPushes.Count > 0) | |||
{ | |||
@@ -40,14 +42,14 @@ namespace HBLConsole | |||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) | |||
{ | |||
InitService.GetInstance.DataSave(); | |||
MainConsole.Main.GetInstance.DataSave(); | |||
Process.Start($"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName}.exe"); | |||
} | |||
protected override void OnExit(ExitEventArgs e) | |||
{ | |||
base.OnExit(e); | |||
InitService.GetInstance.DataSave(); | |||
MainConsole.Main.GetInstance.DataSave(); | |||
} | |||
} | |||
} |
@@ -23,6 +23,27 @@ namespace HBLConsole.DialogWindow.ViewModel | |||
public ListDialogViewModel() | |||
{ | |||
//for (int i = 0; i < 10; i++) | |||
//{ | |||
// Json<MorkOrderPushPar>.GetInstance.Base.morkOrderPushes.Add(new OrderData() | |||
// { | |||
// IsSelected = true, | |||
// OrderStatus = BPA.Message.Enum.ORDER_STATUS.WAIT, | |||
// OrderPush = new BPA.Message.MorkOrderPush() | |||
// { | |||
// GoodsName = i.ToString(), | |||
// RecipeId = i, | |||
// SortNum = i, | |||
// SuborderId = i.ToString(), | |||
// GoodBatchings = new List<BPA.Message.GoodBatchings>() | |||
// } | |||
// }); | |||
//} | |||
//Json<MorkOrderPushPar>.GetInstance.Save(); | |||
CloseCommand = new RelayCommand(() => | |||
{ | |||
Json<MorkOrderPushPar>.GetInstance.Base.morkOrderPushes.Clear(); | |||
@@ -1,46 +0,0 @@ | |||
using BPA.Message; | |||
using BPA.Message.Enum; | |||
using HBLConsole.Service; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace HBLConsole | |||
{ | |||
public class InitService | |||
{ | |||
private volatile static InitService _Instance; | |||
public static InitService GetInstance => _Instance ?? (_Instance = new InitService()); | |||
private InitService() { } | |||
public void DataInit() | |||
{ | |||
Json<MorkOrderPushPar>.GetInstance.Read(); | |||
} | |||
public void DataSave() | |||
{ | |||
Json<MorkOrderPushPar>.GetInstance.Save(); | |||
} | |||
public void Register() | |||
{ | |||
ActionManagerment.GetInstance.Register(new Action<object>((o) => | |||
{ | |||
if (o is MorkOrderPush morkOrderPush) | |||
{ | |||
Json<MorkOrderPushPar>.GetInstance.Base.morkOrderPushes.Add(new OrderData() | |||
{ | |||
OrderStatus = ORDER_STATUS.WAIT, | |||
IsSelected = true, | |||
OrderPush = morkOrderPush | |||
}); | |||
} | |||
}), "orderSend"); | |||
} | |||
} | |||
} |