using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
namespace ProjectBase.Data.Update
{
///
/// 文件清单对象
///
[XmlRoot("manifest")]
public class Manifest
{
[XmlElement("version")]
public string Version { get; set; }
[XmlElement("description")]
public string Description { get; set; }
[XmlElement("ftpname")]
public string FtpName { get; set; }
[XmlElement("ftppsswd")]
public string FtpPsswd { get; set; }
[XmlElement("fileBytes")]
public long FileBytes { get; set; }
[XmlElement("myapplication")]
public MyApplication MyApplication { get; set; }
[XmlElement("files")]
public ManifestFiles ManifestFiles { get; set; }
[XmlArray("excludes")]
[XmlArrayItem("exclude", typeof(MyExclude))]
public List ExcludeList { get; set; }
}
///
/// 更新的文件列表
///
public class ManifestFiles
{
[XmlElement("file")]
public ManifestFile[] Files { get; set; }
[XmlAttribute("base")]
public string BaseUrl { get; set; }
}
///
/// 更新的单个文件对象
///
public class ManifestFile
{
[XmlAttribute("source")]
public string Source
{
get;
set;
}
[XmlAttribute("hash")]
public string Hash
{
get;
set;
}
[XmlAttribute("unzip")]
public string Unzip
{
get;
set;
}
}
///
/// 更新的程序对象
///
public class MyApplication
{
[XmlAttribute("applicationId")]
public string ApplicationId { get; set; }
[XmlElement("entryPoint")]
public EntryPoint EntryPoint { get; set; }
[XmlElement("location")]
public string Location { get; set; }
[XmlElement("expand")]
public string Expand { get; set; }
}
///
/// 排除更新的文件扩展名
///
public class MyExclude
{
[XmlAttribute("name")]
public string Exclude { get; set; }
}
///
/// 程序启动对象
///
public class EntryPoint
{
[XmlAttribute("file")]
public string File { get; set; }
[XmlAttribute("parameters")]
public string Parameters { get; set; }
}
///
/// 客户端配置文件对象
///
public class UpdaterConfigurationView
{
private static XmlDocument document = new XmlDocument();
private static readonly string xmlFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../updateconfiguration.config");
static UpdaterConfigurationView()
{
document.Load(xmlFileName);
}
///
/// 刷新配置文件信息
///
public void Refresh()
{
document.RemoveAll();
document.Load(xmlFileName);
}
///
/// 程序版本
///
public string Version
{
get
{
return document.SelectSingleNode("applicationUpdater").Attributes["version"].Value;
}
set
{
document.SelectSingleNode("applicationUpdater").Attributes["version"].Value = value;
document.Save(xmlFileName);
}
}
///
/// 应用程序唯一标识
///
public string ApplicationId
{
get
{
return document.SelectSingleNode("applicationUpdater").Attributes["applicationId"].Value;
}
set
{
document.SelectSingleNode("applicationUpdater").Attributes["applicationId"].Value = value;
document.Save(xmlFileName);
}
}
///
/// 远程更新文件的清单路径
///
public string ManifestUri
{
get
{
return document.SelectSingleNode("applicationUpdater").Attributes["manifestUri"].Value;
}
set
{
document.SelectSingleNode("applicationUpdater").Attributes["manifestUri"].Value = value;
document.Save(xmlFileName);
}
}
///
/// 远程用户名
///
public string ManifestName
{
get
{
return document.SelectSingleNode("applicationUpdater").Attributes["manifestName"].Value;
}
set
{
document.SelectSingleNode("applicationUpdater").Attributes["manifestName"].Value = value;
document.Save(xmlFileName);
}
}
///
/// 远程密码
///
public string ManifestPasswd
{
get
{
return document.SelectSingleNode("applicationUpdater").Attributes["manifestPasswd"].Value;
}
set
{
document.SelectSingleNode("applicationUpdater").Attributes["manifestPasswd"].Value = value;
document.Save(xmlFileName);
}
}
///
/// 程序名称
///
public string Title
{
get
{
return document.SelectSingleNode("applicationUpdater").Attributes["title"].Value;
}
set
{
document.SelectSingleNode("applicationUpdater").Attributes["title"].Value = value;
document.Save(xmlFileName);
}
}
}
}