示例#1
0
        /// <summary>
        /// Opens a previous application feed and populates default information from it.
        /// </summary>
        /// <param name="feedUrl">Url to feed.</param>
        public void OpenPrevious(Uri feedUrl)
        {
            string localFeedPath = null;
            bool   download      = false;

            if (feedUrl.Scheme == Uri.UriSchemeHttp || feedUrl.Scheme == Uri.UriSchemeHttps)
            {
                localFeedPath = Path.GetTempFileName();
                download      = true;
            }
            else if (feedUrl.Scheme == Uri.UriSchemeFile)
            {
                localFeedPath = feedUrl.LocalPath;
            }
            else
            {
                throw new ArgumentException("Only http:, https:, and file: protocols are supported.", "feedUrl");
            }

            if (download)
            {
                this.DownloadUrl(feedUrl, localFeedPath);
            }

            this.previousFeed    = new XmlDocument();
            this.previousAppItem = null;

            XmlNamespaceManager namespaces = new XmlNamespaceManager(this.previousFeed.NameTable);

            namespaces.AddNamespace("as", "http://appsyndication.org/schemas/appsyn");

            this.previousFeed.Load(localFeedPath);

            // Get the application id, if there isn't one this isn't a valid application feed.
            XmlNode node = this.previousFeed.SelectSingleNode("rss/channel/as:application", namespaces);

            if (node == null)
            {
                throw new ApplicationException("Did not open a valid Application Feed");
            }

            this.feedId = new Guid(node.InnerText);

            // Get the title and description from the previous feed, if present.
            node = this.previousFeed.SelectSingleNode("rss/channel/title");
            if (node != null)
            {
                this.title = node.InnerText;
            }

            node = this.previousFeed.SelectSingleNode("rss/channel/description");
            if (node != null)
            {
                this.description = node.InnerText;
            }

            // Find the previous app.
            XmlNodeList items = this.previousFeed.SelectNodes("rss/channel/item");

            foreach (XmlNode item in items)
            {
                // Get the application's version from the feed.  If there is
                // no version, then this isn't an application feed.
                node = item.SelectSingleNode("as:version", namespaces);
                if (node == null)
                {
                    continue;
                }

                // If this item's application version isn't higher, skip proccessing it.
                Version appVersion = new Version(node.InnerText);
                if (this.previousAppItem != null && appVersion < this.previousAppItem.Version)
                {
                    continue;
                }

                // Get the URL to the application.  If there is no URL, then this
                // isn't a valid application feed.
                node = item.SelectSingleNode("enclosure/@url");
                if (node == null)
                {
                    continue;
                }

                this.previousAppItem         = new ApplicationFeedItem();
                this.previousAppItem.Version = appVersion;
                try
                {
                    this.previousAppItem.Url = new Uri(node.Value);
                }
                catch (UriFormatException)
                {
                    this.previousAppItem.Url = new Uri(feedUrl, node.Value);
                }

                // Get the optional application id, if there is one.
                node = item.SelectSingleNode("as:application", namespaces);
                if (node != null)
                {
                    this.previousAppItem.Id = node.InnerText;
                }
            }
        }
示例#2
0
文件: FeedBuilder.cs 项目: zooba/wix3
        /// <summary>
        /// Opens a previous application feed and populates default information from it.
        /// </summary>
        /// <param name="feedUrl">Url to feed.</param>
        public void OpenPrevious(Uri feedUrl)
        {
            string localFeedPath = null;
            bool download = false;
            if (feedUrl.Scheme == Uri.UriSchemeHttp || feedUrl.Scheme == Uri.UriSchemeHttps)
            {
                localFeedPath = Path.GetTempFileName();
                download = true;
            }
            else if (feedUrl.Scheme == Uri.UriSchemeFile)
            {
                localFeedPath = feedUrl.LocalPath;
            }
            else
            {
                throw new ArgumentException("Only http:, https:, and file: protocols are supported.", "feedUrl");
            }

            if (download)
            {
                this.DownloadUrl(feedUrl, localFeedPath);
            }

            this.previousFeed = new XmlDocument();
            this.previousAppItem = null;

            XmlNamespaceManager namespaces = new XmlNamespaceManager(this.previousFeed.NameTable);
            namespaces.AddNamespace("as", "http://appsyndication.org/schemas/appsyn");

            this.previousFeed.Load(localFeedPath);

            // Get the application id, if there isn't one this isn't a valid application feed.
            XmlNode node = this.previousFeed.SelectSingleNode("rss/channel/as:application", namespaces);
            if (node == null)
            {
                throw new ApplicationException("Did not open a valid Application Feed");
            }

            this.feedId = new Guid(node.InnerText);

            // Get the title and description from the previous feed, if present.
            node = this.previousFeed.SelectSingleNode("rss/channel/title");
            if (node != null)
            {
                this.title = node.InnerText;
            }

            node = this.previousFeed.SelectSingleNode("rss/channel/description");
            if (node != null)
            {
                this.description = node.InnerText;
            }

            // Find the previous app.
            XmlNodeList items = this.previousFeed.SelectNodes("rss/channel/item");
            foreach (XmlNode item in items)
            {
                // Get the application's version from the feed.  If there is
                // no version, then this isn't an application feed.
                node = item.SelectSingleNode("as:version", namespaces);
                if (node == null)
                {
                    continue;
                }

                // If this item's application version isn't higher, skip proccessing it.
                Version appVersion = new Version(node.InnerText);
                if (this.previousAppItem != null && appVersion < this.previousAppItem.Version)
                {
                    continue;
                }

                // Get the URL to the application.  If there is no URL, then this
                // isn't a valid application feed.
                node = item.SelectSingleNode("enclosure/@url");
                if (node == null)
                {
                    continue;
                }

                this.previousAppItem = new ApplicationFeedItem();
                this.previousAppItem.Version = appVersion;
                try
                {
                    this.previousAppItem.Url = new Uri(node.Value);
                }
                catch (UriFormatException)
                {
                    this.previousAppItem.Url = new Uri(feedUrl, node.Value);
                }

                // Get the optional application id, if there is one.
                node = item.SelectSingleNode("as:application", namespaces);
                if (node != null)
                {
                    this.previousAppItem.Id = node.InnerText;
                }
            }
        }