123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.Serialization;
- using System.IO;
- using System.Xml;
- using System.Xml.Serialization;
- namespace Aitex.UI.RecipeEditor.Core
- {
- /// <summary>
- /// Endby condition define
- /// </summary>
- [Serializable]
- [DataContract]
- public enum EndByCondition
- {
- /// <summary>
- /// Reactor temperature greate than
- /// </summary>
- [EnumMember]
- PmTempGt,
- /// <summary>
- /// Reactor temperature less than
- /// </summary>
- [EnumMember]
- PmTempLt,
- /// <summary>
- /// Reactor A zone temperature greate than
- /// </summary>
- [EnumMember]
- AZoneTempGt,
- /// <summary>
- /// Reactor A zone temperature less than
- /// </summary>
- [EnumMember]
- AZoneTempLt,
- /// <summary>
- /// Reactor B zone temperature greate than
- /// </summary>
- [EnumMember]
- BZoneTempGt,
- /// <summary>
- /// Reactor B zone temperature less than
- /// </summary>
- [EnumMember]
- BZoneTempLt,
- /// <summary>
- /// Reactor C zone temperature greate than
- /// </summary>
- [EnumMember]
- CZoneTempGt,
- /// <summary>
- /// Reactor C zone temperature less than
- /// </summary>
- [EnumMember]
- CZoneTempLt,
- /// <summary>
- /// Reactor D zone temperature greate than
- /// </summary>
- [EnumMember]
- DZoneTempGt,
- /// <summary>
- /// Reactor D zone temperature less than
- /// </summary>
- [EnumMember]
- DZoneTempLt,
- /// <summary>
- /// Reactor pressure greate than
- /// </summary>
- [EnumMember]
- PmPresGt,
- /// <summary>
- /// Reactorpressure less than
- /// </summary>
- [EnumMember]
- PmPresLt,
- /// <summary>
- /// TC value great than
- /// </summary>
- [EnumMember]
- TcGt,
- /// <summary>
- /// TC value less than
- /// </summary>
- [EnumMember]
- TcLt,
- /// <summary>
- /// spindle speed great than
- /// </summary>
- [EnumMember]
- RpmGt,
- /// <summary>
- /// spindle speed less than
- /// </summary>
- [EnumMember]
- RpmLt,
- }
- public class CustomXmlSerializer
- {
- static public void Serialize<T>(T t, string fileName)
- {
- using (FileStream fileWriter = new FileStream(fileName, FileMode.Create))
- using (XmlWriter writer = XmlTextWriter.Create(fileWriter))
- {
- XmlSerializer serializer = new XmlSerializer(t.GetType());
- serializer.Serialize(writer, t);
- writer.Flush();
- }
- }
- static public string Serialize<T>(T t)
- {
- StringBuilder buffer = new StringBuilder();
- using (StringWriter writer = new StringWriter(buffer))
- {
- XmlSerializer serializer = new XmlSerializer(typeof(T));
- serializer.Serialize(writer, t);
- }
- return buffer.ToString();
- }
- static public T Deserialize<T>(string xmlString)
- {
- if (string.IsNullOrWhiteSpace(xmlString))
- throw new ArgumentNullException("xmlString");
- using (StringReader reader = new StringReader(xmlString))
- {
- XmlSerializer serializer = new XmlSerializer(typeof(T));
- return (T)serializer.Deserialize(reader);
- }
- }
- static public T Deserialize<T>(Stream streamReader)
- {
- if (streamReader == null)
- throw new ArgumentNullException("streamReader");
- if (streamReader.Length <= 0)
- throw new EndOfStreamException("The stream is blank");
- using (XmlReader reader = XmlTextReader.Create(streamReader))
- {
- XmlSerializer deserializer = new XmlSerializer(typeof(T));
- return (T)deserializer.Deserialize(reader);
- }
- }
- static public T Deserialize<T>(FileInfo fi)
- {
- if (fi == null)
- throw new ArgumentNullException("fi");
- if (!fi.Exists)
- throw new FileNotFoundException(fi.FullName);
- using (FileStream fileReader = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read))
- return Deserialize<T>(fileReader);
- }
- }
- }
|