Example #1
0
        static public Microsoft.Samples.FeedSync.SyncNode CreateNew(Microsoft.Samples.FeedSync.Feed i_Feed, Microsoft.Samples.FeedSync.FeedItemNode i_FeedItemNode, string i_SyncNodeID, int i_Sequence, System.DateTime? i_WhenDateTime, string i_By, bool i_Deleted, bool i_NoConflicts, int i_Updates)
        {
            string ElementName = System.String.Format
                (
                "{0}:{1}",
                i_Feed.FeedSyncNamespacePrefix,
                Microsoft.Samples.FeedSync.Constants.SYNC_ELEMENT_NAME
                );

            System.Xml.XmlElement SyncNodeXmlElement = i_Feed.XmlDocument.CreateElement
                (
                ElementName, 
                Microsoft.Samples.FeedSync.Constants.FEEDSYNC_XML_NAMESPACE_URI
                );

            SyncNodeXmlElement.SetAttribute
                (
                Microsoft.Samples.FeedSync.Constants.ID_ATTRIBUTE,
                i_SyncNodeID
                );

            SyncNodeXmlElement.SetAttribute
                (
                Microsoft.Samples.FeedSync.Constants.UPDATES_ATTRIBUTE,
                i_Updates.ToString()
                );

            SyncNodeXmlElement.SetAttribute
                (
                Microsoft.Samples.FeedSync.Constants.DELETED_ATTRIBUTE,
                i_Deleted ? "true" : "false"
                );

            SyncNodeXmlElement.SetAttribute
                (
                Microsoft.Samples.FeedSync.Constants.NO_CONFLICTS_ATTRIBUTE,
                i_NoConflicts ? "true" : "false"
                );

            Microsoft.Samples.FeedSync.SyncNode SyncNode = new Microsoft.Samples.FeedSync.SyncNode
                (
                i_FeedItemNode, 
                SyncNodeXmlElement
                );

            Microsoft.Samples.FeedSync.HistoryNode FeedSyncHistoryNode = Microsoft.Samples.FeedSync.HistoryNode.CreateNew
                (
                SyncNode, 
                i_WhenDateTime, 
                i_By
                );

            SyncNode.AddHistoryNode(FeedSyncHistoryNode);

            return SyncNode;
        }
Example #2
0
        static public Microsoft.Samples.FeedSync.SyncNode CreateFromXmlElement(Microsoft.Samples.FeedSync.FeedItemNode i_FeedItemNode, System.Xml.XmlElement i_SyncNodeXmlElement)
        {
            if (i_SyncNodeXmlElement.OwnerDocument != i_FeedItemNode.Feed.XmlDocument)
                i_SyncNodeXmlElement = (System.Xml.XmlElement)i_FeedItemNode.Feed.XmlDocument.ImportNode(i_SyncNodeXmlElement, true);

            Microsoft.Samples.FeedSync.SyncNode SyncNode = new Microsoft.Samples.FeedSync.SyncNode(i_FeedItemNode, i_SyncNodeXmlElement);
            return SyncNode;
        }
Example #3
0
        private FeedItemNode(Microsoft.Samples.FeedSync.Feed i_Feed, System.Xml.XmlElement i_FeedItemXmlElement, string i_SyncNodeID, int i_Sequence, System.DateTime? i_WhenDateTime, string i_By, bool i_Deleted, bool i_NoConflicts, int i_Updates)
        {
            m_Feed = i_Feed;

            this.GetFeedItemDataFromXmlElement(i_FeedItemXmlElement);

            m_XmlElement = i_FeedItemXmlElement;

            m_SyncNode = Microsoft.Samples.FeedSync.SyncNode.CreateNew
                (
                m_Feed, 
                this,
                i_SyncNodeID,
                i_Sequence,
                i_WhenDateTime,
                i_By,
                i_Deleted,
                i_NoConflicts,
                i_Updates
                );

            if (m_XmlElement.ChildNodes.Count > 0)
                m_XmlElement.InsertBefore(m_SyncNode.XmlElement, m_XmlElement.ChildNodes[0]);
            else
                m_XmlElement.AppendChild(m_SyncNode.XmlElement);
            if (m_Feed.FeedType == Microsoft.Samples.FeedSync.Feed.FeedTypes.Atom)
                this.AddUpdatedElement();
        }
Example #4
0
        private FeedItemNode(Microsoft.Samples.FeedSync.Feed i_Feed, System.Xml.XmlElement i_FeedItemXmlElement, string i_SyncNodeID)
        {
            m_Feed = i_Feed;

            this.GetFeedItemDataFromXmlElement(i_FeedItemXmlElement);

            m_XmlElement = i_FeedItemXmlElement;

            m_SyncNode = Microsoft.Samples.FeedSync.SyncNode.CreateNew
                (
                m_Feed,
                this,
                i_SyncNodeID
                );

            if (m_XmlElement.ChildNodes.Count > 0)
                m_XmlElement.InsertBefore(m_SyncNode.XmlElement, m_XmlElement.ChildNodes[0]);
            else
                m_XmlElement.AppendChild(m_SyncNode.XmlElement);
        }
Example #5
0
        private FeedItemNode(Microsoft.Samples.FeedSync.Feed i_Feed, System.Xml.XmlElement i_FeedItemXmlElement)
        {
            m_Feed = i_Feed;

            this.GetFeedItemDataFromXmlElement(i_FeedItemXmlElement);

            m_XmlElement = i_FeedItemXmlElement;

            #region Get sx:sync element

            string ElementName = System.String.Format
                (
                "{0}:{1}",
                i_Feed.FeedSyncNamespacePrefix,
                Microsoft.Samples.FeedSync.Constants.SYNC_ELEMENT_NAME
                );

            System.Xml.XmlElement SyncNodeXmlElement = (System.Xml.XmlElement)m_XmlElement.SelectSingleNode
                (
                ElementName, 
                i_Feed.XmlNamespaceManager
                );

            if (SyncNodeXmlElement == null)
                throw new System.ArgumentException("Item is missing 'sx:sync' element!");

            m_SyncNode = Microsoft.Samples.FeedSync.SyncNode.CreateFromXmlElement(this, SyncNodeXmlElement);

            #endregion
        }
Example #6
0
        private HistoryNode(Microsoft.Samples.FeedSync.SyncNode i_SyncNode, System.Xml.XmlElement i_HistoryNodeXmlElement)
        {
            bool InvalidXmlElement =
                (i_HistoryNodeXmlElement.LocalName != Microsoft.Samples.FeedSync.Constants.HISTORY_ELEMENT_NAME) ||
                (i_HistoryNodeXmlElement.NamespaceURI != Microsoft.Samples.FeedSync.Constants.FEEDSYNC_XML_NAMESPACE_URI);

            if (InvalidXmlElement)
                throw new System.Exception("Invalid xml element!");

            m_SyncNode = i_SyncNode;
            m_XmlElement = i_HistoryNodeXmlElement;

            m_Sequence = System.Convert.ToInt32(i_HistoryNodeXmlElement.GetAttribute(Microsoft.Samples.FeedSync.Constants.SEQUENCE_ATTRIBUTE));

            if (i_HistoryNodeXmlElement.HasAttribute(Microsoft.Samples.FeedSync.Constants.WHEN_ATTRIBUTE))
            {
                string When = i_HistoryNodeXmlElement.GetAttribute(Microsoft.Samples.FeedSync.Constants.WHEN_ATTRIBUTE);
                m_WhenDateTime = System.Convert.ToDateTime(When);
            }
            
            if (i_HistoryNodeXmlElement.HasAttribute(Microsoft.Samples.FeedSync.Constants.BY_ATTRIBUTE))
                m_By = i_HistoryNodeXmlElement.GetAttribute(Microsoft.Samples.FeedSync.Constants.BY_ATTRIBUTE);

            if ((m_WhenDateTime == null) && (System.String.IsNullOrEmpty(m_By)))
                throw new System.ArgumentException("Must have 'when' or 'by' attribute!");

            if (m_Sequence > (2^32 - 1))
                throw new System.ArgumentException("Invalid value for 'sequence' attribute!");
        }