From ce086f95a2d62212d822ba05c9eaf0af4245db93 Mon Sep 17 00:00:00 2001 From: fyf Date: Fri, 13 May 2022 12:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=91=8A=E8=AD=A6=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Themes/MyStyle.xaml | 7 +- BPASmartClient.Device/BaseDevice.cs | 12 +-- BPASmartClient.Device/IDevice.cs | 4 +- BPASmartClient.IoT/DataVClient.cs | 10 +- BPASmartClient.Message/MessageLog.cs | 36 +++++++ BPASmartClient.ViewModel/LogViewModel.cs | 10 ++ BPASmartClient.ViewModel/MainViewModel.cs | 95 +++++++++++++++++++ BPASmartClient/MainWindow.xaml | 7 +- 8 files changed, 166 insertions(+), 15 deletions(-) diff --git a/BPASmartClient.CustomResource/Themes/MyStyle.xaml b/BPASmartClient.CustomResource/Themes/MyStyle.xaml index 303b9782..5a02829c 100644 --- a/BPASmartClient.CustomResource/Themes/MyStyle.xaml +++ b/BPASmartClient.CustomResource/Themes/MyStyle.xaml @@ -77,7 +77,7 @@ HorizontalAlignment="Center" FontSize="8" Foreground="#FF00E6F7" - Text="{Binding ListNum}" /> + Text="{Binding ListNum, Mode=TwoWay}" /> + + + + + diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index 337066cd..0ab65f37 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/BPASmartClient.Device/BaseDevice.cs @@ -99,8 +99,8 @@ namespace BPASmartClient.Device /// private List peripherals; - public Action AddErrorAction { get; set; } - public Action DeleteErrorAction { get; set; } + public Action AddErrorAction { get; set; } + public Action DeleteErrorAction { get; set; } #endregion @@ -173,7 +173,7 @@ namespace BPASmartClient.Device Text = item.Ms }; Error.Add(obj); - AddErrorAction?.Invoke(obj); + AddErrorAction?.Invoke(DeviceId,obj); } } else @@ -182,7 +182,7 @@ namespace BPASmartClient.Device if (res != null) { Error.Remove(res); - DeleteErrorAction?.Invoke(res); + DeleteErrorAction?.Invoke(DeviceId,res); } } } @@ -234,7 +234,7 @@ namespace BPASmartClient.Device Text = res.Info }; Error.Add(obj); - AddErrorAction?.Invoke(obj); + AddErrorAction?.Invoke(DeviceId, obj); } }); alarmHelper.RemoveAction = new Action((s) => @@ -243,7 +243,7 @@ namespace BPASmartClient.Device if (res != null && Error.Contains(res)) { Error.Remove(res); - DeleteErrorAction?.Invoke(res); + DeleteErrorAction?.Invoke(DeviceId, res); } }); ThreadManage.GetInstance().StartLong(new Action(() => diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs index ef47bf8e..582215a8 100644 --- a/BPASmartClient.Device/IDevice.cs +++ b/BPASmartClient.Device/IDevice.cs @@ -82,7 +82,7 @@ namespace BPASmartClient.Device /// object GetPropertyValue(object info, string field); - Action AddErrorAction { get; set; } - Action DeleteErrorAction { get; set; } + Action AddErrorAction { get; set; } + Action DeleteErrorAction { get; set; } } } diff --git a/BPASmartClient.IoT/DataVClient.cs b/BPASmartClient.IoT/DataVClient.cs index 5fa65c91..702b0b42 100644 --- a/BPASmartClient.IoT/DataVClient.cs +++ b/BPASmartClient.IoT/DataVClient.cs @@ -184,7 +184,7 @@ namespace BPASmartClient.IoT /// 增加告警 /// /// - private void AddErrorAction(object obj) + private void AddErrorAction(int Devid, object obj) { string id = Guid.NewGuid().ToString(); HttpAddAlarm(new AlarmTable @@ -193,16 +193,19 @@ namespace BPASmartClient.IoT AlarmType = GetPropertyValue(obj, "Type").ToString(), AlarmMessage = GetPropertyValue(obj, "Text").ToString(), AlarmVla = "告警", + DeviceId = Devid.ToString(), KeyID = id, }); keyValues[GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString()] =id ; + MessageLog.GetInstance.AddDeviceAlarmLogShow(GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(),id); + } /// /// 删除告警 /// /// - private void DeleteErrorAction(object obj) + private void DeleteErrorAction(int Devid, object obj) { string message = GetPropertyValue(obj, "Time").ToString() + GetPropertyValue(obj, "Type").ToString() + GetPropertyValue(obj, "Text").ToString(); if (keyValues.ContainsKey(message)) @@ -213,9 +216,12 @@ namespace BPASmartClient.IoT AlarmType = GetPropertyValue(obj, "Type").ToString(), AlarmMessage = GetPropertyValue(obj, "Text").ToString(), AlarmVla = "告警", + DeviceId= Devid.ToString(), KeyID = keyValues[message], State="n" }); + MessageLog.GetInstance.DeleteDeviceAlarmLogShow(message, keyValues[message]); + } } diff --git a/BPASmartClient.Message/MessageLog.cs b/BPASmartClient.Message/MessageLog.cs index 468a7995..67c29b7c 100644 --- a/BPASmartClient.Message/MessageLog.cs +++ b/BPASmartClient.Message/MessageLog.cs @@ -89,6 +89,42 @@ namespace BPASmartClient.Message } #endregion + #region 设备告警日志 + /// + /// 设备告警日志委托 + /// + public Action DeviceAlarmLogNotify { get; set; } + public Action AlarmLogNotify { get; set; } + /// + /// 设备告警日志委托字典 + /// + public ConcurrentDictionary DPAlarmInfo = new ConcurrentDictionary(); + /// + /// 设备告警日志输出 + /// + /// + public void AddDeviceAlarmLogShow(string id, string info) + { + DPAlarmInfo[info] = id; + Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); + if (DeviceAlarmLogNotify != null) DeviceAlarmLogNotify(id, info); + if (AlarmLogNotify != null) AlarmLogNotify(); + } + /// + /// 设备告警日志输出 + /// + /// + public void DeleteDeviceAlarmLogShow(string id, string info) + { + if (DPAlarmInfo.ContainsKey(id)) + { + string mes=string.Empty; + DPAlarmInfo.Remove(id, out mes); + if (AlarmLogNotify != null) AlarmLogNotify(); + } + } + #endregion + #region 查找设备ID /// /// 查询设备ID diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 1f26dd4a..7df670cd 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -67,6 +67,16 @@ namespace BPASmartClient.ViewModel })); }); + //设备告警日志 + MessageLog.GetInstance.DeviceAlarmLogNotify = new Action((id, s) => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + LogDataGrid.Insert(0, new LogModel { message = id, type = "DeviceAlarm" }); + logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); + })); + }); + //错误日志 MessageLog.GetInstance.ExInfoNotify = new Action((s) => { diff --git a/BPASmartClient.ViewModel/MainViewModel.cs b/BPASmartClient.ViewModel/MainViewModel.cs index 7b22558f..595671c8 100644 --- a/BPASmartClient.ViewModel/MainViewModel.cs +++ b/BPASmartClient.ViewModel/MainViewModel.cs @@ -1,4 +1,6 @@ using BPASmartClient.Business; +using BPASmartClient.Helper; +using BPASmartClient.Message; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; @@ -9,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using System.Windows.Threading; namespace BPASmartClient.ViewModel { @@ -17,9 +20,101 @@ namespace BPASmartClient.ViewModel /// public class MainViewModel : ObservableObject { + /// + /// 网络连接状态 + /// + private bool _NetworkConnectState = true; + public bool NetworkConnectState + { + get + { + return _NetworkConnectState; + } + set + { + if (_NetworkConnectState == value) + return; + _NetworkConnectState = value; + OnPropertyChanged("NetworkConnectState"); + } + } + /// + /// 是否告警 + /// + public AlarmModel IsAlarm { get; set; } + + public DispatcherTimer dispatcherTimer; + + public MainViewModel() { + IsAlarm =new AlarmModel(); OrderStatusViewModel.Init(); + //设备告警日志 + MessageLog.GetInstance.AlarmLogNotify = new Action(() => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + IsAlarm.IsCheck = MessageLog.GetInstance.DPAlarmInfo.Count > 0; + IsAlarm.ListNum = MessageLog.GetInstance.DPAlarmInfo.Count; + })); + }); + + dispatcherTimer = new DispatcherTimer(); + dispatcherTimer.Tick += delegate + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + NetworkConnectState = UniversalHelper.GetInstance().GetNetworkState(); + })); + }; + dispatcherTimer.Interval = TimeSpan.FromSeconds(1); + dispatcherTimer.Start(); + } + } + + public class AlarmModel : ObservableObject + { + /// + /// 是否告警 + /// + private bool _IsCheck = false; + public bool IsCheck + { + get + { + return _IsCheck; + } + set + { + if (_IsCheck == value) + return; + _IsCheck = value; + OnPropertyChanged("IsCheck"); + } + } + /// + /// 告警数量 + /// + private int _ListNum = 0; + public int ListNum + { + get + { + return _ListNum; + } + set + { + if (_ListNum == value) + return; + _ListNum = value; + OnPropertyChanged("ListNum"); + } + } + + public AlarmModel() + { + } } } diff --git a/BPASmartClient/MainWindow.xaml b/BPASmartClient/MainWindow.xaml index 907fb28f..a97db6ee 100644 --- a/BPASmartClient/MainWindow.xaml +++ b/BPASmartClient/MainWindow.xaml @@ -177,16 +177,15 @@ HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand" - DataContext="{Binding GaoJingMessage}" - IsChecked="True" + IsChecked="{Binding NetworkConnectState}" Style="{DynamicResource StatusBtnStyle网络连接状态}" ToolTip="网络连接状态" />