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

            if (value != null)
            {
                int result = String.Compare(this.By, value.By, StringComparison.OrdinalIgnoreCase);
                result = result | this.Sequence.CompareTo(value.Sequence);
                result = result | this.When.CompareTo(value.When);

                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>
 /// Initializes a new instance of the <see cref="FeedSynchronizationItem"/> class using the supplied indentifier, number of updates, and initial <see cref="FeedSynchronizationHistory"/>.
 /// </summary>
 /// <param name="id">The globally unique identifier for the item.</param>
 /// <param name="updates">The number of updates applied to this item.</param>
 /// <param name="history">A <see cref="FeedSynchronizationHistory"/> object that represents the initial information about updates to this item.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="id"/> is an empty string.</exception>
 /// <exception cref="ArgumentOutOfRangeException">The <paramref name="updates"/> is less than <b>1</b>.</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="history"/> is a null reference (Nothing in Visual Basic).</exception>
 public FeedSynchronizationItem(string id, int updates, FeedSynchronizationHistory history) : this(id, updates)
 {
     //------------------------------------------------------------
     //	Initialize class state using guarded properties
     //------------------------------------------------------------
     Guard.ArgumentNotNull(history, "history");
     this.Histories.Add(history);
 }
        /// <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);
            }
            FeedSynchronizationHistory value = obj as FeedSynchronizationHistory;

            if (value != null)
            {
                int result = String.Compare(this.By, value.By, StringComparison.OrdinalIgnoreCase);
                result = result | this.Sequence.CompareTo(value.Sequence);
                result = result | this.When.CompareTo(value.When);

                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");
            }
        }
예제 #4
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="FeedSynchronizationItem"/> 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="FeedSynchronizationItem"/> 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="FeedSynchronizationItem"/>.
        /// </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 idAttribute          = source.GetAttribute("id", String.Empty);
                string updatesAttribute     = source.GetAttribute("updates", String.Empty);
                string deletedAttribute     = source.GetAttribute("deleted", String.Empty);
                string noConflictsAttribute = source.GetAttribute("noconflicts", String.Empty);

                if (!String.IsNullOrEmpty(idAttribute))
                {
                    this.Id   = idAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(updatesAttribute))
                {
                    int updates;
                    if (Int32.TryParse(updatesAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out updates))
                    {
                        this.Updates = updates;
                        wasLoaded    = true;
                    }
                }

                if (!String.IsNullOrEmpty(deletedAttribute))
                {
                    FeedSynchronizationTombstoneStatus status = FeedSynchronizationItem.TombstoneStatusByName(deletedAttribute);
                    if (status != FeedSynchronizationTombstoneStatus.None)
                    {
                        this.TombstoneStatus = status;
                        wasLoaded            = true;
                    }
                }

                if (!String.IsNullOrEmpty(noConflictsAttribute))
                {
                    FeedSynchronizationConflictPreservationDirective directive = FeedSynchronizationItem.ConflictPreservationByName(noConflictsAttribute);
                    if (directive != FeedSynchronizationConflictPreservationDirective.None)
                    {
                        this.ConflictPreservation = directive;
                        wasLoaded = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator historyIterator    = source.Select("sx:history", manager);
                XPathNavigator    conflictsNavigator = source.SelectSingleNode("sx:conflicts", manager);

                if (historyIterator != null && historyIterator.Count > 0)
                {
                    while (historyIterator.MoveNext())
                    {
                        FeedSynchronizationHistory history = new FeedSynchronizationHistory();
                        if (history.Load(historyIterator.Current))
                        {
                            this.Histories.Add(history);
                            wasLoaded = true;
                        }
                    }
                }

                if (conflictsNavigator != null && conflictsNavigator.HasChildren)
                {
                    XPathNodeIterator childrenIterator = conflictsNavigator.SelectChildren(XPathNodeType.Element);
                    if (childrenIterator != null && childrenIterator.Count > 0)
                    {
                        this.Conflicts.Add(childrenIterator.Current);
                        wasLoaded = true;
                    }
                }
            }

            return(wasLoaded);
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FeedSynchronizationItem"/> class using the supplied indentifier, number of updates, and initial <see cref="FeedSynchronizationHistory"/>.
 /// </summary>
 /// <param name="id">The globally unique identifier for the item.</param>
 /// <param name="updates">The number of updates applied to this item.</param>
 /// <param name="history">A <see cref="FeedSynchronizationHistory"/> object that represents the initial information about updates to this item.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="id"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="id"/> is an empty string.</exception>
 /// <exception cref="ArgumentOutOfRangeException">The <paramref name="updates"/> is less than <b>1</b>.</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="history"/> is a null reference (Nothing in Visual Basic).</exception>
 public FeedSynchronizationItem(string id, int updates, FeedSynchronizationHistory history) : this(id, updates)
 {
     Guard.ArgumentNotNull(history, "history");
     this.Histories.Add(history);
 }