|
- using BPASmart.Model;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BeDesignerSCADA.ViewModel
- {
- public class DataBusModel
- {
- #region 单例模式
- public static DataBusModel dataBus = null;
-
- public static DataBusModel GetInstance()
- {
- if (dataBus == null)
- {
- dataBus = new DataBusModel();
- }
- return dataBus;
- }
- #endregion
-
- #region 变量
- /// <summary>
- /// 变量地址保存
- /// key:地址
- /// value:变量
- /// </summary>
- private ConcurrentDictionary<string, CommunicationPar> _KeyValues { get; set; } = new ConcurrentDictionary<string, CommunicationPar>();
- public ConcurrentDictionary<string, CommunicationPar> KeyValues
- {
- get
- {
- return _KeyValues;
- }
- set
- {
- _KeyValues = value;
-
- }
- }
- #endregion
- /// <summary>
- /// 刷新界面管理器
- /// </summary>
- /// <param name="path"></param>
- public bool RefreshVariableManager(string path="")
- {
- bool IsSucess=false;
- try
- {
- if (File.Exists(path))
- {
- CommunicationPar val = JsonConvert.DeserializeObject<CommunicationPar>(File.ReadAllText(path));
- if (val != null)
- {
- if (KeyValues == null)
- {
- KeyValues = new ConcurrentDictionary<string, CommunicationPar>();
- }
- KeyValues[path] = val;
- IsSucess = true;
- }
- }
- }
- catch (Exception ex)
- {
-
- }
- return IsSucess;
- }
-
- }
- }
|