Exemple #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
            //------------------------------------------------------------
            OpmlOwner value = obj as OpmlOwner;

            if (value != null)
            {
                int result = String.Compare(this.EmailAddress, value.EmailAddress, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Id, value.Id, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, 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");
            }
        }
Exemple #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);
            }
            OpmlOwner value = obj as OpmlOwner;

            if (value != null)
            {
                int result = String.Compare(this.EmailAddress, value.EmailAddress, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Id, value.Id, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, 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");
            }
        }
Exemple #3
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="OpmlHead"/> 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="OpmlHead"/> 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="OpmlHead"/>.
        /// </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
            //------------------------------------------------------------
            XPathNavigator titleNavigator               = source.SelectSingleNode("title");
            XPathNavigator dateCreatedNavigator         = source.SelectSingleNode("dateCreated");
            XPathNavigator dateModifiedNavigator        = source.SelectSingleNode("dateModified");
            XPathNavigator expansionStateNavigator      = source.SelectSingleNode("expansionState");
            XPathNavigator verticalScrollStateNavigator = source.SelectSingleNode("vertScrollState");

            if (titleNavigator != null)
            {
                this.Title = titleNavigator.Value;
                wasLoaded  = true;
            }

            if (dateCreatedNavigator != null)
            {
                DateTime createdOn;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(dateCreatedNavigator.Value, out createdOn))
                {
                    this.CreatedOn = createdOn;
                    wasLoaded      = true;
                }
            }

            if (dateModifiedNavigator != null)
            {
                DateTime modifiedOn;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(dateModifiedNavigator.Value, out modifiedOn))
                {
                    this.ModifiedOn = modifiedOn;
                    wasLoaded       = true;
                }
            }

            OpmlOwner owner = new OpmlOwner();

            if (owner.Load(source))
            {
                this.Owner = owner;
            }

            if (expansionStateNavigator != null && !String.IsNullOrEmpty(expansionStateNavigator.Value))
            {
                if (expansionStateNavigator.Value.Contains(","))
                {
                    string[] expansionStates = expansionStateNavigator.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    foreach (string expansionState in expansionStates)
                    {
                        int state;
                        if (Int32.TryParse(expansionState.Trim(), System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out state))
                        {
                            this.ExpansionState.Add(state);
                            wasLoaded = true;
                        }
                    }
                }
                else
                {
                    int expansionState;
                    if (Int32.TryParse(expansionStateNavigator.Value, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out expansionState))
                    {
                        this.ExpansionState.Add(expansionState);
                        wasLoaded = true;
                    }
                }
            }

            if (verticalScrollStateNavigator != null)
            {
                int verticalScrollState;
                if (Int32.TryParse(verticalScrollStateNavigator.Value, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out verticalScrollState))
                {
                    this.VerticalScrollState = verticalScrollState;
                    wasLoaded = true;
                }
            }

            OpmlWindow window = new OpmlWindow();

            if (window.Load(source))
            {
                this.Window = window;
            }

            return(wasLoaded);
        }