Browse Source

上位机控制框架搭建

master
pry 2 years ago
parent
commit
c224a1ea81
41 changed files with 1404 additions and 83 deletions
  1. +12
    -0
      Factory/Factory.csproj
  2. +29
    -0
      Factory/SimpleFactory.cs
  3. +15
    -0
      HBLConsole.Abstract/AbstractMessageServer.cs
  4. +7
    -0
      HBLConsole.Abstract/HBLConsole.Abstract.csproj
  5. +98
    -0
      HBLConsole.Business/AlarmHelper.cs
  6. +21
    -0
      HBLConsole.Business/HBLConsole.Business.csproj
  7. +76
    -0
      HBLConsole.Business/M2MqttHelper.cs
  8. +32
    -0
      HBLConsole.Business/MessageServerBase.cs
  9. +22
    -0
      HBLConsole.Business/ServerMessage.cs
  10. +18
    -0
      HBLConsole.Communication/HBLConsole.Communication.csproj
  11. +147
    -0
      HBLConsole.Communication/M2MQTT/MqttM2.cs
  12. +55
    -0
      HBLConsole.Communication/M2MQTT/MqttSign.cs
  13. +161
    -0
      HBLConsole.Communication/MqttHelper.cs
  14. +18
    -0
      HBLConsole.GVL/HBLConsole.GVL.csproj
  15. +78
    -0
      HBLConsole.GVL/InternetInfo.cs
  16. +17
    -0
      HBLConsole.Interface/HBLConsole.Interface.csproj
  17. +16
    -0
      HBLConsole.Interface/IServerMessage.cs
  18. +7
    -0
      HBLConsole.MainConsole/HBLConsole.MainConsole.csproj
  19. +22
    -0
      HBLConsole.MainConsole/Main.cs
  20. +16
    -0
      HBLConsole.Model/Enums/AlarmLevel.cs
  21. +20
    -0
      HBLConsole.Model/Enums/AlarmTriggerType.cs
  22. +17
    -0
      HBLConsole.Model/Iot/AlarmHzObj.cs
  23. +26
    -0
      HBLConsole.Model/Iot/AlarmInfo.cs
  24. +19
    -0
      HBLConsole.Model/Iot/ColorSet.cs
  25. +21
    -0
      HBLConsole.Model/Iot/IotAlarmInfo.cs
  26. +19
    -0
      HBLConsole.Model/Iot/IotMessage.cs
  27. +16
    -0
      HBLConsole.Model/Iot/Iotparams.cs
  28. +20
    -0
      HBLConsole.Model/Iot/LowerComputerStateInfoClass.cs
  29. +14
    -0
      HBLConsole.Model/KeepParameter/AlarmHzParameter.cs
  30. +13
    -0
      HBLConsole.Service/HBLConsole.Service.csproj
  31. +109
    -0
      HBLConsole.Service/SystemHelper.cs
  32. +36
    -6
      HBLConsole.sln
  33. +18
    -0
      HBLConsole/App.config
  34. +1
    -2
      HBLConsole/App.xaml
  35. +23
    -0
      HBLConsole/App.xaml.cs
  36. +13
    -1
      HBLConsole/HBLConsole.csproj
  37. +1
    -1
      HBLConsole/Resources/ResourceDictionarys/BasicStyle.xaml
  38. +39
    -14
      HBLConsole/Resources/ResourceDictionarys/MyBorder.xaml
  39. +109
    -0
      HBLConsole/Server/SystemHelper.cs
  40. +1
    -54
      HBLConsole/ViewModel/MainViewModel.cs
  41. +2
    -5
      HBLConsole/ViewModel/ViewModelBase.cs

+ 12
- 0
Factory/Factory.csproj View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Abstract\HBLConsole.Abstract.csproj" />
<ProjectReference Include="..\HBLConsole.Interface\HBLConsole.Interface.csproj" />
</ItemGroup>

</Project>

+ 29
- 0
Factory/SimpleFactory.cs View File

@@ -0,0 +1,29 @@
using HBLConsole.Abstract;
using HBLConsole.Interface;
using System;
using System.Reflection;

namespace Factory
{
public class SimpleFactory
{

private volatile static SimpleFactory _Instance;
public static SimpleFactory GetInstance => _Instance ?? (_Instance = new SimpleFactory());
private SimpleFactory() { }

public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer());
private AbstractMessageServer _GetAbsMessageServer;

public IServerMessage GetIServerMessage => _GetIServerMessage ?? (_GetIServerMessage = new ServerMessage());
private IServerMessage _GetIServerMessage;

private AbstractMessageServer GetAbstractMessageServer()
{
Type type = Assembly.Load("MqttMessageServer").GetType($"MqttMessageServer.{GVL_VAR.GetInstance.StartDeviceType.ToString()}");
if (type == null)
type = Assembly.Load("MqttMessageServer").GetType($"MqttMessageServer.Base");
return (AbstractMessageServer)Activator.CreateInstance(type);
}
}
}

+ 15
- 0
HBLConsole.Abstract/AbstractMessageServer.cs View File

@@ -0,0 +1,15 @@
using System;

namespace HBLConsole.Abstract
{
public abstract class AbstractMessageServer
{
public abstract void GetBatchingInfo<T>(T batchingInfo);

public abstract void AddOrder<T>(T orderInfo);

public abstract void GetRecipeBom<T>(T recipeBomInfo);

public abstract void BatchingCountInfo();
}
}

+ 7
- 0
HBLConsole.Abstract/HBLConsole.Abstract.csproj View File

@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

</Project>

+ 98
- 0
HBLConsole.Business/AlarmHelper.cs View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using HBLConsole.Service;
using HBLConsole.Model;

namespace HBLConsole.Business
{
public class AlarmHelper
{
private volatile static AlarmHelper _Instance;
public static AlarmHelper GetInstance => _Instance ?? (_Instance = new AlarmHelper());
private AlarmHelper()
{
Json<AlarmHzParameter>.GetInstance.Read();
colorValue.TryAdd(AlarmLevel.一般报警.ToString(), Color.FromArgb(1, 255, 216, 0));
colorValue.TryAdd(AlarmLevel.严重报警.ToString(), Color.FromArgb(1, 255, 0, 0));
}
private List<AlarmInfo> Alarms { get; set; } = new List<AlarmInfo>();
ConcurrentDictionary<string, bool> flagbit = new ConcurrentDictionary<string, bool>();
public ConcurrentDictionary<string, Color> colorValue = new ConcurrentDictionary<string, Color>();
public Action<string> AddAction { get; set; }
public Action<string> RemoveAction { get; set; }
public Action ChangeAction { get; set; }

/// <summary>
/// 沿报警检测
/// </summary>
/// <param name="Trigger">触发变量</param>
/// <param name="text">报警信息</param>
/// <param name="edgeType">触发类型,上升沿 或 下降沿</param>
public void EdgeAlarm(bool Trigger, string text, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising)
{
if (!flagbit.ContainsKey(text)) flagbit.TryAdd(text, false);
if (edgeType == AlarmTriggerType.Rising ? Trigger : !Trigger)
{
if (edgeType == AlarmTriggerType.Rising ? !flagbit[text] : flagbit[text])
{
AddAlarm(text, alarmLevel);
flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false;
}
}
else
{
RemoveAlarm(text);
}
if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger;
}

/// <summary>
/// 获取当前报警信息集合
/// </summary>
public List<AlarmInfo> GetAlarmInfo => Alarms;

/// <summary>
/// 添加报警信息
/// </summary>
/// <param name="AlarmInfo">报警信息</param>
private void AddAlarm(string AlarmInfo, AlarmLevel alarmLevel)
{
if (Alarms.FirstOrDefault(p => p.AlarmInfomation == AlarmInfo) == null)
{
Alarms.Add(new AlarmInfo() { AlarmInfomation = AlarmInfo, date = DateTime.Now.ToString("HH:mm:ss"), AlarmLevel = alarmLevel.ToString() });

//报警频率计算
if (Json<AlarmHzParameter>.GetInstance.Base.AlarmHz.ContainsKey(AlarmInfo))
Json<AlarmHzParameter>.GetInstance.Base.AlarmHz[AlarmInfo]++;
else
Json<AlarmHzParameter>.GetInstance.Base.AlarmHz.TryAdd(AlarmInfo, 1);

if (AddAction != null) AddAction(AlarmInfo);//添加报警通知
if (ChangeAction != null) ChangeAction();//更改报警通知
}
}

/// <summary>
/// 移除报警信息
/// </summary>
/// <param name="AlarmInfo">报警信息</param>
private void RemoveAlarm(string AlarmInfo)
{
var result = Alarms.FirstOrDefault(p => p.AlarmInfomation == AlarmInfo);
if (result != null)
{
Alarms.Remove(result);
if (RemoveAction != null) RemoveAction(AlarmInfo);
if (ChangeAction != null) ChangeAction();
}
}



}
}

+ 21
- 0
HBLConsole.Business/HBLConsole.Business.csproj View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Abstract\HBLConsole.Abstract.csproj" />
<ProjectReference Include="..\HBLConsole.Communication\HBLConsole.Communication.csproj" />
<ProjectReference Include="..\HBLConsole.Interface\HBLConsole.Interface.csproj" />
<ProjectReference Include="..\HBLConsole.Model\HBLConsole.Model.csproj" />
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="BPA.Message">
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

+ 76
- 0
HBLConsole.Business/M2MqttHelper.cs View File

@@ -0,0 +1,76 @@
using HBLConsole.Model;
using HBLConsole.Service;
using Newtonsoft.Json;
using System;
using System.Text;
using HBLConsole.Communication;
using System.Threading;

namespace HBLConsole.Business
{
public class M2MqttHelper
{

private volatile static M2MqttHelper _Instance;
public static M2MqttHelper GetInstance => _Instance ?? (_Instance = new M2MqttHelper());
private M2MqttHelper() { }


IotMessage iotMessage = new IotMessage();
LowerComputerStateInfo lowerComputerStateInfoClass = new LowerComputerStateInfo();
string PublishContent;

public void Init()
{
ThreadManagerment.GetInstance.StartLong(new Action(() =>
{
//AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.MCUDisconnected, "单片机掉线", AlarmLevel.严重报警);
//AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.IceCreamAbnormal, "冰淇淋机异常");
//AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.TakeBowlAbnormal, "取碗异常");
//AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.RobotAbnormal, "机器人异常", AlarmLevel.严重报警);

#region 报警信息设置
lowerComputerStateInfoClass.AlarmInfo.Clear();
foreach (var item in AlarmHelper.GetInstance.GetAlarmInfo)
{
lowerComputerStateInfoClass.AlarmInfo.Add(new IotAlarmInfo()
{
time = item.date,
AlarmLevel = item.AlarmLevel,
info = item.AlarmInfomation,
color = new ColorSet()
{
a = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].A,
b = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].B,
g = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].G,
r = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].R,
},
infoSrc = ""
});
}
#endregion

#region 报警频率显示
lowerComputerStateInfoClass.AlarmHzObj.Clear();
foreach (var item in Json<AlarmHzParameter>.GetInstance.Base.AlarmHz)
{
lowerComputerStateInfoClass.AlarmHzObj.Add(new AlarmHz() { Count = item.Value, Name = item.Key });
}
#endregion

#region 忙碌状态显示
//lowerComputerStateInfoClass.Busy = GVL_VAR.GetInstance.Busy ? "空闲" : "忙碌";
#endregion

iotMessage.@params.LowerComputerStateInfo = JsonConvert.SerializeObject(lowerComputerStateInfoClass);
PublishContent = JsonConvert.SerializeObject(iotMessage);

MqttM2.GetInstance.PublishInfo(PublishContent);
//mqttClient.Publish($"/sys/grgp0rFA2uu/{deviceName}/thing/event/property/post", Encoding.UTF8.GetBytes(PublishContent), 0, false);

Thread.Sleep(1000);
}), "阿里云数据上报", new Action(() => { MqttM2.GetInstance.DisConnect(); }));
}

}
}

+ 32
- 0
HBLConsole.Business/MessageServerBase.cs View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HBLConsole.Abstract;

namespace HBLConsole.Business
{
public class MessageServerBase : AbstractMessageServer
{
public override void AddOrder<T>(T orderInfo)
{
throw new NotImplementedException();
}

public override void BatchingCountInfo()
{
throw new NotImplementedException();
}

public override void GetBatchingInfo<T>(T batchingInfo)
{
throw new NotImplementedException();
}

public override void GetRecipeBom<T>(T recipeBomInfo)
{
throw new NotImplementedException();
}
}
}

+ 22
- 0
HBLConsole.Business/ServerMessage.cs View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HBLConsole.Interface;
using BPA.Message;
using HBLConsole.Abstract;

namespace HBLConsole.Business
{
public class ServerMessage : IServerMessage
{
public void Universal(AbstractMessageServer abstractMessageServer, IMessage message)
{
abstractMessageServer.AddOrder(message);
abstractMessageServer.GetBatchingInfo(message);
abstractMessageServer.GetRecipeBom(message);
abstractMessageServer.BatchingCountInfo();
}
}
}

+ 18
- 0
HBLConsole.Communication/HBLConsole.Communication.csproj View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="M2Mqtt" Version="4.3.0" />
<PackageReference Include="MQTTnet" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.GVL\HBLConsole.GVL.csproj" />
<ProjectReference Include="..\HBLConsole.Model\HBLConsole.Model.csproj" />
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
</ItemGroup>

</Project>

+ 147
- 0
HBLConsole.Communication/M2MQTT/MqttM2.cs View File

@@ -0,0 +1,147 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
using Newtonsoft.Json;
using Communication.Model;
using System.Collections.Concurrent;
using Alarm.Enums;
using Alarm.Models;
using Alarm.Service;
using ServiceModel;
using GVL;
using BPA.Message;
using BPA.Utility;
using Communication.MQTT;
using System.Drawing;
using HBLConsole.Model;
using HBLConsole.Service;

namespace HBLConsole.Communication
{
public class MqttM2
{
private volatile static MqttM2 _Instance;
public static MqttM2 GetInstance => _Instance ?? (_Instance = new MqttM2());
private MqttM2() { }

string productKey = "grgp0rFA2uu";//产品密钥
string deviceName = "Machine01";//设备名称
string deviceSecret = "ee810ac992033ffc3047f4e80cb49521";//设备秘钥

MqttClient mqttClient;
//IotMessage iotMessage = new IotMessage();
//LowerComputerStateInfo lowerComputerStateInfoClass = new LowerComputerStateInfo();
//string PublishContent;

/// <summary>
/// 连接成功
/// </summary>
public Action ConnectOk { get; set; }
public void Init()
{
// 计算MQTT连接参数。
MqttSign sign = new MqttSign();
sign.calculate(productKey, deviceName, deviceSecret);
// 使用Paho连接阿里云物联网平台。
int port = 443;
string broker = productKey + ".iot-as-mqtt.cn-shanghai.aliyuncs.com";

mqttClient = new MqttClient(broker, port, true, MqttSslProtocols.TLSv1_2, null, null);
mqttClient.Connect(sign.getClientid(), sign.getUsername(), sign.getPassword(), true, 60);

if (mqttClient.IsConnected)
{
if (ConnectOk != null) ConnectOk();
MessageLog.GetInstance.Show("阿里云连接成功");

//订阅消息
//string[] topic = new string[] { "/sys/grgp0rFA2uu/Machine01/thing/event/property/post" };
//byte[] qosLevels = new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }; // qos=2
//mqttClient.Subscribe(topic, qosLevels);
//mqttClient.MqttMsgPublishReceived += MqttClient_MqttMsgPublishReceived;//接收消息事件


//PublishInfo();
}
else
MessageLog.GetInstance.Show("阿里云连接失败");
}

private void MqttClient_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
MessageLog.GetInstance.Show($"接收到阿里云消息:{Encoding.UTF8.GetString(e.Message)}");
}

/// <summary>
/// 推送消息
/// </summary>
public void PublishInfo(string Info)
{
mqttClient.Publish($"/sys/grgp0rFA2uu/{deviceName}/thing/event/property/post", Encoding.UTF8.GetBytes(Info), 0, false);

//ThreadManagerment.GetInstance.StartLong(new Action(() =>
//{
// AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.MCUDisconnected, "单片机掉线", AlarmLevel.严重报警);
// AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.IceCreamAbnormal, "冰淇淋机异常");
// AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.TakeBowlAbnormal, "取碗异常");
// AlarmHelper.GetInstance.EdgeAlarm(GVL_Fault.GetInstance.RobotAbnormal, "机器人异常", AlarmLevel.严重报警);

// #region 报警信息设置
// lowerComputerStateInfoClass.AlarmInfo.Clear();
// foreach (var item in AlarmHelper.GetInstance.GetAlarmInfo)
// {
// lowerComputerStateInfoClass.AlarmInfo.Add(new IotAlarmInfo()
// {
// time = item.date,
// AlarmLevel = item.AlarmLevel,
// info = item.AlarmInfomation,
// color = new ColorSet()
// {
// a = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].A,
// b = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].B,
// g = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].G,
// r = AlarmHelper.GetInstance.colorValue[item.AlarmLevel].R,
// },
// infoSrc = ""
// });
// }
// #endregion

// #region 报警频率显示
// lowerComputerStateInfoClass.AlarmHz.Clear();
// foreach (var item in Json<AlarmHzParameter>.GetInstance.Base.AlarmHz)
// {
// lowerComputerStateInfoClass.AlarmHz.Add(new AlarmHzObj() { Count = item.Value, Name = item.Key });
// }
// #endregion

// #region 忙碌状态显示
// lowerComputerStateInfoClass.Busy = GVL_VAR.GetInstance.Busy ? "空闲" : "忙碌";
// #endregion

// iotMessage.@params.LowerComputerStateInfo = JsonConvert.SerializeObject(lowerComputerStateInfoClass);
// PublishContent = JsonConvert.SerializeObject(iotMessage);
// mqttClient.Publish($"/sys/grgp0rFA2uu/{deviceName}/thing/event/property/post", Encoding.UTF8.GetBytes(PublishContent), 0, false);

// Thread.Sleep(1000);
//}), "阿里云数据上报", new Action(() => { if (mqttClient != null) mqttClient.Disconnect(); }));
}

/// <summary>
/// 断开连接
/// </summary>
public void DisConnect()
{
if (mqttClient != null) mqttClient.Disconnect();
}

}
}

+ 55
- 0
HBLConsole.Communication/M2MQTT/MqttSign.cs View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Communication
{
public class MqttSign
{
private string username = "";

private string password = "";

private string clientid = "";

public string getUsername() { return this.username; }

public string getPassword() { return this.password; }

public string getClientid() { return this.clientid; }

public bool calculate(string productKey, string deviceName, string deviceSecret)
{
if (productKey == null || deviceName == null || deviceSecret == null)
{
return false;
}

//MQTT用户名
this.username = deviceName + "&" + productKey;

//MQTT密码
String timestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString();
String plainPasswd = "clientId" + productKey + "." + deviceName + "deviceName" + deviceName + "productKey" + productKey + "timestamp" + timestamp;
this.password = hmacSha256(plainPasswd, deviceSecret);

//MQTT ClientId
this.clientid = productKey + "." + deviceName + "|" + "timestamp=" + timestamp + ",_v=paho-c#-1.0.0,securemode=2,signmethod=hmacsha256|";
return true;
}

public string hmacSha256(string plainText, string key)
{
var encoding = new System.Text.UTF8Encoding();
byte[] plainTextBytes = encoding.GetBytes(plainText);
byte[] keyBytes = encoding.GetBytes(key);

HMACSHA256 hmac = new HMACSHA256(keyBytes);
byte[] sign = hmac.ComputeHash(plainTextBytes);
return BitConverter.ToString(sign).Replace("-", string.Empty);
}
}
}

+ 161
- 0
HBLConsole.Communication/MqttHelper.cs View File

@@ -0,0 +1,161 @@
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using HBLConsole.GVL;
using HBLConsole.Service;

namespace HBLConsole.Communication
{
public class MqttHelper
{

private volatile static MqttHelper _Instance;
public static MqttHelper GetInstance => _Instance ?? (_Instance = new MqttHelper());
private MqttHelper() { }

private IMqttClient client;
IMqttClientOptions options;

/// <summary>
/// MQTT 接收消息
/// </summary>
public Action<MqttApplicationMessageReceivedEventArgs> MqttReceive { get; set; }

/// <summary>
/// MQTT 连接成功
/// </summary>
public Action ConnectOk { get; set; }

/// <summary>
/// 重连成功
/// </summary>
public Action Reconnection { get; set; }


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 =>
{
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)
{
MessageLog.GetInstance.Show("MQTT重连成功!");
if (Reconnection != null) Reconnection();
}

}).UseApplicationMessageReceivedHandler(c =>
{
MqttReceive(c);
}).UseConnectedHandler((e) =>
{
MessageLog.GetInstance.Show($"连接成功");
});


try
{
await client.ConnectAsync(options);
}
catch (Exception ex) { MessageLog.GetInstance.Show(ex.Message); }
if (!client.IsConnected)
{
Thread.Sleep(2000);
MessageLog.GetInstance.Show("mqtt连接失败!重连执行中");
goto p1;
}
MessageLog.GetInstance.Show("MQTT连接成功!");
if (ConnectOk != null) ConnectOk();
}

/// <summary>
/// Mqtt 订阅
/// </summary>
/// <param name="topic">需要订阅的主题</param>
public async void MqttSubscriptionAsync(string topic)
{
if (client != null)
{
if (client.IsConnected)
{
try
{
var result = await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic(topic).WithExactlyOnceQoS().Build());
}
catch { }
}
}
}

/// <summary>
/// Mqtt 订阅
/// </summary>
/// <param name="topic">需要订阅的主题</param>
public async void MqttSubscriptionAsync(string[] topic)
{
if (client != null)
{
if (client.IsConnected)
{
try
{
foreach (var item in topic)
{
var result = await client.SubscribeAsync(new MqttTopicFilterBuilder().WithTopic(item).WithExactlyOnceQoS().Build());
}

}
catch { }
}
}
}

/// <summary>
/// Mqtt 发布
/// </summary>
/// <param name="topic">需要发布的主题</param>
/// <param name="content">需要发布的内容</param>
public async void MqttPublishAsync(string topic, string content)
{
if (client != null)
{
if (client.IsConnected)
{

var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(content).WithExactlyOnceQoS().Build();
try
{
var result = await client.PublishAsync(msg);
}
catch { }
}
}
}




}
}

+ 18
- 0
HBLConsole.GVL/HBLConsole.GVL.csproj View File

@@ -4,4 +4,22 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Consul" Version="1.6.10.4" />
<PackageReference Include="Consul.Microsoft.Extensions.Configuration" Version="0.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="BPA.Utility">
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Utility.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

+ 78
- 0
HBLConsole.GVL/InternetInfo.cs View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using BPA.Utility.Consul.YT;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Consul;

namespace HBLConsole.GVL
{
/// <summary>
/// 网络信息数据
/// </summary>
public class InternetInfo
{
private volatile static InternetInfo _Instance;
public static InternetInfo GetInstance => _Instance ?? (_Instance = new InternetInfo());
private InternetInfo() { }

public void Init()
{
ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"];
ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);

IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/BQLControl/app.json", false, 5_000);
IConfiguration config = configurationBuilder.Build();
MqttUserName = config["Server:MqttUserName"];
MqttAddress = config["Server:MqttAddress"];
MqttPassword = config["Server:MqttPassword"];
MqttPort = int.Parse(config["Server:MqttPort"]);
}

/// <summary>
/// Consul 地址
/// </summary>
public string ConsulAddress { get; set; }

/// <summary>
/// 网络连接状态
/// </summary>
public bool NetworkConnectState { get; set; }

/// <summary>
/// 客户端ID
/// </summary>
public int ClientId { get; set; }

#region MQTT连接信息
/// <summary>
/// mqtt 服务地址
/// </summary>
public string MqttAddress { get; set; }

/// <summary>
/// mqtt 用户名
/// </summary>
public string MqttUserName { get; set; }

/// <summary>
/// mqtt 密码
/// </summary>
public string MqttPassword { get; set; }

/// <summary>
/// mqtt 端口号
/// </summary>
public int MqttPort { get; set; }
#endregion

#region API地址

#endregion

}
}

+ 17
- 0
HBLConsole.Interface/HBLConsole.Interface.csproj View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Abstract\HBLConsole.Abstract.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="BPA.Message">
<HintPath>..\..\..\..\BPACommon_output\net5.0\BPA.Message.dll</HintPath>
</Reference>
</ItemGroup>

</Project>

+ 16
- 0
HBLConsole.Interface/IServerMessage.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPA.Message;
using HBLConsole.Abstract;


namespace HBLConsole.Interface
{
public interface IServerMessage
{
public void Universal(AbstractMessageServer abstractMessageServer, IMessage message);
}
}

+ 7
- 0
HBLConsole.MainConsole/HBLConsole.MainConsole.csproj View File

@@ -4,4 +4,11 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.Communication\HBLConsole.Communication.csproj" />
<ProjectReference Include="..\HBLConsole.GVL\HBLConsole.GVL.csproj" />
<ProjectReference Include="..\HBLConsole.Model\HBLConsole.Model.csproj" />
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
</ItemGroup>

</Project>

+ 22
- 0
HBLConsole.MainConsole/Main.cs View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.MainConsole
{
public class Main
{

private volatile static Main _Instance;
public static Main GetInstance => _Instance ?? (_Instance = new Main());
private Main() { }

public void Init()
{

}

}
}

+ 16
- 0
HBLConsole.Model/Enums/AlarmLevel.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
public enum AlarmLevel
{
一般报警,
严重报警
}


}

+ 20
- 0
HBLConsole.Model/Enums/AlarmTriggerType.cs View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
public enum AlarmTriggerType
{
/// <summary>
/// 上升沿
/// </summary>
Rising,
/// <summary>
/// 下降沿
/// </summary>
Falling
}
}

+ 17
- 0
HBLConsole.Model/Iot/AlarmHzObj.cs View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
/// <summary>
/// 报警频率
/// </summary>
public class AlarmHz
{
public int Count { get; set; }
public string Name { get; set; }
}
}

+ 26
- 0
HBLConsole.Model/Iot/AlarmInfo.cs View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
public class AlarmInfo
{
/// <summary>
/// 报警信息
/// </summary>
public string AlarmInfomation { get; set; } = string.Empty;

/// <summary>
/// 报警时间
/// </summary>
public string date { get; set; }

/// <summary>
/// 报警等级
/// </summary>
public string AlarmLevel { get; set; }
}
}

+ 19
- 0
HBLConsole.Model/Iot/ColorSet.cs View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
/// <summary>
/// 报警字体颜色
/// </summary>
public class ColorSet
{
public byte r { get; set; }
public byte g { get; set; }
public byte b { get; set; }
public double a { get; set; }
}
}

+ 21
- 0
HBLConsole.Model/Iot/IotAlarmInfo.cs View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
/// <summary>
/// Iot 报警信息
/// </summary>
public class IotAlarmInfo
{
public string time { get; set; }
public string AlarmLevel { get; set; }
public string info { get; set; }
public ColorSet color { get; set; } = new ColorSet();
public ColorSet bgColor { get; set; } = new ColorSet();
public string infoSrc { get; set; }
}
}

+ 19
- 0
HBLConsole.Model/Iot/IotMessage.cs View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
/// <summary>
/// Iot 消息主体
/// </summary>
public class IotMessage
{
public string id { get; set; } = Guid.NewGuid().ToString();
public string version { get; set; } = "1.0";
public Iotparams @params { get; set; } = new Iotparams();
public string method { get; set; } = "thing.event.property.post";
}
}

+ 16
- 0
HBLConsole.Model/Iot/Iotparams.cs View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
/// <summary>
/// Iot 消息参数
/// </summary>
public class Iotparams
{
public string LowerComputerStateInfo { get; set; }
}
}

+ 20
- 0
HBLConsole.Model/Iot/LowerComputerStateInfoClass.cs View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
/// <summary>
/// 上位机状态信息
/// </summary>
public class LowerComputerStateInfo
{
public List<IotAlarmInfo> AlarmInfo { get; set; } = new List<IotAlarmInfo>();

public List<AlarmHz> AlarmHzObj { get; set; } = new List<AlarmHz>();

public string Busy { get; set; } = "忙碌";
}
}

+ 14
- 0
HBLConsole.Model/KeepParameter/AlarmHzParameter.cs View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Model
{
public class AlarmHzParameter
{
public ConcurrentDictionary<string, int> AlarmHz { get; set; } = new ConcurrentDictionary<string, int>();
}
}

+ 13
- 0
HBLConsole.Service/HBLConsole.Service.csproj View File

@@ -5,6 +5,19 @@
</PropertyGroup>

<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>



+ 109
- 0
HBLConsole.Service/SystemHelper.cs View File

@@ -0,0 +1,109 @@
using IWshRuntimeLibrary;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Windows.Forms;

namespace HBLConsole.Server
{
/// <summary>
/// 系统操作类
/// </summary>
public class SystemHelper
{
private volatile static SystemHelper _Instance;
public static SystemHelper GetInstance => _Instance ?? (_Instance = new SystemHelper());
private SystemHelper() { }

/// <summary>
/// 获取当前应用程序名称,包括后缀名
/// </summary>
public string GetApplicationName => $"{AppDomain.CurrentDomain.FriendlyName}.exe";

/// <summary>
/// 获取当前应用程序完整路径
/// </summary>
public string GetApplicationPath => $"{AppDomain.CurrentDomain.BaseDirectory}{GetApplicationName}";

/// <summary>
/// 创建桌面快捷方式
/// </summary>
/// <returns>成功或失败</returns>
public bool CreateDesktopShortcut()
{
//1、在COM对象中找到 Windows Script Host Object Model
//2、添加引用 using IWshRuntimeLibrary;
string deskTop = string.Empty;
try
{
deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";
if (System.IO.File.Exists(deskTop + GetApplicationName + ".lnk")) //
{
return true;
//System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式
}
WshShell shell = new WshShell();

//快捷键方式创建的位置、名称
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTop + GetApplicationName + ".lnk");
shortcut.TargetPath = GetApplicationPath; //目标文件
//该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
shortcut.Description = GetApplicationName; //描述
//shortcut.IconLocation = exePath + "\\logo.ico"; //快捷方式图标
shortcut.Arguments = "";
//shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键
shortcut.Save(); //必须调用保存快捷才成创建成功
return true;
}
catch (Exception)
{
return false;
}
}

/// <summary>
/// 设置开机自启动
/// </summary>
/// <param name="isAuto">true:开机启动,false:不开机自启</param>
public void AutoStart(bool isAuto = true)
{
if (isAuto == true)
{
RegistryKey R_local = Registry.CurrentUser;
RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
R_run.SetValue(GetApplicationName, GetApplicationPath);
R_run.Close();
R_local.Close();
}
else
{
RegistryKey R_local = Registry.CurrentUser;
RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
R_run.DeleteValue(GetApplicationName, false);
R_run.Close();
R_local.Close();
}
}

/// <summary>
/// 判断是否是自动启动
/// </summary>
/// <returns></returns>
public bool IsAutoStart()
{
//RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\");
return registryKey.GetValueNames().Contains(GetApplicationName);
}




}
}

+ 36
- 6
HBLConsole.sln View File

@@ -3,17 +3,27 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole", "HBLConsole\HBLConsole.csproj", "{1F887F1F-227D-41F5-9B42-C4F09381B750}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole", "HBLConsole\HBLConsole.csproj", "{1F887F1F-227D-41F5-9B42-C4F09381B750}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Service", "HBLConsole.Service\HBLConsole.Service.csproj", "{D9208FA9-66FC-4C42-9077-66419B2013F6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Service", "HBLConsole.Service\HBLConsole.Service.csproj", "{D9208FA9-66FC-4C42-9077-66419B2013F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Model", "HBLConsole.Model\HBLConsole.Model.csproj", "{1411E854-4124-444B-84EE-F8536E2C56B2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.Model", "HBLConsole.Model\HBLConsole.Model.csproj", "{1411E854-4124-444B-84EE-F8536E2C56B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.MainConsole", "HBLConsole.MainConsole\HBLConsole.MainConsole.csproj", "{D63D392D-4252-4610-A50F-3CC4A30A22C4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.MainConsole", "HBLConsole.MainConsole\HBLConsole.MainConsole.csproj", "{D63D392D-4252-4610-A50F-3CC4A30A22C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.GVL", "HBLConsole.GVL\HBLConsole.GVL.csproj", "{E1820D4A-B2FA-4F75-B3D5-8D421D2B1313}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.GVL", "HBLConsole.GVL\HBLConsole.GVL.csproj", "{E1820D4A-B2FA-4F75-B3D5-8D421D2B1313}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.PryUserControl", "HBLConsole.PryUserControl\HBLConsole.PryUserControl.csproj", "{F774F02B-C2C1-472A-AF1E-876304D0AEC7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HBLConsole.PryUserControl", "HBLConsole.PryUserControl\HBLConsole.PryUserControl.csproj", "{F774F02B-C2C1-472A-AF1E-876304D0AEC7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Communication", "HBLConsole.Communication\HBLConsole.Communication.csproj", "{59F71EE7-0B29-442F-B24F-295DCE7325D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Business", "HBLConsole.Business\HBLConsole.Business.csproj", "{62F88BDC-99F6-4C62-A870-7EE73E86C087}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Interface", "HBLConsole.Interface\HBLConsole.Interface.csproj", "{E4B66867-7024-40BC-942F-240B88DCC4C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HBLConsole.Abstract", "HBLConsole.Abstract\HBLConsole.Abstract.csproj", "{366CA88C-D690-4669-9AB8-1948D3CBF127}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Factory", "Factory\Factory.csproj", "{A71309D9-6791-4D0A-BFAE-7D6AD63467A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -45,6 +55,26 @@ Global
{F774F02B-C2C1-472A-AF1E-876304D0AEC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F774F02B-C2C1-472A-AF1E-876304D0AEC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F774F02B-C2C1-472A-AF1E-876304D0AEC7}.Release|Any CPU.Build.0 = Release|Any CPU
{59F71EE7-0B29-442F-B24F-295DCE7325D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59F71EE7-0B29-442F-B24F-295DCE7325D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59F71EE7-0B29-442F-B24F-295DCE7325D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59F71EE7-0B29-442F-B24F-295DCE7325D2}.Release|Any CPU.Build.0 = Release|Any CPU
{62F88BDC-99F6-4C62-A870-7EE73E86C087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62F88BDC-99F6-4C62-A870-7EE73E86C087}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62F88BDC-99F6-4C62-A870-7EE73E86C087}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62F88BDC-99F6-4C62-A870-7EE73E86C087}.Release|Any CPU.Build.0 = Release|Any CPU
{E4B66867-7024-40BC-942F-240B88DCC4C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4B66867-7024-40BC-942F-240B88DCC4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4B66867-7024-40BC-942F-240B88DCC4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4B66867-7024-40BC-942F-240B88DCC4C2}.Release|Any CPU.Build.0 = Release|Any CPU
{366CA88C-D690-4669-9AB8-1948D3CBF127}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{366CA88C-D690-4669-9AB8-1948D3CBF127}.Debug|Any CPU.Build.0 = Debug|Any CPU
{366CA88C-D690-4669-9AB8-1948D3CBF127}.Release|Any CPU.ActiveCfg = Release|Any CPU
{366CA88C-D690-4669-9AB8-1948D3CBF127}.Release|Any CPU.Build.0 = Release|Any CPU
{A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A71309D9-6791-4D0A-BFAE-7D6AD63467A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 18
- 0
HBLConsole/App.config View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--通用配置-->

<!--测试服务 Consul 地址-->
<!--<add key="ConsulAddress" value="http://114.117.161.250:8500" />-->

<!--正式服务 Consul 地址-->
<add key="ConsulAddress" value="http://162.14.105.138:9005" />

<!--客户端ID-->
<!--MorkD = 2,MorkS 且时且多 = 8,MorkS 珠海 = 9,冰淇淋 = 4,咖啡机 = 13-->
<add key="ClientId" value="9"/>


</appSettings>
</configuration>

+ 1
- 2
HBLConsole/App.xaml View File

@@ -2,7 +2,6 @@
x:Class="HBLConsole.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:HBLConsole"
StartupUri="/View/MainView.xaml">
xmlns:local="clr-namespace:HBLConsole">
<Application.Resources />
</Application>

+ 23
- 0
HBLConsole/App.xaml.cs View File

@@ -5,6 +5,10 @@ using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using HBLConsole.DialogWindow.View;
using HBLConsole.View;
using HBLConsole.Server;
using System.Diagnostics;

namespace HBLConsole
{
@@ -13,5 +17,24 @@ namespace HBLConsole
/// </summary>
public partial class App : Application
{
MainView mainView = new MainView();
ListDialogView listDialogView = new ListDialogView();
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
SystemHelper.GetInstance.AutoStart(false);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
mainView.Show();
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Process.Start($"{AppDomain.CurrentDomain.BaseDirectory}{AppDomain.CurrentDomain.FriendlyName}.exe");
}

protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
}
}
}

+ 13
- 1
HBLConsole/HBLConsole.csproj View File

@@ -87,6 +87,18 @@
<None Remove="Resources\Images\黑菠萝科技.png" />
</ItemGroup>

<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.14" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
@@ -180,12 +192,12 @@
<Folder Include="View\" />
<Folder Include="ViewModel\" />
<Folder Include="Model\" />
<Folder Include="Server\" />
<Folder Include="Converter\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HBLConsole.PryUserControl\HBLConsole.PryUserControl.csproj" />
<ProjectReference Include="..\HBLConsole.Service\HBLConsole.Service.csproj" />
</ItemGroup>

<ItemGroup>


+ 1
- 1
HBLConsole/Resources/ResourceDictionarys/BasicStyle.xaml View File

@@ -5,7 +5,7 @@
xmlns:pry="clr-namespace:HBLConsole.PryUserControl;assembly=HBLConsole.PryUserControl">

<!--#region 转换器-->
<con:ColorConverter x:Key="ColorConverter"/>
<con:ColorConverter x:Key="ColorConverter" />
<!--<con:ColorConverter x:Key="ColorConverter" />-->
<con:TextConverter x:Key="TextConverter" />
<!--#endregion-->


+ 39
- 14
HBLConsole/Resources/ResourceDictionarys/MyBorder.xaml View File

@@ -24,20 +24,33 @@
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden" />

<Border Margin="1.5 0.5 1 0.5" BorderThickness="1" BorderBrush="{StaticResource BorderGradient}" CornerRadius="0.5" ClipToBounds="True">
<Border
Margin="1.5,0.5,1,0.5"
BorderBrush="{StaticResource BorderGradient}"
BorderThickness="1"
ClipToBounds="True"
CornerRadius="0.5">
<Border.Effect>
<DropShadowEffect BlurRadius="20" ShadowDepth="0" Direction="0" Color="#3186e6" Opacity="1"/>
<DropShadowEffect
BlurRadius="20"
Direction="0"
Opacity="1"
ShadowDepth="0"
Color="#3186e6" />
</Border.Effect>
</Border>

<!-- 上边框 --><!--
<!-- 上边框 -->
<!--
<Path Stroke="{StaticResource BorderGradient}" StrokeThickness="0.5">
--><!--<Path.Stroke>
-->
<!--<Path.Stroke>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#3300FFFF" />
<GradientStop Offset="1" Color="#1500FFFF" />
</LinearGradientBrush>
</Path.Stroke>--><!--
</Path.Stroke>-->
<!--
<Path.Effect>
<DropShadowEffect
Direction="270"
@@ -54,14 +67,18 @@
</Path.Data>
</Path>

--><!-- 下边框 --><!--
-->
<!-- 下边框 -->
<!--
<Path Stroke="{StaticResource BorderGradient}" StrokeThickness="0.5">
--><!--<Path.Stroke>
-->
<!--<Path.Stroke>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="1" Color="#3300FFFF" />
<GradientStop Color="#1500FFFF" />
</LinearGradientBrush>
</Path.Stroke>--><!--
</Path.Stroke>-->
<!--
<Path.Effect>
<DropShadowEffect
Direction="90"
@@ -78,14 +95,18 @@
</Path.Data>
</Path>

--><!-- 左边框 --><!--
-->
<!-- 左边框 -->
<!--
<Path Stroke="{StaticResource BorderGradient}" StrokeThickness="1">
--><!--<Path.Stroke>
-->
<!--<Path.Stroke>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#3300FFFF" />
<GradientStop Offset="1" Color="#1500FFFF" />
</LinearGradientBrush>
</Path.Stroke>--><!--
</Path.Stroke>-->
<!--
<Path.Effect>
<DropShadowEffect
Direction="0"
@@ -103,14 +124,18 @@
</Path.Data>
</Path>

--><!-- 右边框 --><!--
-->
<!-- 右边框 -->
<!--
<Path Stroke="{StaticResource BorderGradient}" StrokeThickness="1">
--><!--<Path.Stroke>
-->
<!--<Path.Stroke>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#3300FFFF" />
<GradientStop Offset="1" Color="#1500FFFF" />
</LinearGradientBrush>
</Path.Stroke>--><!--
</Path.Stroke>-->
<!--
<Path.Effect>
<DropShadowEffect
Direction="180"


+ 109
- 0
HBLConsole/Server/SystemHelper.cs View File

@@ -0,0 +1,109 @@
//using IWshRuntimeLibrary;
//using Microsoft.Win32;
//using System;
//using System.Collections.Generic;
//using System.Diagnostics;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using System.Windows.Forms;

//namespace HBLConsole.Server
//{
// /// <summary>
// /// 系统操作类
// /// </summary>
// public class SystemHelper
// {
// private volatile static SystemHelper _Instance;
// public static SystemHelper GetInstance => _Instance ?? (_Instance = new SystemHelper());
// private SystemHelper() { }

// /// <summary>
// /// 获取当前应用程序名称,包括后缀名
// /// </summary>
// public string GetApplicationName => Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf(@"\") + 1);

// /// <summary>
// /// 获取当前应用程序完整路径
// /// </summary>
// public string GetApplicationPath => Application.ExecutablePath;

// /// <summary>
// /// 创建桌面快捷方式
// /// </summary>
// /// <returns>成功或失败</returns>
// public bool CreateDesktopShortcut()
// {
// //1、在COM对象中找到 Windows Script Host Object Model
// //2、添加引用 using IWshRuntimeLibrary;
// string deskTop = string.Empty;
// try
// {
// deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";
// if (System.IO.File.Exists(deskTop + GetApplicationName + ".lnk")) //
// {
// return true;
// //System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式
// }
// WshShell shell = new WshShell();

// //快捷键方式创建的位置、名称
// IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTop + GetApplicationName + ".lnk");
// shortcut.TargetPath = GetApplicationPath; //目标文件
// //该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
// shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
// shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
// shortcut.Description = GetApplicationName; //描述
// //shortcut.IconLocation = exePath + "\\logo.ico"; //快捷方式图标
// shortcut.Arguments = "";
// //shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键
// shortcut.Save(); //必须调用保存快捷才成创建成功
// return true;
// }
// catch (Exception)
// {
// return false;
// }
// }

// /// <summary>
// /// 设置开机自启动
// /// </summary>
// /// <param name="isAuto">true:开机启动,false:不开机自启</param>
// public void AutoStart(bool isAuto = true)
// {
// if (isAuto == true)
// {
// RegistryKey R_local = Registry.CurrentUser;
// RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
// R_run.SetValue(GetApplicationName, Application.ExecutablePath);
// R_run.Close();
// R_local.Close();
// }
// else
// {
// RegistryKey R_local = Registry.CurrentUser;
// RegistryKey R_run = R_local.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
// R_run.DeleteValue(GetApplicationName, false);
// R_run.Close();
// R_local.Close();
// }
// }

// /// <summary>
// /// 判断是否是自动启动
// /// </summary>
// /// <returns></returns>
// public bool IsAutoStart()
// {
// //RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\");
// RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\");
// return registryKey.GetValueNames().Contains(GetApplicationName);
// }




// }
//}

+ 1
- 54
HBLConsole/ViewModel/MainViewModel.cs View File

@@ -15,61 +15,13 @@ namespace HBLConsole.ViewModel
{
internal class MainViewModel : ViewModelBase
{
//ConcurrentQueue<MorksOrderPush> morksOrderPushes = new ConcurrentQueue<MorksOrderPush>();
public MainViewModel()
{
DoNavChanged("MessageLogView");
NavChangedCommand = new RelayCommand<object>(DoNavChanged);
//AbstractMessageServer.AddOrderAction = new Action<object>(o =>
// {
// if (o is MorksOrderPush morksOrderPush)
// {
// GVL.MessageLogOut.GetInstance.Show("接收到订单");
// Json<OrderData>.GetInstance.Base.morksOrderPushes.Clear();
// Json<OrderData>.GetInstance.Base.morksOrderPushes.Add(morksOrderPush);
// }
// });

//ThreadManagerment.GetInstance.StartLong(new Action(() =>
//{
// OrderCount = Json<OrderData>.GetInstance.Base.morksOrderPushes.Count;
// while (Json<OrderData>.GetInstance.Base.morksOrderPushes.Count > 0)
// {
// OrderCount = Json<OrderData>.GetInstance.Base.morksOrderPushes.Count;

// MorksOrderPush morksOrder = Json<OrderData>.GetInstance.Base.morksOrderPushes.ElementAt(0);

// GVL.MessageLogOut.GetInstance.Show($"【{morksOrder.SortNum}】开始制作");
// OrderChange(ORDER_STATUS.COOKING, morksOrder.SuborderId);
// Thread.Sleep(5000);

// GVL.MessageLogOut.GetInstance.Show($"【{morksOrder.SortNum}】制作完成");
// OrderChange(ORDER_STATUS.COMPLETED_COOK, morksOrder.SuborderId);
// Thread.Sleep(5000);

// GVL.MessageLogOut.GetInstance.Show($"【{morksOrder.SortNum}】取餐完成");
// OrderChange(ORDER_STATUS.COMPLETED_TAKE, morksOrder.SuborderId);
// Thread.Sleep(5000);

// }
// Thread.Sleep(1000);
//}), "订单模拟");

}





private void OrderChange(ORDER_STATUS OrderStatus, string subId)
{
//MQTT.GetInstance.SendMessagePackage(TOPIC.UP_MORKS_ORDER, MessageID.MORKS_ORDER_STATUS_CHANGE, new ZMJOrderStatusChange()
//{
// OrderStatus = OrderStatus,
// SuborderId = subId
//});
}

#region Command
public RelayCommand<object> NavChangedCommand { get; set; }
#endregion
@@ -77,7 +29,7 @@ namespace HBLConsole.ViewModel
#region 导航栏界面切换
private void DoNavChanged(object obj)
{
Type type = Type.GetType($"LargeScreen.NoodleMorkS.View.{obj.ToString()}");
Type type = Type.GetType($"HBLConsole.View.{obj.ToString()}");
if (type != null)
{
ConstructorInfo cti = type.GetConstructor(Type.EmptyTypes);
@@ -88,10 +40,5 @@ namespace HBLConsole.ViewModel
}
#endregion






}
}

+ 2
- 5
HBLConsole/ViewModel/ViewModelBase.cs View File

@@ -9,9 +9,6 @@ using System.Threading.Tasks;
using System.Windows;
using BPA.Message;
using BPA.Message.Kafka;
//using GVL;
//using LargeScreen.Model;
//using MainConsole;
using Microsoft.Toolkit.Mvvm.ComponentModel;

namespace HBLConsole.ViewModel
@@ -39,7 +36,7 @@ namespace HBLConsole.ViewModel
/// 日志消息
/// </summary>
public static string LogMessage { get { return _mLogMessage; } set { _mLogMessage = value; OnStaticPropertyChanged(); } }
private static string _mLogMessage;
private static string _mLogMessage = string.Empty;

/// <summary>
/// 当前订单量
@@ -56,7 +53,7 @@ namespace HBLConsole.ViewModel
/// 显示当前窗体名称
/// </summary>
public static string WindowName { get { return _mWindowName; } set { _mWindowName = value; OnStaticPropertyChanged(); } }
private static string _mWindowName;
private static string _mWindowName = string.Empty;

#endregion



Loading…
Cancel
Save