|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using BPASmartClient.SCADAControl;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Concurrent;
- using System.IO;
-
- namespace BeDesignerSCADA.ViewModel
- {
- public class DataBusModel
- {
- #region 单例模式
- private static string path
- {
- get
- {
- Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\JSON"));
- return AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\JSON\\CommunicationPar.json";
- }
- }
- 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;
- }
-
- /// <summary>
- /// 读取文件
- /// </summary>
- /// <returns></returns>
- public bool ReadFile()
- {
- 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 ;
- }
-
- }
- }
|