Gloabals.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.Serialization;
  6. using System.IO;
  7. using System.Xml;
  8. using System.Xml.Serialization;
  9. namespace Aitex.UI.RecipeEditor.Core
  10. {
  11. /// <summary>
  12. /// Endby condition define
  13. /// </summary>
  14. [Serializable]
  15. [DataContract]
  16. public enum EndByCondition
  17. {
  18. /// <summary>
  19. /// Reactor temperature greate than
  20. /// </summary>
  21. [EnumMember]
  22. PmTempGt,
  23. /// <summary>
  24. /// Reactor temperature less than
  25. /// </summary>
  26. [EnumMember]
  27. PmTempLt,
  28. /// <summary>
  29. /// Reactor A zone temperature greate than
  30. /// </summary>
  31. [EnumMember]
  32. AZoneTempGt,
  33. /// <summary>
  34. /// Reactor A zone temperature less than
  35. /// </summary>
  36. [EnumMember]
  37. AZoneTempLt,
  38. /// <summary>
  39. /// Reactor B zone temperature greate than
  40. /// </summary>
  41. [EnumMember]
  42. BZoneTempGt,
  43. /// <summary>
  44. /// Reactor B zone temperature less than
  45. /// </summary>
  46. [EnumMember]
  47. BZoneTempLt,
  48. /// <summary>
  49. /// Reactor C zone temperature greate than
  50. /// </summary>
  51. [EnumMember]
  52. CZoneTempGt,
  53. /// <summary>
  54. /// Reactor C zone temperature less than
  55. /// </summary>
  56. [EnumMember]
  57. CZoneTempLt,
  58. /// <summary>
  59. /// Reactor D zone temperature greate than
  60. /// </summary>
  61. [EnumMember]
  62. DZoneTempGt,
  63. /// <summary>
  64. /// Reactor D zone temperature less than
  65. /// </summary>
  66. [EnumMember]
  67. DZoneTempLt,
  68. /// <summary>
  69. /// Reactor pressure greate than
  70. /// </summary>
  71. [EnumMember]
  72. PmPresGt,
  73. /// <summary>
  74. /// Reactorpressure less than
  75. /// </summary>
  76. [EnumMember]
  77. PmPresLt,
  78. /// <summary>
  79. /// TC value great than
  80. /// </summary>
  81. [EnumMember]
  82. TcGt,
  83. /// <summary>
  84. /// TC value less than
  85. /// </summary>
  86. [EnumMember]
  87. TcLt,
  88. /// <summary>
  89. /// spindle speed great than
  90. /// </summary>
  91. [EnumMember]
  92. RpmGt,
  93. /// <summary>
  94. /// spindle speed less than
  95. /// </summary>
  96. [EnumMember]
  97. RpmLt,
  98. }
  99. public class CustomXmlSerializer
  100. {
  101. static public void Serialize<T>(T t, string fileName)
  102. {
  103. using (FileStream fileWriter = new FileStream(fileName, FileMode.Create))
  104. using (XmlWriter writer = XmlTextWriter.Create(fileWriter))
  105. {
  106. XmlSerializer serializer = new XmlSerializer(t.GetType());
  107. serializer.Serialize(writer, t);
  108. writer.Flush();
  109. }
  110. }
  111. static public string Serialize<T>(T t)
  112. {
  113. StringBuilder buffer = new StringBuilder();
  114. using (StringWriter writer = new StringWriter(buffer))
  115. {
  116. XmlSerializer serializer = new XmlSerializer(typeof(T));
  117. serializer.Serialize(writer, t);
  118. }
  119. return buffer.ToString();
  120. }
  121. static public T Deserialize<T>(string xmlString)
  122. {
  123. if (string.IsNullOrWhiteSpace(xmlString))
  124. throw new ArgumentNullException("xmlString");
  125. using (StringReader reader = new StringReader(xmlString))
  126. {
  127. XmlSerializer serializer = new XmlSerializer(typeof(T));
  128. return (T)serializer.Deserialize(reader);
  129. }
  130. }
  131. static public T Deserialize<T>(Stream streamReader)
  132. {
  133. if (streamReader == null)
  134. throw new ArgumentNullException("streamReader");
  135. if (streamReader.Length <= 0)
  136. throw new EndOfStreamException("The stream is blank");
  137. using (XmlReader reader = XmlTextReader.Create(streamReader))
  138. {
  139. XmlSerializer deserializer = new XmlSerializer(typeof(T));
  140. return (T)deserializer.Deserialize(reader);
  141. }
  142. }
  143. static public T Deserialize<T>(FileInfo fi)
  144. {
  145. if (fi == null)
  146. throw new ArgumentNullException("fi");
  147. if (!fi.Exists)
  148. throw new FileNotFoundException(fi.FullName);
  149. using (FileStream fileReader = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read))
  150. return Deserialize<T>(fileReader);
  151. }
  152. }
  153. }