|
|
@@ -23,10 +23,10 @@ namespace BPASmartClient.ViewModel |
|
|
|
/// </summary> |
|
|
|
public class LogViewModel : ObservableObject |
|
|
|
{ |
|
|
|
#region 变量 |
|
|
|
public DispatcherTimer dispatcherTimer; |
|
|
|
public string ClientId = System.Configuration.ConfigurationManager.AppSettings["ClientId"].ToString(); |
|
|
|
private ObservableCollection<LogModel> _LogModels; |
|
|
|
public ObservableCollection<LogModel> LogDataGrid |
|
|
|
private ObservableCollection<LogModel> _LogModels;public ObservableCollection<LogModel> LogDataGrid |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
@@ -40,13 +40,53 @@ namespace BPASmartClient.ViewModel |
|
|
|
OnPropertyChanged("LogDataGrid"); |
|
|
|
} |
|
|
|
} |
|
|
|
private bool _RealTimeModel = true;public bool RealTimeModel |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _RealTimeModel; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_RealTimeModel == value) |
|
|
|
return; |
|
|
|
_RealTimeModel = value; |
|
|
|
OnPropertyChanged("RealTimeModel"); |
|
|
|
} |
|
|
|
} |
|
|
|
private bool _TimedClear = true;public bool TimedClear |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _TimedClear; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_TimedClear == value) |
|
|
|
return; |
|
|
|
_TimedClear = value; |
|
|
|
OnPropertyChanged("TimedClear"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 单一 |
|
|
|
private volatile static LogViewModel _Instance; |
|
|
|
public static LogViewModel GetInstance() => _Instance ?? (_Instance = new LogViewModel()); |
|
|
|
private LogViewModel() |
|
|
|
{ |
|
|
|
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); |
|
|
|
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>(); |
|
|
|
Init(); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 函数 |
|
|
|
/// <summary> |
|
|
|
/// 初始化 |
|
|
|
/// </summary> |
|
|
|
public void Init() |
|
|
|
{ |
|
|
|
if (LogDataGrid == null) LogDataGrid = new ObservableCollection<LogModel>(); |
|
|
|
logHelper.Fun_InitLog(System.AppDomain.CurrentDomain.BaseDirectory); |
|
|
|
//一般日志 |
|
|
|
MessageLog.GetInstance.InfoNotify = new Action<string>((s) => |
|
|
|
{ |
|
|
@@ -56,17 +96,15 @@ namespace BPASmartClient.ViewModel |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.INFO, s); |
|
|
|
})); |
|
|
|
}); |
|
|
|
|
|
|
|
//设备日志 |
|
|
|
MessageLog.GetInstance.DeviceProcessLogNotify = new Action<string, string>((id, s) => |
|
|
|
{ |
|
|
|
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => |
|
|
|
{ |
|
|
|
LogDataGrid.Insert(0, new LogModel { message = s, type = "DeviceLog" }); |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.DEBUG, 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<string, string>((id, s) => |
|
|
|
{ |
|
|
@@ -76,7 +114,6 @@ namespace BPASmartClient.ViewModel |
|
|
|
logHelper.GetLogConfigInstance().WriteLog(LogLevel.WARN, id); |
|
|
|
})); |
|
|
|
}); |
|
|
|
|
|
|
|
//错误日志 |
|
|
|
MessageLog.GetInstance.ExInfoNotify = new Action<string>((s) => |
|
|
|
{ |
|
|
@@ -106,10 +143,10 @@ namespace BPASmartClient.ViewModel |
|
|
|
if (System.Windows.MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK) |
|
|
|
{ |
|
|
|
System.Diagnostics.Process.Start("Explorer", "/select," + logHelper.GetLogConfigInstance().directRollfileAppender.File); |
|
|
|
OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File); |
|
|
|
}else |
|
|
|
logHelper.GetLogConfigInstance().OpenFile(logHelper.GetLogConfigInstance().directRollfileAppender.File); |
|
|
|
} |
|
|
|
else |
|
|
|
System.Diagnostics.Process.Start("Explorer", "/select," + logHelper.GetLogConfigInstance().directRollfileAppender.File); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
dispatcherTimer = new DispatcherTimer(); |
|
|
@@ -127,7 +164,6 @@ namespace BPASmartClient.ViewModel |
|
|
|
dispatcherTimer.Interval = TimeSpan.FromSeconds(10); |
|
|
|
dispatcherTimer.Start(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 导出数据 |
|
|
|
/// </summary> |
|
|
@@ -167,104 +203,24 @@ namespace BPASmartClient.ViewModel |
|
|
|
string msg = string.Format("记录导出完成,共导出记录{0}条,是否打开!", LogDataGrid.Count); |
|
|
|
if (System.Windows.MessageBox.Show(msg, "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK) |
|
|
|
{ |
|
|
|
OpenFile(openfile.FileName); |
|
|
|
logHelper.GetLogConfigInstance().OpenFile(openfile.FileName); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
System.Windows.MessageBox.Show("无数据!"); |
|
|
|
|
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 打开指定路径下文件,比如:Word、Excel、Dll、图片等都可以(前提是你已经安装打开程序的对应软件) |
|
|
|
/// </summary> |
|
|
|
/// <param name="NewFileName">eg:D:\Test\模版8.doc</param> |
|
|
|
/// <param name="NewFileName">eg:D:\Test\模版8.doc</param> |
|
|
|
private void OpenFile(string NewFileName) |
|
|
|
{ |
|
|
|
Process process = new Process(); |
|
|
|
ProcessStartInfo processStartInfo = new ProcessStartInfo(NewFileName); |
|
|
|
process.StartInfo = processStartInfo; |
|
|
|
#region 下面这段被注释掉代码(可以用来全屏打开代码) |
|
|
|
//建立新的系统进程 |
|
|
|
////System.Diagnostics.Process process = new System.Diagnostics.Process(); |
|
|
|
//设置文件名,此处为图片的真实路径 + 文件名(需要有后缀) |
|
|
|
////process.StartInfo.FileName = NewFileName; |
|
|
|
//此为关键部分。设置进程运行参数,此时为最大化窗口显示图片。 |
|
|
|
////process.StartInfo.Arguments = "rundll32.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen"; |
|
|
|
// 此项为是否使用Shell执行程序,因系统默认为true,此项也可不设,但若设置必须为true |
|
|
|
process.StartInfo.UseShellExecute = true; |
|
|
|
#endregion |
|
|
|
try |
|
|
|
{ |
|
|
|
process.Start(); |
|
|
|
try |
|
|
|
{ |
|
|
|
// process.WaitForExit(); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
finally |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
if (process != null) |
|
|
|
{ |
|
|
|
process.Close(); |
|
|
|
process = null; |
|
|
|
} |
|
|
|
} |
|
|
|
catch { } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private bool _RealTimeModel = true; |
|
|
|
public bool RealTimeModel |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _RealTimeModel; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_RealTimeModel == value) |
|
|
|
return; |
|
|
|
_RealTimeModel = value; |
|
|
|
OnPropertyChanged("RealTimeModel"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private bool _TimedClear = true; |
|
|
|
public bool TimedClear |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _TimedClear; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
if (_TimedClear == value) |
|
|
|
return; |
|
|
|
_TimedClear = value; |
|
|
|
OnPropertyChanged("TimedClear"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#region Command |
|
|
|
public RelayCommand ExcelCommand { get; set; } |
|
|
|
public RelayCommand OpenCommand { get; set; } |
|
|
|
#endregion |
|
|
|
} |
|
|
|
|
|
|
|
public class LogModel : ObservableObject |
|
|
|
{ |
|
|
|
public string time { get; set; } |
|
|
|
|
|
|
|
private string _type; |
|
|
|
public string type |
|
|
|
{ |
|
|
@@ -283,7 +239,6 @@ namespace BPASmartClient.ViewModel |
|
|
|
} |
|
|
|
} |
|
|
|
public string message { get; set; } |
|
|
|
|
|
|
|
private Brush _foreground; |
|
|
|
public Brush foreground |
|
|
|
{ |
|
|
|