Esempio n. 1
0
        //============================================================
        //	ICOMPARABLE IMPLEMENTATION
        //============================================================
        #region CompareTo(object obj)
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            //------------------------------------------------------------
            //	If target is a null reference, instance is greater
            //------------------------------------------------------------
            if (obj == null)
            {
                return(1);
            }

            //------------------------------------------------------------
            //	Determine comparison result using property state of objects
            //------------------------------------------------------------
            RssTextInput value = obj as RssTextInput;

            if (value != null)
            {
                int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Link, value.Link, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Title, value.Title, StringComparison.OrdinalIgnoreCase);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            RssTextInput value = obj as RssTextInput;

            if (value != null)
            {
                int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Link, value.Link, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Title, value.Title, StringComparison.OrdinalIgnoreCase);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
Esempio n. 3
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;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssTextInput"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="textInput">The <see cref="RssTextInput"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the text input XML data.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="textInput"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> 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>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillTextInput(RssTextInput textInput, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(textInput, "textInput");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract text input information
            //------------------------------------------------------------
            XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager);
            XPathNavigator linkNavigator        = navigator.SelectSingleNode("link", manager);
            XPathNavigator nameNavigator        = navigator.SelectSingleNode("name", manager);
            XPathNavigator titleNavigator       = navigator.SelectSingleNode("title", manager);

            if (descriptionNavigator != null)
            {
                if (!String.IsNullOrEmpty(descriptionNavigator.Value))
                {
                    textInput.Description   = descriptionNavigator.Value;
                }
            }
            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    textInput.Link          = link;
                }
            }
            if (nameNavigator != null)
            {
                if (!String.IsNullOrEmpty(nameNavigator.Value))
                {
                    textInput.Name          = nameNavigator.Value;
                }
            }
            if (titleNavigator != null)
            {
                if (!String.IsNullOrEmpty(titleNavigator.Value))
                {
                    textInput.Title         = titleNavigator.Value;
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(textInput);
        }