CSpecialGrayRangeParam.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using OTSDataType;
  2. using OTSModelSharp;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Xml;
  10. namespace OTSMeasureApp._0_OTSModel.OTSDataType
  11. {
  12. public class CSpecialGrayRange:ISlo
  13. {
  14. public CIntRange range=new CIntRange();
  15. public CIntRange diameterRange = new CIntRange();
  16. public bool ifCollectXray;
  17. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  18. {
  19. xInt xStart = new xInt();
  20. xInt xEnd = new xInt();
  21. xInt xdiaStart = new xInt();
  22. xInt xdiaEnd = new xInt();
  23. xBool xIfXray = new xBool();
  24. Slo slo = new Slo();
  25. slo.Register("start", xStart);
  26. slo.Register("end", xEnd);
  27. slo.Register("diameterStart", xdiaStart);
  28. slo.Register("diameterEnd", xdiaEnd);
  29. slo.Register("collectXray", xIfXray);
  30. if (isStoring)
  31. {
  32. xStart.AssignValue(range.GetStart());
  33. xEnd.AssignValue(range.GetEnd());
  34. xdiaStart.AssignValue(diameterRange.GetStart());
  35. xdiaEnd.AssignValue(diameterRange.GetEnd());
  36. xIfXray.AssignValue(ifCollectXray);
  37. slo.Serialize(true, classDoc, rootNode);
  38. }
  39. else
  40. {
  41. slo.Serialize(false, classDoc, rootNode);
  42. range.SetStart(xStart.value());
  43. range.SetEnd(xEnd.value());
  44. diameterRange.SetStart(xdiaStart.value());
  45. diameterRange.SetEnd(xdiaEnd.value());
  46. ifCollectXray = xIfXray.value();
  47. }
  48. }
  49. }
  50. public class CSpecialGrayRangeParam: ISlo
  51. {
  52. const string STRSPECIALGRAYCONFIGFILE = "SpecialGrayConfig.xml";
  53. private List<CSpecialGrayRange> Ranges=new List<CSpecialGrayRange>();
  54. private bool isToRun=false;
  55. private bool isInited=false;
  56. public CSpecialGrayRangeParam()
  57. {
  58. }
  59. public static string GetParamFileFullName()
  60. {
  61. String path = ".\\" + DataPublic.STR_COFIGPATH + "\\" + DataPublic.STR_SYSTEM_DATA + "\\" + STRSPECIALGRAYCONFIGFILE;
  62. return path;
  63. }
  64. public bool GetIsToRun()
  65. {
  66. if (isInited == false)
  67. {
  68. LoadParam();
  69. isInited = true;
  70. }
  71. return isToRun;
  72. }
  73. public void SetIsToRun(bool value)
  74. {
  75. isToRun = value;
  76. }
  77. public bool IsInited { get => isInited; set => isInited = value; }
  78. public List<CSpecialGrayRange> GetSpecialGreyRanges()
  79. {
  80. if (isInited == false)
  81. {
  82. LoadParam();
  83. isInited = true;
  84. }
  85. return Ranges;
  86. }
  87. public void SetSpecailGrayRanges(List<CSpecialGrayRange> value)
  88. {
  89. Ranges = value;
  90. }
  91. public override void Serialize(bool isStoring, XmlDocument classDoc, XmlNode rootNode)
  92. {
  93. Collection<CSpecialGrayRange> xRangelist = new Collection<CSpecialGrayRange>();
  94. xBool xtoRun = new xBool();
  95. Slo slo = new Slo();
  96. slo.Register("ToRun", xtoRun);
  97. slo.Register("GrayRangeList", xRangelist);
  98. if (isStoring)
  99. {
  100. xtoRun.AssignValue(isToRun);
  101. for (int i = 0; i < Ranges.Count; i++)
  102. {
  103. xRangelist.addItem(Ranges[i]);
  104. }
  105. slo.Serialize(true, classDoc, rootNode);
  106. }
  107. else
  108. {
  109. slo.Serialize(false, classDoc, rootNode);
  110. isToRun = xtoRun.value();
  111. Ranges.Clear();
  112. for (int i = 0; i < xRangelist.size(); i++)
  113. {
  114. Ranges.Add(xRangelist.getItem(i));
  115. }
  116. }
  117. }
  118. public bool LoadParam()
  119. {
  120. String path = ".\\" + DataPublic.STR_COFIGPATH + "\\" + DataPublic.STR_SYSTEM_DATA + "\\"+ STRSPECIALGRAYCONFIGFILE;
  121. // 5. check if the stage file exist
  122. if (File.Exists(path))
  123. {// the stage file exist
  124. XmlDocument doc = new XmlDocument();
  125. //载入xml文件
  126. doc.Load(path);
  127. XmlNode root = doc.SelectSingleNode("XMLData");
  128. Serialize(false, doc, root);
  129. isInited = true;
  130. return true;
  131. }
  132. return false;
  133. }
  134. }
  135. }