Esempio n. 1
0
        /// <summary>
        /// Loads the optional elements of this <see cref="RssChannel"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="RssChannel"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="RssChannel"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        private bool LoadOptionals(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator cloudNavigator           = source.SelectSingleNode("cloud", manager);
            XPathNavigator copyrightNavigator       = source.SelectSingleNode("copyright", manager);
            XPathNavigator generatorNavigator       = source.SelectSingleNode("generator", manager);
            XPathNavigator imageNavigator           = source.SelectSingleNode("image", manager);
            XPathNavigator languageNavigator        = source.SelectSingleNode("language", manager);
            XPathNavigator lastBuildDateNavigator   = source.SelectSingleNode("lastBuildDate", manager);
            XPathNavigator managingEditorNavigator  = source.SelectSingleNode("managingEditor", manager);
            XPathNavigator publicationNavigator     = source.SelectSingleNode("pubDate", manager);
            XPathNavigator ratingNavigator          = source.SelectSingleNode("rating", manager);
            XPathNavigator textInputNavigator       = source.SelectSingleNode("textInput", manager);
            XPathNavigator timeToLiveNavigator      = source.SelectSingleNode("ttl", manager);
            XPathNavigator webMasterNavigator       = source.SelectSingleNode("webMaster", manager);

            if (cloudNavigator != null)
            {
                RssCloud cloud  = new RssCloud();
                if (cloud.Load(cloudNavigator, settings))
                {
                    this.Cloud      = cloud;
                    wasLoaded       = true;
                }
            }

            if (copyrightNavigator != null)
            {
                this.Copyright      = copyrightNavigator.Value;
                wasLoaded           = true;
            }

            if (generatorNavigator != null)
            {
                this.Generator      = generatorNavigator.Value;
                wasLoaded           = true;
            }

            if (imageNavigator != null)
            {
                RssImage image  = new RssImage();
                if (image.Load(imageNavigator, settings))
                {
                    this.Image      = image;
                    wasLoaded       = true;
                }
            }

            if (languageNavigator != null && !String.IsNullOrEmpty(languageNavigator.Value))
            {
                try
                {
                    CultureInfo language    = new CultureInfo(languageNavigator.Value);
                    this.Language           = language;
                    wasLoaded               = true;
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Trace.TraceWarning("RssChannel unable to determine CultureInfo with a name of {0}.", languageNavigator.Value);
                }
            }

            if (lastBuildDateNavigator != null)
            {
                DateTime lastBuildDate;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(lastBuildDateNavigator.Value, out lastBuildDate))
                {
                    this.LastBuildDate  = lastBuildDate;
                    wasLoaded           = true;
                }
            }

            if (managingEditorNavigator != null)
            {
                this.ManagingEditor     = managingEditorNavigator.Value;
                wasLoaded               = true;
            }

            if (publicationNavigator != null)
            {
                DateTime publicationDate;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate))
                {
                    this.PublicationDate    = publicationDate;
                    wasLoaded               = true;
                }
            }

            if (ratingNavigator != null)
            {
                this.Rating             = ratingNavigator.Value;
                wasLoaded               = true;
            }

            if (textInputNavigator != null)
            {
                RssTextInput textInput = new RssTextInput();
                if (textInput.Load(textInputNavigator, settings))
                {
                    this.TextInput      = textInput;
                    wasLoaded           = true;
                }
            }

            if (timeToLiveNavigator != null)
            {
                int timeToLive;
                if (Int32.TryParse(timeToLiveNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out timeToLive))
                {
                    this.TimeToLive     = timeToLive;
                    wasLoaded           = true;
                }
            }

            if (webMasterNavigator != null)
            {
                this.Webmaster          = webMasterNavigator.Value;
                wasLoaded               = true;
            }

            return wasLoaded;
        }