终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using BPASmartClient.SCADAControl;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Concurrent;
  5. using System.IO;
  6. namespace BeDesignerSCADA.ViewModel
  7. {
  8. public class DataBusModel
  9. {
  10. #region 单例模式
  11. private static string path
  12. {
  13. get
  14. {
  15. Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\JSON"));
  16. return AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\CommunicationPar.json";
  17. }
  18. }
  19. public static DataBusModel dataBus = null;
  20. public static DataBusModel GetInstance()
  21. {
  22. if (dataBus == null)
  23. {
  24. dataBus = new DataBusModel();
  25. }
  26. return dataBus;
  27. }
  28. #endregion
  29. #region 变量
  30. /// <summary>
  31. /// 变量地址保存
  32. /// key:地址
  33. /// value:变量
  34. /// </summary>
  35. private ConcurrentDictionary<string, CommunicationPar> _KeyValues { get; set; } = new ConcurrentDictionary<string, CommunicationPar>();
  36. public ConcurrentDictionary<string, CommunicationPar> KeyValues
  37. {
  38. get
  39. {
  40. return _KeyValues;
  41. }
  42. set
  43. {
  44. _KeyValues = value;
  45. }
  46. }
  47. #endregion
  48. /// <summary>
  49. /// 刷新界面管理器
  50. /// </summary>
  51. /// <param name="path"></param>
  52. public bool RefreshVariableManager(string path="")
  53. {
  54. bool IsSucess=false;
  55. try
  56. {
  57. if (File.Exists(path))
  58. {
  59. CommunicationPar val = JsonConvert.DeserializeObject<CommunicationPar>(File.ReadAllText(path));
  60. if (val != null)
  61. {
  62. if (KeyValues == null)
  63. {
  64. KeyValues = new ConcurrentDictionary<string, CommunicationPar>();
  65. }
  66. KeyValues[path] = val;
  67. IsSucess = true;
  68. }
  69. }
  70. }
  71. catch (Exception ex)
  72. {
  73. }
  74. return IsSucess;
  75. }
  76. /// <summary>
  77. /// 读取文件
  78. /// </summary>
  79. /// <returns></returns>
  80. public bool ReadFile()
  81. {
  82. bool IsSucess = false;
  83. try
  84. {
  85. if (File.Exists(path))
  86. {
  87. CommunicationPar val = JsonConvert.DeserializeObject<CommunicationPar>(File.ReadAllText(path));
  88. if (val != null)
  89. {
  90. if (KeyValues == null)
  91. {
  92. KeyValues = new ConcurrentDictionary<string, CommunicationPar>();
  93. }
  94. KeyValues[path] = val;
  95. IsSucess = true;
  96. }
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. }
  102. return IsSucess ;
  103. }
  104. }
  105. }