219 lines
5.7 KiB
C#
219 lines
5.7 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 升级配置信息。
|
|
/// </summary>
|
|
[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<SmartFile> files;
|
|
|
|
/// <summary>
|
|
/// 初始化SmartConfig对象实例。
|
|
/// </summary>
|
|
public SmartConfig()
|
|
{
|
|
this.files = new List<SmartFile>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// URL地址。
|
|
/// </summary>
|
|
[DataMember]
|
|
public string URI
|
|
{
|
|
get
|
|
{
|
|
return this.url;
|
|
}
|
|
set
|
|
{
|
|
this.url = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 名称。
|
|
/// </summary>
|
|
[DataMember]
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return this.name;
|
|
}
|
|
set
|
|
{
|
|
this.name = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 说明。
|
|
/// </summary>
|
|
[DataMember]
|
|
public string Description
|
|
{
|
|
get
|
|
{
|
|
return this.description;
|
|
}
|
|
set
|
|
{
|
|
this.description = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下载完后执行。
|
|
/// </summary>
|
|
[DataMember]
|
|
public string StartEx
|
|
{
|
|
get
|
|
{
|
|
return this.startEx;
|
|
}
|
|
set
|
|
{
|
|
this.startEx = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 最后更新时间。
|
|
/// </summary>
|
|
[DataMember]
|
|
public DateTime Time
|
|
{
|
|
get
|
|
{
|
|
return this.time;
|
|
}
|
|
set
|
|
{
|
|
this.time = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 系统运行必须的一些文件。
|
|
/// </summary>
|
|
[XmlArray()]
|
|
[XmlArrayItem(typeof(SmartFile))]
|
|
[DataMember]
|
|
public List<SmartFile> Files
|
|
{
|
|
get
|
|
{
|
|
if (this.files == null)
|
|
{
|
|
this.files = new List<SmartFile>();
|
|
}
|
|
|
|
return this.files;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 装载智能升级配置。
|
|
/// </summary>
|
|
/// <param name="xml">xml。</param>
|
|
/// <returns>智能升级配置。</returns>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 转换为XML字符串。
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存智能升级配置信息到
|
|
/// </summary>
|
|
/// <param name="config">智能升级配置。</param>
|
|
/// <param name="file">文件名。</param>
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 装载智能升级配置。
|
|
/// </summary>
|
|
/// <param name="file">文件名。</param>
|
|
/// <returns>智能升级配置。</returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 系统默认配置文件。
|
|
/// </summary>
|
|
public static string DefaultConfgiFile
|
|
{
|
|
get
|
|
{
|
|
return "SmartUpdate.xml";
|
|
}
|
|
}
|
|
}
|
|
}
|