终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

99 righe
3.4 KiB

  1. using BPASmartClient.Helper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Collections.ObjectModel;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using BPASmartClient.Model;
  10. using System.Windows.Media;
  11. namespace BPASmartClient.CustomResource.Pages.Model
  12. {
  13. public class MessageLog
  14. {
  15. private volatile static MessageLog _Instance;
  16. public static MessageLog GetInstance => _Instance ??= new MessageLog();
  17. public static readonly object runLock = new object();
  18. public static readonly object userlock = new object();
  19. public static readonly object alarmlock = new object();
  20. private MessageLog() { }
  21. public Action<string> UserLog { get; set; }
  22. public Action<string> RunLog { get; set; }
  23. public Action<string> AlarmLog { get; set; }
  24. public ObservableCollection<RunLog> runLogs { get; set; } = new ObservableCollection<RunLog>();
  25. public ObservableCollection<UserLog> userLogs { get; set; } = new ObservableCollection<UserLog>();
  26. public ObservableCollection<Alarm> alarmLogs { get; set; } = new ObservableCollection<Alarm>();
  27. public void LogSave()
  28. {
  29. Sqlite<UserLog>.GetInstance.Save();
  30. Sqlite<RunLog>.GetInstance.Save();
  31. Sqlite<Alarm>.GetInstance.Save();
  32. }
  33. public void ShowUserLog(string info)
  34. {
  35. lock (userlock)
  36. {
  37. UserLog userLog = new UserLog()
  38. {
  39. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  40. Time = DateTime.Now.ToString("HH:mm:ss"),
  41. Permission = Global.userInfo.permission.ToString(),
  42. UserName = Global.userInfo.UserName,
  43. LogInfo = info
  44. };
  45. Sqlite<UserLog>.GetInstance.Base.Add(userLog);
  46. Application.Current.Dispatcher.Invoke(new Action(() => { userLogs.Insert(0, userLog); }));
  47. UserLog?.Invoke(info);
  48. }
  49. }
  50. public void ShowRunLog(string info)
  51. {
  52. lock (runLock)
  53. {
  54. RunLog runLog = new RunLog()
  55. {
  56. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  57. Time = DateTime.Now.ToString("HH:mm:ss"),
  58. RunLogInfo = info
  59. };
  60. Sqlite<RunLog>.GetInstance.Base.Add(runLog);
  61. Application.Current.Dispatcher.Invoke(new Action(() => { runLogs.Insert(0, runLog); }));
  62. RunLog?.Invoke(info);
  63. }
  64. }
  65. int AlarmID;
  66. public void ShowAlarmLog(string info, string AlarmNumber = "_", AlarmLevel level = AlarmLevel.一般报警)
  67. {
  68. lock (alarmlock)
  69. {
  70. AlarmID++;
  71. Alarm alarmLog = new Alarm()
  72. {
  73. NumId = AlarmID,
  74. Date = DateTime.Now.ToString("yyyy-MM-dd"),
  75. Time = DateTime.Now.ToString("HH:mm:ss"),
  76. Info = info,
  77. Value = AlarmNumber,
  78. Grade = (level) + ""
  79. };
  80. Sqlite<Alarm>.GetInstance.Base.Add(alarmLog);
  81. Application.Current.Dispatcher.Invoke(new Action(() => { alarmLogs.Insert(0, alarmLog); }));
  82. AlarmLog?.Invoke(info);
  83. }
  84. }
  85. }
  86. }