终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

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