From 90fb39d8557c58f5a8177d686a6842b9e6cfd62d 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: Fri, 13 May 2022 15:30:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E8=B0=83=E8=AF=95=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.Message/MessageLog.cs | 21 +++++++------- BPASmartClient.ViewModel/LogViewModel.cs | 36 ++++++++++-------------- BPASmartClient/App.config | 24 ++++++++-------- 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/BPASmartClient.Message/MessageLog.cs b/BPASmartClient.Message/MessageLog.cs index 84e6cbc0..58d0d8d7 100644 --- a/BPASmartClient.Message/MessageLog.cs +++ b/BPASmartClient.Message/MessageLog.cs @@ -81,11 +81,15 @@ namespace BPASmartClient.Message { if (!DPLogInfo.ContainsKey(id)) DPLogInfo.TryAdd(id, info); - Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); - //ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}"; - if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id,info); - } + else + DPLogInfo[id] = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DPLogInfo[id]}"; + Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); + if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id, info); + //Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); + // //ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}"; + // if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(id,info); } + #endregion #region 设备告警日志 @@ -117,16 +121,13 @@ namespace BPASmartClient.Message { if (DPAlarmInfo.ContainsKey(id)) { - string mes=string.Empty; + string mes = string.Empty; DPAlarmInfo.Remove(id, out mes); if (AlarmLogNotify != null) AlarmLogNotify(); } } - else - DPLogInfo[id] = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DPLogInfo[id]}"; - Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}"); - if (DeviceProcessLogNotify != null) DeviceProcessLogNotify(info); - } + + #endregion #region 查找设备ID diff --git a/BPASmartClient.ViewModel/LogViewModel.cs b/BPASmartClient.ViewModel/LogViewModel.cs index 7fe27c38..77cff3f5 100644 --- a/BPASmartClient.ViewModel/LogViewModel.cs +++ b/BPASmartClient.ViewModel/LogViewModel.cs @@ -24,7 +24,7 @@ namespace BPASmartClient.ViewModel public class LogViewModel : ObservableObject { public DispatcherTimer dispatcherTimer; - public string ClientId= System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); + public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); private ObservableCollection _LogModels; public ObservableCollection LogDataGrid { @@ -45,27 +45,27 @@ namespace BPASmartClient.ViewModel private LogViewModel() { logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); - if (LogDataGrid==null) LogDataGrid = new ObservableCollection(); + if (LogDataGrid == null) LogDataGrid = new ObservableCollection(); //一般日志 MessageLog.GetInstance.InfoNotify = new Action((s) => { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - LogDataGrid.Insert(0,new LogModel { message = s,type = "Info" }); + LogDataGrid.Insert(0, new LogModel { message = s, type = "Info" }); logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s); })); }); //设备日志 - MessageLog.GetInstance.DeviceProcessLogNotify = new Action((id,s) => - { - System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => - { - LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" }); - logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s); - })); - }); + MessageLog.GetInstance.DeviceProcessLogNotify = new Action((id, s) => + { + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" }); + logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s); + })); + }); //设备告警日志 MessageLog.GetInstance.DeviceAlarmLogNotify = new Action((id, s) => @@ -82,7 +82,7 @@ namespace BPASmartClient.ViewModel { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { - LogDataGrid.Insert(0,new LogModel { message = s,type = "Error" }); + LogDataGrid.Insert(0, new LogModel { message = s, type = "Error" }); logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s); DataVClient.GetInstance().HttpAddLog(new LogTable { @@ -94,13 +94,7 @@ namespace BPASmartClient.ViewModel }); })); }); - MessageLog.GetInstance.DeviceProcessLogNotify = new Action((s) => - { - Application.Current?.Dispatcher.Invoke(new Action(() => - { - LogDataGrid.Insert(0, new LogModel { message = s, type = "Device" });//设备消息 - })); - }); + ExcelCommand = new RelayCommand(() => { ExcellOrder(); @@ -113,10 +107,10 @@ namespace BPASmartClient.ViewModel { if (LogDataGrid.Count > 100) { - LogDataGrid.RemoveAt(LogDataGrid.Count-1); + LogDataGrid.RemoveAt(LogDataGrid.Count - 1); } })); - + }; dispatcherTimer.Interval = TimeSpan.FromSeconds(10); dispatcherTimer.Start(); diff --git a/BPASmartClient/App.config b/BPASmartClient/App.config index 4ce41952..e1353de6 100644 --- a/BPASmartClient/App.config +++ b/BPASmartClient/App.config @@ -3,13 +3,13 @@ - + - + @@ -25,16 +25,16 @@ --> - - - - - - - - - - + + + + + + + + + +