public MappedItem(string name, DocumentMap documentMap, MappedItem parentMapItem = null)
 {
     this.Name = name;
     AddParent(documentMap, parentMapItem);
     DocumentMapId = documentMap.Id;
     Id            = Guid.NewGuid();
 }
Example #2
0
        public void AddMappedItem(MappedItem mappedItem)
        {
            mappedItem.Name = mappedItem.Name.Trim();
            if (!MappedItemDictionary.ContainsKey(mappedItem.Id.ToString()))
            {
                if (mappedItem.ParentMappedItemId.HasValue)
                {
                    var parentItem = MappedItemDictionary[mappedItem.ParentMappedItemId.Value.ToString()];
                    if (parentItem != null)
                    {
                        mappedItem.Position = parentItem.ChildMappedItems.Count > 0 ? parentItem.ChildMappedItems.Count + 1 : 0;
                        parentItem.ChildMappedItems.Add(mappedItem);
                    }
                }
                else
                {
                    mappedItem.Position   = this.MappedItems.Count > 0 ? this.MappedItems.Count + 1 : 0;
                    mappedItem.IsRootItem = true;
                    MappedItems.Add(mappedItem);
                }
            }

            if (!MappedItemDictionary.ContainsKey(mappedItem.Id.ToString()))
            {
                MappedItemDictionary.Add(mappedItem.Id.ToString(), mappedItem);
            }
        }
Example #3
0
 public void ChangeParentItem(MappedItem childItem, MappedItem parentitem)
 {
     if (MappedItemDictionary.ContainsKey(childItem.ParentMappedItemId.ToString()))
     {
         var CurrentParent = this.MappedItemDictionary[childItem.ParentMappedItemId.ToString()];
         CurrentParent.ChildMappedItems.Remove(childItem);
     }
     parentitem.AddChildMappedItem(childItem);
 }
        public string ThisMappedItemToXMLString()
        {
            MappedItem onlyThisMappedItem = this;

            onlyThisMappedItem.ChildMappedItems.Clear();
            using (StringWriter stringwriter = new System.IO.StringWriter())
            {
                var serializer = new XmlSerializer(onlyThisMappedItem.GetType());
                serializer.Serialize(stringwriter, onlyThisMappedItem);
                return(stringwriter.ToString());
            }
        }
 private void AddParent(DocumentMap documentMap, MappedItem parentMapItem = null)
 {
     if (parentMapItem == null)
     {
         this.Position = documentMap.MappedItems.Count > 0 ? documentMap.MappedItems.Count + 1 : 0;
         IsRootItem    = true;
     }
     else
     {
         ParentMappedItemId = parentMapItem.Id;
         IsRootItem         = false;
     }
 }
        public void AddChildMappedItem(MappedItem mappedItem, int?position = null)
        {
            if (this.Name == mappedItem.Name)
            {
                //Error message
            }

            if (position.HasValue)
            {
            }
            mappedItem.ParentMappedItemId = this.Id;
            _childMappedItems.Add(mappedItem);
        }
        internal void DeleteChildMappedItem(MappedItem mappedItem)
        {
            int?itemIdex = null;

            for (var i = 0; i < ChildMappedItems.Count; i++)
            {
                if (ChildMappedItems[i].Id == mappedItem.Id)
                {
                    itemIdex = i;
                    break;
                }
            }

            if (itemIdex.HasValue)
            {
                ChildMappedItems.RemoveAt(itemIdex.Value);
            }
        }
        public IList <MappedItem> FlattenChildItems(MappedItem item)
        {
            if (item == null)
            {
                FlattenChildItems(this);
            }

            var childMappedItems = new List <MappedItem>();

            foreach (var child in item.ChildMappedItems)
            {
                childMappedItems.Add(child);

                if (child.ChildMappedItems.Any())
                {
                    foreach (var childItem in child.ChildMappedItems)
                    {
                        childMappedItems.AddRange(FlattenChildItems(childItem));
                    }
                }
            }

            return(childMappedItems);
        }