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);
75 currentItem.DownloadLink = reader.GetAttribute(urlAttribute);
76 currentItem.DSASignature = reader.GetAttribute(dasSignature);
82 else if (reader.NodeType == XmlNodeType.EndElement)
88 if (latestVersion == null)
89 latestVersion = currentItem;
90 else if (currentItem.CompareTo(latestVersion) > 0 )
92 latestVersion = currentItem;
100 // add some other attributes
101 latestVersion.AppName = _config.ApplicationName;
102 latestVersion.AppVersionInstalled = _config.InstalledVersion;
105 return latestVersion;