|
- using BPASmartClient.Helper;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Collections.ObjectModel;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using BPASmartClient.Model;
-
- namespace BPASmartClient.CustomResource.Pages.Model
- {
- public class MessageLog
- {
- private volatile static MessageLog _Instance;
- public static MessageLog GetInstance => _Instance ??= new MessageLog();
-
- public static readonly object runLock = new object();
- public static readonly object userlock = new object();
- public static readonly object alarmlock = new object();
- private MessageLog() { }
-
- public Action<string> UserLog { get; set; }
-
- public Action<string> RunLog { get; set; }
-
- public Action<string> AlarmLog { get; set; }
-
- public ObservableCollection<RunLog> runLogs { get; set; } = new ObservableCollection<RunLog>();
-
- public ObservableCollection<UserLog> userLogs { get; set; } = new ObservableCollection<UserLog>();
-
- public ObservableCollection<Alarm> alarmLogs { get; set; } = new ObservableCollection<Alarm>();
-
- public void LogSave()
- {
- Sqlite<UserLog>.GetInstance.Save();
- Sqlite<RunLog>.GetInstance.Save();
- Sqlite<Alarm>.GetInstance.Save();
- }
-
- public void ShowUserLog(string info)
- {
- lock (userlock)
- {
- UserLog userLog = new UserLog()
- {
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Time = DateTime.Now.ToString("HH:mm:ss"),
- Permission = Global.userInfo.permission.ToString(),
- UserName = Global.userInfo.UserName,
- LogInfo = info
- };
- Sqlite<UserLog>.GetInstance.Base.Add(userLog);
- Application.Current.Dispatcher.Invoke(new Action(() => { userLogs.Insert(0, userLog); }));
- UserLog?.Invoke(info);
- }
- }
-
- public void ShowRunLog(string info)
- {
- lock (runLock)
- {
- RunLog runLog = new RunLog()
- {
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Time = DateTime.Now.ToString("HH:mm:ss"),
- RunLogInfo = info
- };
- Sqlite<RunLog>.GetInstance.Base.Add(runLog);
- Application.Current.Dispatcher.Invoke(new Action(() => { runLogs.Insert(0, runLog); }));
- RunLog?.Invoke(info);
- }
- }
- int AlarmID;
- public void ShowAlarmLog(string info, string AlarmNumber="_", AlarmLevel level= AlarmLevel.一般报警)
- {
- lock (alarmlock)
- {
- AlarmID++;
- Alarm alarmLog = new Alarm()
- {
- NumId = AlarmID,
- Date = DateTime.Now.ToString("yyyy-MM-dd"),
- Time = DateTime.Now.ToString("HH:mm:ss"),
- Info = info,
- Value = AlarmNumber,
- Grade = (level)+""
- };
- Sqlite<Alarm>.GetInstance.Base.Add(alarmLog);
- Application.Current.Dispatcher.Invoke(new Action(() => { alarmLogs.Insert(0, alarmLog); }));
- AlarmLog?.Invoke(info);
- }
- }
- }
- }
|