终端一体化运控平台
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.
 
 
 

80 rivejä
2.0 KiB

  1. using BPASmart.Model;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Concurrent;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace BeDesignerSCADA.ViewModel
  11. {
  12. public class DataBusModel
  13. {
  14. #region 单例模式
  15. public static DataBusModel dataBus = null;
  16. public static DataBusModel GetInstance()
  17. {
  18. if (dataBus == null)
  19. {
  20. dataBus = new DataBusModel();
  21. }
  22. return dataBus;
  23. }
  24. #endregion
  25. #region 变量
  26. /// <summary>
  27. /// 变量地址保存
  28. /// key:地址
  29. /// value:变量
  30. /// </summary>
  31. private ConcurrentDictionary<string, CommunicationPar> _KeyValues { get; set; } = new ConcurrentDictionary<string, CommunicationPar>();
  32. public ConcurrentDictionary<string, CommunicationPar> KeyValues
  33. {
  34. get
  35. {
  36. return _KeyValues;
  37. }
  38. set
  39. {
  40. _KeyValues = value;
  41. }
  42. }
  43. #endregion
  44. /// <summary>
  45. /// 刷新界面管理器
  46. /// </summary>
  47. /// <param name="path"></param>
  48. public bool RefreshVariableManager(string path="")
  49. {
  50. bool IsSucess=false;
  51. try
  52. {
  53. if (File.Exists(path))
  54. {
  55. CommunicationPar val = JsonConvert.DeserializeObject<CommunicationPar>(File.ReadAllText(path));
  56. if (val != null)
  57. {
  58. if (KeyValues == null)
  59. {
  60. KeyValues = new ConcurrentDictionary<string, CommunicationPar>();
  61. }
  62. KeyValues[path] = val;
  63. IsSucess = true;
  64. }
  65. }
  66. }
  67. catch (Exception ex)
  68. {
  69. }
  70. return IsSucess;
  71. }
  72. }
  73. }