Exemplo n.º 1
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="FeedSynchronizationSyndicationExtensionContext"/>.</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="FeedSynchronizationSyndicationExtensionContext"/> 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 (source.HasChildren)
            {
                XPathNavigator sharingNavigator = source.SelectSingleNode("sx:sharing", manager);
                XPathNavigator syncNavigator    = source.SelectSingleNode("sx:sync", manager);

                if (sharingNavigator != null)
                {
                    FeedSynchronizationSharingInformation sharing = new FeedSynchronizationSharingInformation();
                    if (sharing.Load(sharingNavigator))
                    {
                        this.Sharing = sharing;
                        wasLoaded    = true;
                    }
                }

                if (syncNavigator != null)
                {
                    FeedSynchronizationItem synchronization = new FeedSynchronizationItem();
                    if (synchronization.Load(syncNavigator))
                    {
                        this.Synchronization = synchronization;
                        wasLoaded            = true;
                    }
                }
            }

            return(wasLoaded);
        }
Exemplo n.º 2
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
            //------------------------------------------------------------
            FeedSynchronizationItem value = obj as FeedSynchronizationItem;

            if (value != null)
            {
                int result = String.Compare(this.Id, value.Id, StringComparison.OrdinalIgnoreCase);
                result = result | this.ConflictPreservation.CompareTo(value.ConflictPreservation);
                result = result | this.TombstoneStatus.CompareTo(value.TombstoneStatus);
                result = result | this.Updates.CompareTo(value.Updates);
                result = result | FeedSynchronizationItem.CompareSequence(this.Histories, value.Histories);
                result = result | ComparisonUtility.CompareSequence(this.Conflicts, value.Conflicts);

                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>
        /// Saves the current <see cref="FeedSynchronizationItem"/> 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("sync", extension.XmlNamespace);

            writer.WriteAttributeString("id", this.Id);
            writer.WriteAttributeString("updates", this.Updates.ToString(NumberFormatInfo.InvariantInfo));

            if (this.TombstoneStatus != FeedSynchronizationTombstoneStatus.None)
            {
                writer.WriteAttributeString("deleted", FeedSynchronizationItem.TombstoneStatusAsString(this.TombstoneStatus));
            }

            if (this.ConflictPreservation != FeedSynchronizationConflictPreservationDirective.None)
            {
                writer.WriteAttributeString("noconflicts", FeedSynchronizationItem.ConflictPreservationAsString(this.ConflictPreservation));
            }

            foreach (FeedSynchronizationHistory history in this.Histories)
            {
                history.WriteTo(writer);
            }

            if (this.Conflicts.Count > 0)
            {
                writer.WriteStartElement("conflicts", extension.XmlNamespace);
                foreach (XPathNavigator conflict in this.Conflicts)
                {
                    conflict.WriteSubtree(writer);
                }
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source, XmlNamespaceManager manager)
        /// <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="FeedSynchronizationSyndicationExtensionContext"/>.</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="FeedSynchronizationSyndicationExtensionContext"/> 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)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator sharingNavigator = source.SelectSingleNode("sx:sharing", manager);
                XPathNavigator syncNavigator    = source.SelectSingleNode("sx:sync", manager);

                if (sharingNavigator != null)
                {
                    FeedSynchronizationSharingInformation sharing = new FeedSynchronizationSharingInformation();
                    if (sharing.Load(sharingNavigator))
                    {
                        this.Sharing = sharing;
                        wasLoaded    = true;
                    }
                }

                if (syncNavigator != null)
                {
                    FeedSynchronizationItem synchronization = new FeedSynchronizationItem();
                    if (synchronization.Load(syncNavigator))
                    {
                        this.Synchronization = synchronization;
                        wasLoaded            = true;
                    }
                }
            }

            return(wasLoaded);
        }
Exemplo n.º 5
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);
        }