1 feat(mqtt): 实现MQTT服务器状态管理与事件系统
2
3 1. 在MqttServer和MqttServerDto模型中添加IsConnect属性,用于跟踪连接状态
4 2. 重构MqttManagementService服务,使用事件驱动方式管理服务器状态变化
5 3. 实现MqttServerChangedEventArgs事件参数类,支持区分不同变更类型
6 4. 在IEventService中添加OnMqttServerChanged事件,实现事件通知机制
7 5. 优化数据存储结构,将MqttServers从ObservableCollection改为ObservableDictionary
8 6. 更新MqttServiceManager以正确处理连接状态和事件触发
9 7. 在WPF层更新UI以响应服务器状态变化
10 8. 删除不再需要的Helper类(DataServicesHelper, MessageHelper, SiemensHelper)
11 9. 在NLog配置中添加调试器输出目标以便调试
12 10. 完善VariableHistoryViewModel防止空引用异常
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Core.Models;
|
||||
using DMS.WPF.ViewModels;
|
||||
using DMS.WPF.ViewModels;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DMS.WPF.Helper;
|
||||
|
||||
public class DataServicesHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 从设备列表中找到变量表VarTable对象
|
||||
/// </summary>
|
||||
/// <param name="vtableId">VarTable的ID</param>
|
||||
/// <returns>如果找到择返回对象,否则返回null</returns>
|
||||
public static VariableTable FindVarTableForDevice(List<Device> devices, int vtableId)
|
||||
{
|
||||
VariableTable varTable = null;
|
||||
foreach (var device in devices)
|
||||
{
|
||||
varTable = device.VariableTables.FirstOrDefault(v => v.Id == vtableId);
|
||||
if (varTable != null)
|
||||
return varTable;
|
||||
}
|
||||
|
||||
return varTable;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static MenuBean FindMenusForDevice(Device device, IEnumerable<MenuBean> menus)
|
||||
{
|
||||
// if (menus == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// foreach (var menu in menus)
|
||||
// {
|
||||
// // 检查当前菜单项是否匹配
|
||||
// if (menu.Type==MenuType.DeviceMenu && menu.DataId ==device.Id)
|
||||
// {
|
||||
// return menu;
|
||||
// }
|
||||
//
|
||||
// // 递归搜索子菜单
|
||||
// var foundInSubMenu = FindMenusForDevice(device, menu.Items);
|
||||
// if (foundInSubMenu != null)
|
||||
// {
|
||||
// return foundInSubMenu;
|
||||
// }
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给菜单排序
|
||||
/// </summary>
|
||||
/// <param name="menu"></param>
|
||||
public static void SortMenus(MenuBean menu)
|
||||
{
|
||||
// if (menu.Items == null || menu.Items.Count() == 0)
|
||||
// return;
|
||||
// menu.Items.Sort((a, b) =>
|
||||
// a.Type.ToString().Length.CompareTo(b.Type.ToString().Length)
|
||||
// );
|
||||
// foreach (var menuItem in menu.Items)
|
||||
// {
|
||||
// SortMenus(menuItem);
|
||||
// }
|
||||
}
|
||||
|
||||
public static ViewModelBase GetMainViewModel(string name)
|
||||
{
|
||||
ViewModelBase navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
switch (name)
|
||||
{
|
||||
case "主页":
|
||||
navgateVM = App.Current.Services.GetRequiredService<HomeViewModel>();
|
||||
break;
|
||||
case "设备":
|
||||
navgateVM = App.Current.Services.GetRequiredService<DevicesViewModel>();
|
||||
break;
|
||||
case "Mqtt服务器":
|
||||
navgateVM = App.Current.Services.GetRequiredService<MqttsViewModel>();
|
||||
break;
|
||||
case "数据转换":
|
||||
navgateVM = App.Current.Services.GetRequiredService<DataTransformViewModel>();
|
||||
break;
|
||||
case "设置":
|
||||
navgateVM = App.Current.Services.GetRequiredService<SettingViewModel>();
|
||||
break;
|
||||
}
|
||||
|
||||
return navgateVM;
|
||||
}
|
||||
|
||||
public static MenuBean FindVarTableMenu(int varTableId, List<MenuBean> menus)
|
||||
{
|
||||
// if (menus == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// foreach (var menu in menus)
|
||||
// {
|
||||
// // 检查当前菜单项是否匹配
|
||||
// if (menu.Type==MenuType.VariableTableMenu && menu.DataId ==varTableId)
|
||||
// {
|
||||
// return menu;
|
||||
// }
|
||||
//
|
||||
// // 递归搜索子菜单
|
||||
// var foundInSubMenu = FindVarTableMenu(varTableId, menu.Items);
|
||||
// if (foundInSubMenu != null)
|
||||
// {
|
||||
// return foundInSubMenu;
|
||||
// }
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Message;
|
||||
using DMS.WPF.ViewModels;
|
||||
|
||||
namespace DMS.WPF.Helper;
|
||||
|
||||
public class MessageHelper
|
||||
{
|
||||
public static void Send<T>(T message) where T : class
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send<T>(message);
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送加载消息
|
||||
/// </summary>
|
||||
/// <param name="loadType">加载的类型,如菜单</param>
|
||||
public static void SendLoadMessage(LoadTypes loadType)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send<LoadMessage>(new LoadMessage(loadType));
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送导航消息
|
||||
/// </summary>
|
||||
/// <param name="vm">导航View的ViewModel</param>
|
||||
/// <param name="param">带的参数</param>
|
||||
public static void SendNavgatorMessage(ViewModelBase vm)
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send<NavgatorMessage>(new NavgatorMessage(vm));
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
namespace DMS.Helper;
|
||||
|
||||
/// <summary>
|
||||
/// 西门子帮助类
|
||||
/// </summary>
|
||||
public static class SiemensHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 将S7数据类型字符串转换为C#数据类型字符串
|
||||
/// </summary>
|
||||
/// <param name="s7Type">S7数据类型字符串</param>
|
||||
/// <returns>对应的C#数据类型字符串</returns>
|
||||
public static string S7ToCSharpTypeString(string s7Type)
|
||||
{
|
||||
switch (s7Type.ToUpper())
|
||||
{
|
||||
case "BOOL":
|
||||
return "bool";
|
||||
case "BYTE":
|
||||
return "byte";
|
||||
case "WORD":
|
||||
return "ushort";
|
||||
case "DWORD":
|
||||
return "uint";
|
||||
case "INT":
|
||||
return "short";
|
||||
case "DINT":
|
||||
return "int";
|
||||
case "REAL":
|
||||
return "float";
|
||||
case "LREAL":
|
||||
return "double";
|
||||
case "CHAR":
|
||||
return "char";
|
||||
case "STRING":
|
||||
return "string";
|
||||
case "TIMER":
|
||||
case "TIME":
|
||||
return "TimeSpan";
|
||||
case "COUNTER":
|
||||
return "ushort";
|
||||
case "DATE":
|
||||
return "DateTime";
|
||||
case "TIME_OF_DAY":
|
||||
case "TOD":
|
||||
return "DateTime";
|
||||
case "DATE_AND_TIME":
|
||||
case "DT":
|
||||
return "DateTime";
|
||||
default:
|
||||
return "object";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将S7读取到的值转换为显示值
|
||||
/// </summary>
|
||||
/// <param name="value">S7读取到的原始值</param>
|
||||
/// <param name="dataType">变量的数据类型</param>
|
||||
/// <param name="conversion">转换规则</param>
|
||||
/// <returns>显示值</returns>
|
||||
public static string ConvertS7Value(object value, string dataType, string conversion)
|
||||
{
|
||||
if (value == null) return string.Empty;
|
||||
|
||||
// For now, a simple conversion to string. More complex logic can be added here.
|
||||
// Based on dataType and conversion, you might parse, format, or apply formulas.
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user