Пример #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
            //------------------------------------------------------------
            FeedSynchronizationRelatedInformation value = obj as FeedSynchronizationRelatedInformation;

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

                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");
            }
        }
Пример #2
0
        /// <summary>
        /// Saves the current <see cref="FeedSynchronizationRelatedInformation"/> 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");

            //------------------------------------------------------------
            //	Create extension instance to retrieve XML namespace
            //------------------------------------------------------------
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();

            //------------------------------------------------------------
            //	Write XML representation of the current instance
            //------------------------------------------------------------
            writer.WriteStartElement("related", extension.XmlNamespace);

            writer.WriteAttributeString("link", extension.XmlNamespace, this.Link != null ? this.Link.ToString() : String.Empty);
            if (!String.IsNullOrEmpty(this.Title))
            {
                writer.WriteAttributeString("title", extension.XmlNamespace, this.Title);
            }
            writer.WriteAttributeString("type", extension.XmlNamespace, FeedSynchronizationRelatedInformation.RelationTypeAsString(this.RelationType));

            writer.WriteEndElement();
        }
Пример #3
0
        /// <summary>
        /// Loads this <see cref="FeedSynchronizationSharingInformation"/> 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="FeedSynchronizationSharingInformation"/> 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="FeedSynchronizationSharingInformation"/>.
        /// </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");
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();
            XmlNamespaceManager manager = extension.CreateNamespaceManager(source);

            if (source.HasAttributes)
            {
                string sinceAttribute   = source.GetAttribute("since", String.Empty);
                string untilAttribute   = source.GetAttribute("until", String.Empty);
                string expiresAttribute = source.GetAttribute("expires", String.Empty);

                if (!String.IsNullOrEmpty(sinceAttribute))
                {
                    this.Since = sinceAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(untilAttribute))
                {
                    this.Until = untilAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(expiresAttribute))
                {
                    DateTime expiresOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(expiresAttribute, out expiresOn))
                    {
                        this.ExpiresOn = expiresOn;
                        wasLoaded      = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator relatedIterator = source.Select("sx:related", manager);

                if (relatedIterator != null && relatedIterator.Count > 0)
                {
                    while (relatedIterator.MoveNext())
                    {
                        FeedSynchronizationRelatedInformation relation = new FeedSynchronizationRelatedInformation();
                        if (relation.Load(relatedIterator.Current))
                        {
                            this.Relations.Add(relation);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }
Пример #4
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="FeedSynchronizationRelatedInformation"/> 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="FeedSynchronizationRelatedInformation"/> 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="FeedSynchronizationRelatedInformation"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string linkAttribute  = source.GetAttribute("link", String.Empty);
                string titleAttribute = source.GetAttribute("title", String.Empty);
                string typeAttribute  = source.GetAttribute("type", String.Empty);

                if (!String.IsNullOrEmpty(linkAttribute))
                {
                    Uri link;
                    if (Uri.TryCreate(linkAttribute, UriKind.Absolute, out link))
                    {
                        this.Link = link;
                        wasLoaded = true;
                    }
                }

                if (!String.IsNullOrEmpty(titleAttribute))
                {
                    this.Title = titleAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    FeedSynchronizationRelatedInformationType type = FeedSynchronizationRelatedInformation.RelationTypeByName(typeAttribute);
                    if (type != FeedSynchronizationRelatedInformationType.None)
                    {
                        this.RelationType = type;
                        wasLoaded         = true;
                    }
                }
            }

            return(wasLoaded);
        }
Пример #5
0
        /// <summary>
        /// Saves the current <see cref="FeedSynchronizationRelatedInformation"/> 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");
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();

            writer.WriteStartElement("related", extension.XmlNamespace);

            writer.WriteAttributeString("link", extension.XmlNamespace, this.Link != null ? this.Link.ToString() : String.Empty);
            if (!String.IsNullOrEmpty(this.Title))
            {
                writer.WriteAttributeString("title", extension.XmlNamespace, this.Title);
            }
            writer.WriteAttributeString("type", extension.XmlNamespace, FeedSynchronizationRelatedInformation.RelationTypeAsString(this.RelationType));

            writer.WriteEndElement();
        }
Пример #6
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);
            }
            FeedSynchronizationRelatedInformation value = obj as FeedSynchronizationRelatedInformation;

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

                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>
        /// Loads this <see cref="FeedSynchronizationSharingInformation"/> 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="FeedSynchronizationSharingInformation"/> 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="FeedSynchronizationSharingInformation"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

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

            //------------------------------------------------------------
            //	Create namespace manager to resolve prefixed elements
            //------------------------------------------------------------
            FeedSynchronizationSyndicationExtension extension   = new FeedSynchronizationSyndicationExtension();
            XmlNamespaceManager manager                         = extension.CreateNamespaceManager(source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string sinceAttribute   = source.GetAttribute("since", String.Empty);
                string untilAttribute   = source.GetAttribute("until", String.Empty);
                string expiresAttribute = source.GetAttribute("expires", String.Empty);

                if (!String.IsNullOrEmpty(sinceAttribute))
                {
                    this.Since  = sinceAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(untilAttribute))
                {
                    this.Until  = untilAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(expiresAttribute))
                {
                    DateTime expiresOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(expiresAttribute, out expiresOn))
                    {
                        this.ExpiresOn  = expiresOn;
                        wasLoaded       = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator relatedIterator   = source.Select("sx:related", manager);

                if (relatedIterator != null && relatedIterator.Count > 0)
                {
                    while (relatedIterator.MoveNext())
                    {
                        FeedSynchronizationRelatedInformation relation = new FeedSynchronizationRelatedInformation();
                        if (relation.Load(relatedIterator.Current))
                        {
                            this.Relations.Add(relation);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            return wasLoaded;
        }