123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.DataCenter;
- using OpenSEMI.ClientBase.ServiceProvider;
- using VirgoUI.Client.Models.History.ProcessHistory;
- namespace VirgoUI.Client.Models.Operate.RealTime
- {
- public class RealtimeProvider : IProvider
- {
- //private static RealtimeProvider _Instance = null;
- //public static RealtimeProvider Instance
- //{
- // get
- // {
- // if (_Instance == null)
- // _Instance = new RealtimeProvider();
- // return _Instance;
- // }
- //}
- ObservableCollection<ParameterNode> _rootNode = new ObservableCollection<ParameterNode>();
- Dictionary<string, ParameterNode> _indexer = new Dictionary<string, ParameterNode>();
- public void Create()
- {
- }
-
- public ObservableCollection<ParameterNode> GetParameters()
- {
- try
- {
- List<string> dataList = (List<string>)QueryDataClient.Instance.Service.GetConfig("System.NumericDataList");
- dataList.Sort();
- List<string> removeList = _indexer.Keys.ToList();
- foreach (string dataName in dataList)
- {
- string[] nodeName = dataName.Split('.');
- ParameterNode parentNode = null;
- string pathName="";
- for (int i = 0; i < nodeName.Length; i++)
- {
- pathName = (i == 0) ? nodeName[i] : (pathName + "." + nodeName[i]);
- removeList.Remove(pathName);
- if (!_indexer.ContainsKey(pathName))
- {
- _indexer[pathName] = new ParameterNode() {Name = pathName, ChildNodes = new ObservableCollection<ParameterNode>(), ParentNode = parentNode};
- if (parentNode == null)
- {
- _rootNode.Add(_indexer[pathName]);
- }
- else
- {
- parentNode.ChildNodes.Add(_indexer[pathName]);
- }
- }
- parentNode = _indexer[pathName];
- removeList.Remove(pathName);
- }
- }
- foreach (var key in removeList)
- {
- if (_indexer[key].ParentNode == null)
- _rootNode.Remove(_indexer[key]);
- else
- {
- _indexer[key].ParentNode.ChildNodes.Remove(_indexer[key]);
- }
- }
- return _rootNode;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
-
- #region Test code
- ObservableCollection<ParameterNode> result = new ObservableCollection<ParameterNode>();
- ParameterNode node1 = new ParameterNode() { Name = "Para Node 1", Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
- ParameterNode node2 = new ParameterNode() { Name = "Para Node 2", Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
- ParameterNode node3 = new ParameterNode() { Name = "Para Node 3", Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
- for (int i = 0; i < 5; i++)
- {
- ParameterNode node = new ParameterNode() { Name = node1.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
- node1.ChildNodes.Add(node);
- }
- for (int i = 0; i < 3; i++)
- {
- ParameterNode node = new ParameterNode() { Name = node2.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
- node2.ChildNodes.Add(node);
- }
- for (int i = 0; i < 4; i++)
- {
- ParameterNode node = new ParameterNode() { Name = node3.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
- node3.ChildNodes.Add(node);
- }
- result.Add(node1);
- result.Add(node2);
- result.Add(node3);
- return result;
- #endregion
- }
- }
- }
|