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 _rootNode = new ObservableCollection(); Dictionary _indexer = new Dictionary(); public void Create() { } public ObservableCollection GetParameters() { try { List dataList = (List)QueryDataClient.Instance.Service.GetConfig("System.NumericDataList"); dataList.Sort(); List 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(), 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 result = new ObservableCollection(); ParameterNode node1 = new ParameterNode() { Name = "Para Node 1", Selected = false, ChildNodes = new ObservableCollection() }; ParameterNode node2 = new ParameterNode() { Name = "Para Node 2", Selected = false, ChildNodes = new ObservableCollection() }; ParameterNode node3 = new ParameterNode() { Name = "Para Node 3", Selected = false, ChildNodes = new ObservableCollection() }; for (int i = 0; i < 5; i++) { ParameterNode node = new ParameterNode() { Name = node1.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection() }; 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() }; 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() }; node3.ChildNodes.Add(node); } result.Add(node1); result.Add(node2); result.Add(node3); return result; #endregion } } }