RealtimeProvider.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using Aitex.Core.RT.Log;
  6. using MECF.Framework.Common.DataCenter;
  7. using OpenSEMI.ClientBase.ServiceProvider;
  8. using VirgoUI.Client.Models.History.ProcessHistory;
  9. namespace VirgoUI.Client.Models.Operate.RealTime
  10. {
  11. public class RealtimeProvider : IProvider
  12. {
  13. //private static RealtimeProvider _Instance = null;
  14. //public static RealtimeProvider Instance
  15. //{
  16. // get
  17. // {
  18. // if (_Instance == null)
  19. // _Instance = new RealtimeProvider();
  20. // return _Instance;
  21. // }
  22. //}
  23. ObservableCollection<ParameterNode> _rootNode = new ObservableCollection<ParameterNode>();
  24. Dictionary<string, ParameterNode> _indexer = new Dictionary<string, ParameterNode>();
  25. public void Create()
  26. {
  27. }
  28. public ObservableCollection<ParameterNode> GetParameters()
  29. {
  30. try
  31. {
  32. List<string> dataList = (List<string>)QueryDataClient.Instance.Service.GetConfig("System.NumericDataList");
  33. dataList.Sort();
  34. List<string> removeList = _indexer.Keys.ToList();
  35. foreach (string dataName in dataList)
  36. {
  37. string[] nodeName = dataName.Split('.');
  38. ParameterNode parentNode = null;
  39. string pathName="";
  40. for (int i = 0; i < nodeName.Length; i++)
  41. {
  42. pathName = (i == 0) ? nodeName[i] : (pathName + "." + nodeName[i]);
  43. removeList.Remove(pathName);
  44. if (!_indexer.ContainsKey(pathName))
  45. {
  46. _indexer[pathName] = new ParameterNode() {Name = pathName, ChildNodes = new ObservableCollection<ParameterNode>(), ParentNode = parentNode};
  47. if (parentNode == null)
  48. {
  49. _rootNode.Add(_indexer[pathName]);
  50. }
  51. else
  52. {
  53. parentNode.ChildNodes.Add(_indexer[pathName]);
  54. }
  55. }
  56. parentNode = _indexer[pathName];
  57. removeList.Remove(pathName);
  58. }
  59. }
  60. foreach (var key in removeList)
  61. {
  62. if (_indexer[key].ParentNode == null)
  63. _rootNode.Remove(_indexer[key]);
  64. else
  65. {
  66. _indexer[key].ParentNode.ChildNodes.Remove(_indexer[key]);
  67. }
  68. }
  69. return _rootNode;
  70. }
  71. catch (Exception ex)
  72. {
  73. LOG.Write(ex);
  74. }
  75. #region Test code
  76. ObservableCollection<ParameterNode> result = new ObservableCollection<ParameterNode>();
  77. ParameterNode node1 = new ParameterNode() { Name = "Para Node 1", Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
  78. ParameterNode node2 = new ParameterNode() { Name = "Para Node 2", Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
  79. ParameterNode node3 = new ParameterNode() { Name = "Para Node 3", Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
  80. for (int i = 0; i < 5; i++)
  81. {
  82. ParameterNode node = new ParameterNode() { Name = node1.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
  83. node1.ChildNodes.Add(node);
  84. }
  85. for (int i = 0; i < 3; i++)
  86. {
  87. ParameterNode node = new ParameterNode() { Name = node2.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
  88. node2.ChildNodes.Add(node);
  89. }
  90. for (int i = 0; i < 4; i++)
  91. {
  92. ParameterNode node = new ParameterNode() { Name = node3.Name + "_" + i.ToString(), Selected = false, ChildNodes = new ObservableCollection<ParameterNode>() };
  93. node3.ChildNodes.Add(node);
  94. }
  95. result.Add(node1);
  96. result.Add(node2);
  97. result.Add(node3);
  98. return result;
  99. #endregion
  100. }
  101. }
  102. }