Model.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. using System.Xml.Serialization;
  9. namespace ProjectBase.Data.Update
  10. {
  11. /// <summary>
  12. /// 文件清单对象
  13. /// </summary>
  14. [XmlRoot("manifest")]
  15. public class Manifest
  16. {
  17. [XmlElement("version")]
  18. public string Version { get; set; }
  19. [XmlElement("description")]
  20. public string Description { get; set; }
  21. [XmlElement("ftpname")]
  22. public string FtpName { get; set; }
  23. [XmlElement("ftppsswd")]
  24. public string FtpPsswd { get; set; }
  25. [XmlElement("fileBytes")]
  26. public long FileBytes { get; set; }
  27. [XmlElement("myapplication")]
  28. public MyApplication MyApplication { get; set; }
  29. [XmlElement("files")]
  30. public ManifestFiles ManifestFiles { get; set; }
  31. [XmlArray("excludes")]
  32. [XmlArrayItem("exclude", typeof(MyExclude))]
  33. public List<MyExclude> ExcludeList { get; set; }
  34. }
  35. /// <summary>
  36. /// 更新的文件列表
  37. /// </summary>
  38. public class ManifestFiles
  39. {
  40. [XmlElement("file")]
  41. public ManifestFile[] Files { get; set; }
  42. [XmlAttribute("base")]
  43. public string BaseUrl { get; set; }
  44. }
  45. /// <summary>
  46. /// 更新的单个文件对象
  47. /// </summary>
  48. public class ManifestFile
  49. {
  50. [XmlAttribute("source")]
  51. public string Source
  52. {
  53. get;
  54. set;
  55. }
  56. [XmlAttribute("hash")]
  57. public string Hash
  58. {
  59. get;
  60. set;
  61. }
  62. [XmlAttribute("unzip")]
  63. public string Unzip
  64. {
  65. get;
  66. set;
  67. }
  68. }
  69. /// <summary>
  70. /// 更新的程序对象
  71. /// </summary>
  72. public class MyApplication
  73. {
  74. [XmlAttribute("applicationId")]
  75. public string ApplicationId { get; set; }
  76. [XmlElement("entryPoint")]
  77. public EntryPoint EntryPoint { get; set; }
  78. [XmlElement("location")]
  79. public string Location { get; set; }
  80. [XmlElement("expand")]
  81. public string Expand { get; set; }
  82. }
  83. /// <summary>
  84. /// 排除更新的文件扩展名
  85. /// </summary>
  86. public class MyExclude
  87. {
  88. [XmlAttribute("name")]
  89. public string Exclude { get; set; }
  90. }
  91. /// <summary>
  92. /// 程序启动对象
  93. /// </summary>
  94. public class EntryPoint
  95. {
  96. [XmlAttribute("file")]
  97. public string File { get; set; }
  98. [XmlAttribute("parameters")]
  99. public string Parameters { get; set; }
  100. }
  101. /// <summary>
  102. /// 客户端配置文件对象
  103. /// </summary>
  104. public class UpdaterConfigurationView
  105. {
  106. private static XmlDocument document = new XmlDocument();
  107. private static readonly string xmlFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../updateconfiguration.config");
  108. static UpdaterConfigurationView()
  109. {
  110. document.Load(xmlFileName);
  111. }
  112. /// <summary>
  113. /// 刷新配置文件信息
  114. /// </summary>
  115. public void Refresh()
  116. {
  117. document.RemoveAll();
  118. document.Load(xmlFileName);
  119. }
  120. /// <summary>
  121. /// 程序版本
  122. /// </summary>
  123. public string Version
  124. {
  125. get
  126. {
  127. return document.SelectSingleNode("applicationUpdater").Attributes["version"].Value;
  128. }
  129. set
  130. {
  131. document.SelectSingleNode("applicationUpdater").Attributes["version"].Value = value;
  132. document.Save(xmlFileName);
  133. }
  134. }
  135. /// <summary>
  136. /// 应用程序唯一标识
  137. /// </summary>
  138. public string ApplicationId
  139. {
  140. get
  141. {
  142. return document.SelectSingleNode("applicationUpdater").Attributes["applicationId"].Value;
  143. }
  144. set
  145. {
  146. document.SelectSingleNode("applicationUpdater").Attributes["applicationId"].Value = value;
  147. document.Save(xmlFileName);
  148. }
  149. }
  150. /// <summary>
  151. /// 远程更新文件的清单路径
  152. /// </summary>
  153. public string ManifestUri
  154. {
  155. get
  156. {
  157. return document.SelectSingleNode("applicationUpdater").Attributes["manifestUri"].Value;
  158. }
  159. set
  160. {
  161. document.SelectSingleNode("applicationUpdater").Attributes["manifestUri"].Value = value;
  162. document.Save(xmlFileName);
  163. }
  164. }
  165. /// <summary>
  166. /// 远程用户名
  167. /// </summary>
  168. public string ManifestName
  169. {
  170. get
  171. {
  172. return document.SelectSingleNode("applicationUpdater").Attributes["manifestName"].Value;
  173. }
  174. set
  175. {
  176. document.SelectSingleNode("applicationUpdater").Attributes["manifestName"].Value = value;
  177. document.Save(xmlFileName);
  178. }
  179. }
  180. /// <summary>
  181. /// 远程密码
  182. /// </summary>
  183. public string ManifestPasswd
  184. {
  185. get
  186. {
  187. return document.SelectSingleNode("applicationUpdater").Attributes["manifestPasswd"].Value;
  188. }
  189. set
  190. {
  191. document.SelectSingleNode("applicationUpdater").Attributes["manifestPasswd"].Value = value;
  192. document.Save(xmlFileName);
  193. }
  194. }
  195. /// <summary>
  196. /// 程序名称
  197. /// </summary>
  198. public string Title
  199. {
  200. get
  201. {
  202. return document.SelectSingleNode("applicationUpdater").Attributes["title"].Value;
  203. }
  204. set
  205. {
  206. document.SelectSingleNode("applicationUpdater").Attributes["title"].Value = value;
  207. document.Save(xmlFileName);
  208. }
  209. }
  210. }
  211. }