|
|
@@ -1,12 +1,14 @@ |
|
|
|
using BPASmartClient.Helper; |
|
|
|
using BPASmartClient.IoT; |
|
|
|
using BPASmartClient.Message; |
|
|
|
using BPASmartClient.Model; |
|
|
|
using Microsoft.Toolkit.Mvvm.ComponentModel; |
|
|
|
using Microsoft.Toolkit.Mvvm.Input; |
|
|
|
using Microsoft.Win32; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
@@ -26,6 +28,7 @@ namespace BPASmartClient.ViewModel |
|
|
|
#region 变量 |
|
|
|
public DispatcherTimer dispatcherTimer; |
|
|
|
public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); |
|
|
|
public ObservableCollection<LogModel> LogDataGridData { get; set; } |
|
|
|
private ObservableCollection<LogModel> _LogModels;public ObservableCollection<LogModel> LogDataGrid |
|
|
|
{ |
|
|
|
get |
|
|
@@ -68,6 +71,54 @@ namespace BPASmartClient.ViewModel |
|
|
|
OnPropertyChanged("TimedClear"); |
|
|
|
} |
|
|
|
} |
|
|
|
private string _SelectedText = ""; |
|
|
|
public string SelectedText |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _SelectedText; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_SelectedText == value) |
|
|
|
return; |
|
|
|
_SelectedText = value; |
|
|
|
OnPropertyChanged("SelectedText"); |
|
|
|
} |
|
|
|
} |
|
|
|
public ObservableCollection<BookEx> SelectBookExs { set; get; } |
|
|
|
private ObservableCollection<BookEx> _books; |
|
|
|
public ObservableCollection<BookEx> BookExs |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (_books == null) |
|
|
|
{ |
|
|
|
_books = new ObservableCollection<BookEx>(); |
|
|
|
|
|
|
|
_books.CollectionChanged += (sender, e) => |
|
|
|
{ |
|
|
|
if (e.OldItems != null) |
|
|
|
{ |
|
|
|
foreach (BookEx bookEx in e.OldItems) |
|
|
|
{ |
|
|
|
bookEx.PropertyChanged -= ItemPropertyChanged; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (e.NewItems != null) |
|
|
|
{ |
|
|
|
foreach (BookEx bookEx in e.NewItems) |
|
|
|
{ |
|
|
|
bookEx.PropertyChanged += ItemPropertyChanged; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
return _books; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 单一 |
|
|
@@ -85,14 +136,23 @@ namespace BPASmartClient.ViewModel |
|
|
|
/// </summary> |
|
|
|
public void Init() |
|
|
|
{ |
|
|
|
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>(); |
|
|
|
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); |
|
|
|
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>(); |
|
|
|
if (LogDataGridData == null) LogDataGridData = new ObservableCollection<LogModel>(); |
|
|
|
BookExs.Add(new BookEx(new Book() { Name = "一般日志", Tag = "Info" }) { IsChecked = true }); |
|
|
|
BookExs.Add(new BookEx(new Book() { Name = "设备日志", Tag = "DeviceLog" }) { IsChecked = true }); |
|
|
|
BookExs.Add(new BookEx(new Book() { Name = "错误日志", Tag = "Error" }) { IsChecked = true }); |
|
|
|
BookExs.Add(new BookEx(new Book() { Name = "设备告警", Tag = "DeviceAlarm" }) { IsChecked = true }); |
|
|
|
SelectBookExs = new ObservableCollection<BookEx>(); |
|
|
|
ItemPropertyChanged(new BookEx(new Book()) { IsChecked = true }, new PropertyChangedEventArgs("IsChecked")); |
|
|
|
//一般日志 |
|
|
|
MessageLog.GetInstance.InfoNotify = new Action<string>((s) => |
|
|
|
{ |
|
|
|
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => |
|
|
|
{ |
|
|
|
LogDataGrid.Insert(0, new LogModel { message = s, type = "Info" }); |
|
|
|
LogModel logModel = new LogModel { message = s, type = "Info" }; |
|
|
|
LogDataGridData.Insert(0, logModel); |
|
|
|
AddLog(logModel); |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s); |
|
|
|
})); |
|
|
|
}); |
|
|
@@ -101,7 +161,9 @@ namespace BPASmartClient.ViewModel |
|
|
|
{ |
|
|
|
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => |
|
|
|
{ |
|
|
|
LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" }); |
|
|
|
LogModel logModel = new LogModel { message = s, type = "DeviceLog" }; |
|
|
|
LogDataGridData.Insert(0, logModel); |
|
|
|
AddLog(logModel); |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, s); |
|
|
|
})); |
|
|
|
}); |
|
|
@@ -110,7 +172,9 @@ namespace BPASmartClient.ViewModel |
|
|
|
{ |
|
|
|
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => |
|
|
|
{ |
|
|
|
LogDataGrid.Insert(0, new LogModel { message = id, type = "DeviceAlarm" }); |
|
|
|
LogModel logModel = new LogModel { message = id, type = "DeviceAlarm" }; |
|
|
|
LogDataGridData.Insert(0, logModel); |
|
|
|
AddLog(logModel); |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); |
|
|
|
})); |
|
|
|
}); |
|
|
@@ -119,7 +183,9 @@ namespace BPASmartClient.ViewModel |
|
|
|
{ |
|
|
|
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => |
|
|
|
{ |
|
|
|
LogDataGrid.Insert(0, new LogModel { message = s, type = "Error" }); |
|
|
|
LogModel logModel = new LogModel { message = s, type = "Error" }; |
|
|
|
LogDataGridData.Insert(0, logModel); |
|
|
|
AddLog(logModel); |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.ERROR, s); |
|
|
|
DataVClient.GetInstance().HttpAddLog(new LogTable |
|
|
|
{ |
|
|
@@ -154,9 +220,11 @@ namespace BPASmartClient.ViewModel |
|
|
|
{ |
|
|
|
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => |
|
|
|
{ |
|
|
|
if (LogDataGrid.Count > 100) |
|
|
|
if (LogDataGridData.Count > 200) |
|
|
|
{ |
|
|
|
LogDataGrid.RemoveAt(LogDataGrid.Count - 1); |
|
|
|
LogModel logModel= LogDataGridData.Last(); |
|
|
|
DeleteLog(logModel); |
|
|
|
LogDataGridData.Remove(logModel); |
|
|
|
} |
|
|
|
})); |
|
|
|
|
|
|
@@ -164,6 +232,43 @@ namespace BPASmartClient.ViewModel |
|
|
|
dispatcherTimer.Interval = TimeSpan.FromSeconds(10); |
|
|
|
dispatcherTimer.Start(); |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 增加日志 |
|
|
|
/// </summary> |
|
|
|
public void AddLog(LogModel logModel) |
|
|
|
{ |
|
|
|
BookEx book= SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == logModel.type); |
|
|
|
if (book != null) |
|
|
|
{ |
|
|
|
LogDataGrid.Insert(0, logModel); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 刷新日志 |
|
|
|
/// </summary> |
|
|
|
/// <param name="logModel"></param> |
|
|
|
public void RefreshLog() |
|
|
|
{ |
|
|
|
LogDataGrid.Clear(); |
|
|
|
LogDataGridData?.ToList().ForEach(b => { |
|
|
|
|
|
|
|
BookEx book = SelectBookExs?.ToList().Find(par => par.IsChecked && par.BookN.Tag == b.type); |
|
|
|
if (book != null) |
|
|
|
{ |
|
|
|
LogDataGrid.Add(b); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 删除日志 |
|
|
|
/// </summary> |
|
|
|
public void DeleteLog(LogModel logModel) |
|
|
|
{ |
|
|
|
LogModel log= LogDataGrid?.ToList().Find(par => par == logModel); |
|
|
|
if(log!=null) LogDataGrid.Remove(log); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 导出数据 |
|
|
|
/// </summary> |
|
|
@@ -210,6 +315,33 @@ namespace BPASmartClient.ViewModel |
|
|
|
System.Windows.MessageBox.Show("无数据!"); |
|
|
|
|
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 选中改变 |
|
|
|
/// </summary> |
|
|
|
/// <param name="sender"></param> |
|
|
|
/// <param name="e"></param> |
|
|
|
private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
if (e.PropertyName == "IsChecked") |
|
|
|
{ |
|
|
|
BookEx bookEx = sender as BookEx; |
|
|
|
|
|
|
|
if (bookEx != null) |
|
|
|
{ |
|
|
|
IEnumerable<BookEx> bookExs = BookExs.Where(b => b.IsChecked == true); |
|
|
|
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
SelectBookExs.Clear(); |
|
|
|
foreach (BookEx item in bookExs) |
|
|
|
{ |
|
|
|
builder.Append(item.BookN.Name + ","); |
|
|
|
SelectBookExs.Add((BookEx)item); |
|
|
|
} |
|
|
|
SelectedText = builder == null ? string.Empty : builder.ToString(); |
|
|
|
RefreshLog(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region Command |
|
|
|