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
{
///
/// Endby condition define
///
[Serializable]
[DataContract]
public enum EndByCondition
{
///
/// Reactor temperature greate than
///
[EnumMember]
PmTempGt,
///
/// Reactor temperature less than
///
[EnumMember]
PmTempLt,
///
/// Reactor A zone temperature greate than
///
[EnumMember]
AZoneTempGt,
///
/// Reactor A zone temperature less than
///
[EnumMember]
AZoneTempLt,
///
/// Reactor B zone temperature greate than
///
[EnumMember]
BZoneTempGt,
///
/// Reactor B zone temperature less than
///
[EnumMember]
BZoneTempLt,
///
/// Reactor C zone temperature greate than
///
[EnumMember]
CZoneTempGt,
///
/// Reactor C zone temperature less than
///
[EnumMember]
CZoneTempLt,
///
/// Reactor D zone temperature greate than
///
[EnumMember]
DZoneTempGt,
///
/// Reactor D zone temperature less than
///
[EnumMember]
DZoneTempLt,
///
/// Reactor pressure greate than
///
[EnumMember]
PmPresGt,
///
/// Reactorpressure less than
///
[EnumMember]
PmPresLt,
///
/// TC value great than
///
[EnumMember]
TcGt,
///
/// TC value less than
///
[EnumMember]
TcLt,
///
/// spindle speed great than
///
[EnumMember]
RpmGt,
///
/// spindle speed less than
///
[EnumMember]
RpmLt,
}
public class CustomXmlSerializer
{
static public void Serialize(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)
{
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(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(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(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(fileReader);
}
}
}