/// <summary>
        /// Loads this <see cref="FeedHistoryLinkRelation"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="FeedHistoryLinkRelation"/> 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="FeedHistoryLinkRelation"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            if (source.HasAttributes)
            {
                string hrefAttribute = source.GetAttribute("href", String.Empty);
                string relAttribute  = source.GetAttribute("rel", String.Empty);

                if (!String.IsNullOrEmpty(hrefAttribute))
                {
                    Uri href;
                    if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href))
                    {
                        this.Uri  = href;
                        wasLoaded = true;
                    }
                }

                if (!String.IsNullOrEmpty(relAttribute))
                {
                    FeedHistoryLinkRelationType relationType = FeedHistorySyndicationExtension.LinkRelationTypeByName(relAttribute);
                    if (relationType != FeedHistoryLinkRelationType.None)
                    {
                        this.RelationType = relationType;
                        wasLoaded         = true;
                    }
                }
            }

            return(wasLoaded);
        }
Пример #2
0
        /// <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);
            }
            FeedHistorySyndicationExtension value = obj as FeedHistorySyndicationExtension;

            if (value != null)
            {
                int result = String.Compare(this.Description, value.Description, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Documentation, value.Documentation, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase);
                result = result | this.Version.CompareTo(value.Version);
                result = result | String.Compare(this.XmlNamespace, value.XmlNamespace, StringComparison.Ordinal);
                result = result | String.Compare(this.XmlPrefix, value.XmlPrefix, StringComparison.Ordinal);

                result = result | this.Context.IsArchive.CompareTo(value.Context.IsArchive);
                result = result | this.Context.IsComplete.CompareTo(value.Context.IsComplete);
                result = result | FeedHistorySyndicationExtension.CompareSequence(this.Context.Relations, value.Context.Relations);

                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");
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="FeedHistorySyndicationExtensionContext"/>.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param>
        /// <returns><b>true</b> if the <see cref="FeedHistorySyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns>
        /// <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>
        public bool Load(XPathNavigator source, XmlNamespaceManager manager)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            if (String.IsNullOrEmpty(manager.LookupNamespace("atom")))
            {
                manager.AddNamespace("atom", "http://www.w3.org/2005/Atom");
            }
            if (source.HasChildren)
            {
                XPathNavigator    archiveNavigator  = source.SelectSingleNode("fh:archive", manager);
                XPathNavigator    completeNavigator = source.SelectSingleNode("fh:complete", manager);
                XPathNodeIterator linkIterator      = source.Select("atom:link", manager);

                if (archiveNavigator != null)
                {
                    this.IsArchive = true;
                    wasLoaded      = true;
                }

                if (completeNavigator != null)
                {
                    this.IsComplete = true;
                    wasLoaded       = true;
                }

                if (linkIterator != null && linkIterator.Count > 0)
                {
                    while (linkIterator.MoveNext())
                    {
                        string relAttribute = linkIterator.Current.GetAttribute("rel", String.Empty);

                        if (!String.IsNullOrEmpty(relAttribute) && FeedHistorySyndicationExtension.LinkRelationTypeByName(relAttribute) != FeedHistoryLinkRelationType.None)
                        {
                            FeedHistoryLinkRelation relation = new FeedHistoryLinkRelation();
                            if (relation.Load(linkIterator.Current))
                            {
                                this.Relations.Add(relation);
                                wasLoaded = true;
                            }
                        }
                    }
                }
            }

            return(wasLoaded);
        }
        /// <summary>
        /// Saves the current <see cref="FeedHistoryLinkRelation"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            writer.WriteStartElement("link", "http://www.w3.org/2005/Atom");

            writer.WriteAttributeString("href", this.Uri != null ? this.Uri.ToString() : String.Empty);
            writer.WriteAttributeString("rel", this.RelationType != FeedHistoryLinkRelationType.None ? FeedHistorySyndicationExtension.LinkRelationTypeAsString(this.RelationType) : String.Empty);

            writer.WriteEndElement();
        }
Пример #5
0
        /// <summary>
        /// Saves the current <see cref="FeedHistoryLinkRelation"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");

            //------------------------------------------------------------
            //	Write XML representation of the current instance
            //------------------------------------------------------------
            writer.WriteStartElement("link", "http://www.w3.org/2005/Atom");

            writer.WriteAttributeString("href", this.Uri != null ? this.Uri.ToString() : String.Empty);
            writer.WriteAttributeString("rel", this.RelationType != FeedHistoryLinkRelationType.None ? FeedHistorySyndicationExtension.LinkRelationTypeAsString(this.RelationType) : String.Empty);

            writer.WriteEndElement();
        }