Exemplo 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
            //------------------------------------------------------------
            ApmlAuthor value = obj as ApmlAuthor;

            if (value != null)
            {
                int result = String.Compare(this.From, value.From, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Key, value.Key, StringComparison.OrdinalIgnoreCase);
                result = result | this.UpdatedOn.CompareTo(value.UpdatedOn);
                result = result | this.Value.CompareTo(value.Value);

                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);
            }
            ApmlAuthor value = obj as ApmlAuthor;

            if (value != null)
            {
                int result = String.Compare(this.From, value.From, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Key, value.Key, StringComparison.OrdinalIgnoreCase);
                result = result | this.UpdatedOn.CompareTo(value.UpdatedOn);
                result = result | this.Value.CompareTo(value.Value);

                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");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads this <see cref="ApmlSource"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="ApmlSource"/> 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="ApmlSource"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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>
        public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string keyAttribute     = source.GetAttribute("key", String.Empty);
                string nameAttribute    = source.GetAttribute("name", String.Empty);
                string valueAttribute   = source.GetAttribute("value", String.Empty);
                string typeAttribute    = source.GetAttribute("type", String.Empty);
                string fromAttribute    = source.GetAttribute("from", String.Empty);
                string updatedAttribute = source.GetAttribute("updated", String.Empty);

                if (!String.IsNullOrEmpty(keyAttribute))
                {
                    this.Key  = keyAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name = nameAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(valueAttribute))
                {
                    decimal value;
                    if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value))
                    {
                        if (value >= Decimal.MinusOne && value <= Decimal.One)
                        {
                            this.Value = value;
                            wasLoaded  = true;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    this.MimeType = typeAttribute;
                    wasLoaded     = true;
                }

                if (!String.IsNullOrEmpty(fromAttribute))
                {
                    this.From = fromAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(updatedAttribute))
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn))
                    {
                        this.UpdatedOn = updatedOn;
                        wasLoaded      = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator authorIterator = source.Select("apml:Author", manager);

                if (authorIterator != null && authorIterator.Count > 0)
                {
                    while (authorIterator.MoveNext())
                    {
                        ApmlAuthor author = new ApmlAuthor();
                        if (author.Load(authorIterator.Current, settings))
                        {
                            this.Authors.Add(author);
                            wasLoaded = true;
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);

            adapter.Fill(this);

            return(wasLoaded);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads this <see cref="ApmlSource"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="ApmlSource"/> 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="ApmlSource"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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>
        public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

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

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string keyAttribute     = source.GetAttribute("key", String.Empty);
                string nameAttribute    = source.GetAttribute("name", String.Empty);
                string valueAttribute   = source.GetAttribute("value", String.Empty);
                string typeAttribute    = source.GetAttribute("type", String.Empty);
                string fromAttribute    = source.GetAttribute("from", String.Empty);
                string updatedAttribute = source.GetAttribute("updated", String.Empty);

                if (!String.IsNullOrEmpty(keyAttribute))
                {
                    this.Key    = keyAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name   = nameAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(valueAttribute))
                {
                    decimal value;
                    if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value))
                    {
                        if (value >= Decimal.MinusOne && value <= Decimal.One)
                        {
                            this.Value  = value;
                            wasLoaded   = true;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    this.MimeType   = typeAttribute;
                    wasLoaded       = true;
                }

                if (!String.IsNullOrEmpty(fromAttribute))
                {
                    this.From   = fromAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(updatedAttribute))
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn))
                    {
                        this.UpdatedOn  = updatedOn;
                        wasLoaded       = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator authorIterator    = source.Select("apml:Author", manager);

                if (authorIterator != null && authorIterator.Count > 0)
                {
                    while (authorIterator.MoveNext())
                    {
                        ApmlAuthor author = new ApmlAuthor();
                        if (author.Load(authorIterator.Current, settings))
                        {
                            this.Authors.Add(author);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads this <see cref="ApmlSource"/> 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="ApmlSource"/> 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="ApmlSource"/>.
        /// </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");
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            if (source.HasAttributes)
            {
                string keyAttribute     = source.GetAttribute("key", String.Empty);
                string nameAttribute    = source.GetAttribute("name", String.Empty);
                string valueAttribute   = source.GetAttribute("value", String.Empty);
                string typeAttribute    = source.GetAttribute("type", String.Empty);
                string fromAttribute    = source.GetAttribute("from", String.Empty);
                string updatedAttribute = source.GetAttribute("updated", String.Empty);

                if (!String.IsNullOrEmpty(keyAttribute))
                {
                    this.Key  = keyAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name = nameAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(valueAttribute))
                {
                    decimal value;
                    if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value))
                    {
                        if (value >= Decimal.MinusOne && value <= Decimal.One)
                        {
                            this.Value = value;
                            wasLoaded  = true;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    this.MimeType = typeAttribute;
                    wasLoaded     = true;
                }

                if (!String.IsNullOrEmpty(fromAttribute))
                {
                    this.From = fromAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(updatedAttribute))
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn))
                    {
                        this.UpdatedOn = updatedOn;
                        wasLoaded      = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator authorIterator = source.Select("apml:Author", manager);

                if (authorIterator != null && authorIterator.Count > 0)
                {
                    while (authorIterator.MoveNext())
                    {
                        ApmlAuthor author = new ApmlAuthor();
                        if (author.Load(authorIterator.Current))
                        {
                            this.Authors.Add(author);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }