DocumentCollection class
Inheritance: IEnumerable
        public void Merge(DocumentCollection sourceCollection)
        {
            #region Declarations
            List<string> matchedIDs;
            List<Document> newDocs;

            matchedIDs = new List<string>();
            newDocs = new List<Document>();
            Document sourceDocument;

            #endregion

            // remove deleted documents from the target collection
            for (int index = this.documents.Count - 1; index >= 0; index--)
                if (this.documents[index].LogState == LogState.Deleted)
                    this.documents.RemoveAt(index);

            // go thru each target
            foreach (Document target in this)
            {

                // set the temopry soure docuemtn to null
                sourceDocument = null;

                // go thru each source document
                foreach (Document source in sourceCollection)
                {
                    //try to match by type
                    if ((source.Id == null) || (source.Id == ""))
                    {
                        //if the is no already matched sourec document or the matched source is deleted
                        if (((sourceDocument == null) || (sourceDocument.LogState == LogState.Deleted)) &&

                            // if it is a new one
                            (source.LogState == LogState.Created) &&

                            (source.GetTypePropertyValue() != "") &&
                            (source.GetTypePropertyValue() == target.GetTypePropertyValue()))

                            sourceDocument = source;

                        continue;
                    }

                    if (matchedIDs.Contains(source.Id))
                        continue;

                    if (source.Id != target.Id)
                        continue;

                    if (source.LogState != LogState.Deleted)
                        matchedIDs.Add(source.Id);

                    sourceDocument = source;

                }

                if (sourceDocument != null)
                    target.Merge(sourceDocument);
                else
                    target.ClearTransactionStatus();
            }
            foreach (Document source in sourceCollection)
            {
                if (matchedIDs.Contains(source.Id))
                    continue;

                if ((source.LogState == LogState.Created) || (source.LogState == LogState.Deleted))
                    this.Add(source);
            }
        }
Example #2
0
 private void ReadElement(XmlNode parentNode, DocumentCollection collection)
 {
     if (collection == null)
         return;
     collection.ReadElement(parentNode);
 }
Example #3
0
        /// <summary>
        /// add a new collection to the document. If the collection already exists, it returns false
        /// </summary>
        /// <param name="collection">the collection to add</param>
        /// <returns>true if suceeded</returns>
        protected bool AddCollection(DocumentCollection collection)
        {
            if (collections.ContainsKey(collection.CollectionName))
                return false;

            this.collections.Add(collection.CollectionName, collection);

            return true;
        }
Example #4
0
 private void CreateElement(XmlDocument document, XmlNode parentElement, DocumentCollection collection)
 {
     if (collection == null)
         return;
     parentElement.AppendChild(collection.GetXmlNode(document));
 }
        public void Merge(DocumentCollection sourceCollection)
        {
            #region Declarations
            List <string>   matchedIDs;
            List <Document> newDocs;

            matchedIDs = new List <string>();
            newDocs    = new List <Document>();
            Document sourceDocument;

            #endregion

            // remove deleted documents from the target collection
            for (int index = this.documents.Count - 1; index >= 0; index--)
            {
                if (this.documents[index].LogState == LogState.Deleted)
                {
                    this.documents.RemoveAt(index);
                }
            }


            // go thru each target
            foreach (Document target in this)
            {
                // set the temopry soure docuemtn to null
                sourceDocument = null;

                // go thru each source document
                foreach (Document source in sourceCollection)
                {
                    //try to match by type
                    if ((source.Id == null) || (source.Id == ""))
                    {
                        //if the is no already matched sourec document or the matched source is deleted
                        if (((sourceDocument == null) || (sourceDocument.LogState == LogState.Deleted)) &&

                            // if it is a new one
                            (source.LogState == LogState.Created) &&


                            (source.GetTypePropertyValue() != "") &&
                            (source.GetTypePropertyValue() == target.GetTypePropertyValue()))
                        {
                            sourceDocument = source;
                        }

                        continue;
                    }

                    if (matchedIDs.Contains(source.Id))
                    {
                        continue;
                    }

                    if (source.Id != target.Id)
                    {
                        continue;
                    }

                    if (source.LogState != LogState.Deleted)
                    {
                        matchedIDs.Add(source.Id);
                    }


                    sourceDocument = source;
                }

                if (sourceDocument != null)
                {
                    target.Merge(sourceDocument);
                }
                else
                {
                    target.ClearTransactionStatus();
                }
            }
            foreach (Document source in sourceCollection)
            {
                if (matchedIDs.Contains(source.Id))
                {
                    continue;
                }

                if ((source.LogState == LogState.Created) || (source.LogState == LogState.Deleted))
                {
                    this.Add(source);
                }
            }
        }