using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Xml.Serialization; using System.Collections; using System.IO; using System.Runtime.Serialization; namespace EAS.Distributed { /// /// 升级配置信息。 /// [Serializable] [DataContract] public class SmartConfig { string url = "http://www.smarteas.net/"; string name = "AgileEAS.NET SOA平台升级配置文件"; string description = "用于AgileEAS.NET SOA平台SmartClient/ActiveX运行容器模块升级之用"; string startEx = ""; DateTime time = DateTime.Now; List files; /// /// 初始化SmartConfig对象实例。 /// public SmartConfig() { this.files = new List(); } /// /// URL地址。 /// [DataMember] public string URI { get { return this.url; } set { this.url = value; } } /// /// 名称。 /// [DataMember] public string Name { get { return this.name; } set { this.name = value; } } /// /// 说明。 /// [DataMember] public string Description { get { return this.description; } set { this.description = value; } } /// /// 下载完后执行。 /// [DataMember] public string StartEx { get { return this.startEx; } set { this.startEx = value; } } /// /// 最后更新时间。 /// [DataMember] public DateTime Time { get { return this.time; } set { this.time = value; } } /// /// 系统运行必须的一些文件。 /// [XmlArray()] [XmlArrayItem(typeof(SmartFile))] [DataMember] public List Files { get { if (this.files == null) { this.files = new List(); } return this.files; } } /// /// 装载智能升级配置。 /// /// xml。 /// 智能升级配置。 public static SmartConfig LoadXML(string xml) { using (System.IO.TextReader writer = new System.IO.StringReader(xml)) { System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SmartConfig)); return (SmartConfig)xmlSerializer.Deserialize(writer); } } /// /// 转换为XML字符串。 /// /// public override string ToString() { StringBuilder sb = new StringBuilder(); using (System.IO.TextWriter writer = new System.IO.StringWriter(sb)) { System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SmartConfig)); xmlSerializer.Serialize(writer, this); writer.Close(); } return sb.ToString(); } /// /// 保存智能升级配置信息到 /// /// 智能升级配置。 /// 文件名。 public static void Save(SmartConfig config, string file) { if (File.Exists(file)) { File.Delete(file); } using (System.IO.StreamWriter writer = new System.IO.StreamWriter(file)) { System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SmartConfig)); xmlSerializer.Serialize(writer, config); writer.Close(); } } /// /// 装载智能升级配置。 /// /// 文件名。 /// 智能升级配置。 public static SmartConfig Load(string file) { if (!System.IO.File.Exists(file)) { return new SmartConfig(); } using (System.IO.StreamReader reader = new System.IO.StreamReader(file)) { System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SmartConfig)); SmartConfig smartAssemblyList = xmlSerializer.Deserialize(reader) as SmartConfig; reader.Close(); return smartAssemblyList; } } /// /// 系统默认配置文件。 /// public static string DefaultConfgiFile { get { return "SmartUpdate.xml"; } } } }