2 using System.Collections.Generic;
9 namespace AppLimit.NetSparkle
11 public class NetSparkleAppCast
13 private NetSparkleConfiguration _config;
14 private String _castUrl;
16 private const String itemNode = "item";
17 private const String descriptionNode = "description";
18 private const String enclosureNode = "enclosure";
19 private const String releaseNotesLinkNode = "sparkle:releaseNotesLink";
20 private const String versionAttribute = "sparkle:version";
21 private const String dasSignature = "sparkle:dsaSignature";
22 private const String urlAttribute = "url";
24 public NetSparkleAppCast(String castUrl, NetSparkleConfiguration config)
30 public NetSparkleAppCastItem GetLatestVersion()
32 NetSparkleAppCastItem latestVersion = null;
34 // build a http web request stream
35 WebRequest request = HttpWebRequest.Create(_castUrl);
37 // request the cast and build the stream
38 WebResponse response = request.GetResponse();
40 Stream inputstream = response.GetResponseStream();
42 NetSparkleAppCastItem currentItem = null;
44 XmlTextReader reader = new XmlTextReader(inputstream);
47 if ( reader.NodeType == XmlNodeType.Element)
53 currentItem = new NetSparkleAppCastItem();
59 if (currentItem != null)
61 currentItem.Summary = reader.ReadElementContentAsString();
66 case releaseNotesLinkNode:
68 currentItem.ReleaseNotesLink = reader.ReadString();
69 currentItem.ReleaseNotesLink = currentItem.ReleaseNotesLink.Trim('\n');
74 currentItem.Version = reader.GetAttribute(versionAttribute);
76 var downloadLink = reader.GetAttribute(urlAttribute);
77 downloadLink = Environment.Is64BitOperatingSystem
78 ? downloadLink.Replace(".x86.", ".x64.")
79 : downloadLink.Replace(".x64.", ".x86.") ;
80 currentItem.DownloadLink = downloadLink;
81 currentItem.DSASignature = reader.GetAttribute(dasSignature);
87 else if (reader.NodeType == XmlNodeType.EndElement)
93 if (latestVersion == null)
94 latestVersion = currentItem;
95 else if (currentItem.CompareTo(latestVersion) > 0 )
97 latestVersion = currentItem;
105 // add some other attributes
106 latestVersion.AppName = _config.ApplicationName;
107 latestVersion.AppVersionInstalled = _config.InstalledVersion;
110 return latestVersion;