public void ShouldUpdateIndexFile() { DbItem dbItem = new DbItem("it1"); using (var db = new Db() { dbItem }) { IndexFileItem indexFileItem = new IndexFileItem() { Id = ItemIDs.RootID.ToGuid() }; new SerializationManager().UpdateIndexFile(indexFileItem, db.GetItem(dbItem.ID)); indexFileItem.Should().NotBeNull(); List <IndexFileItem> itemList = new List <IndexFileItem>(); itemList.Add(indexFileItem); AddAllDescendants(itemList, indexFileItem); itemList.Select(i => i.Id).ShouldAllBeEquivalentTo(new [] { ItemIDs.RootID.ToGuid(), ItemIDs.ContentRoot.ToGuid(), dbItem.ID.ToGuid() }); } }
public void ShouldChildrenBeSorted() { IndexFileItem indexFileItem = new IndexFileItem(); Guid guid1 = new Guid("f11cd74b-099b-48c6-aaed-44927164e9e7"); indexFileItem.Children.Add(new IndexFileItem() { Id = guid1 }); Guid guid2 = new Guid("62e71efe-bcc8-48dc-9868-4dd2fdbfc2dc"); indexFileItem.Children.Add(new IndexFileItem() { Id = guid2 }); Guid guid3 = new Guid("6aa71741-aaf7-4fef-97ad-6148e3a5c076"); indexFileItem.Children.Add(new IndexFileItem() { Id = guid3 }); indexFileItem.Children.Select(c => c.Id).ShouldBeEquivalentTo(new [] { guid2, guid3, guid1 }, options => options.WithStrictOrdering()); }
private void LoadDescendants( IndexFileItem parentFileItem, Item parent, SerializationManager serializationManager, DirectoryInfo parentDirectory) { foreach (var child in parentFileItem.Children) { Item item = parent.Database.GetItem(ID.Parse(child.Id)); if (item == null) { ItemFile itemFile = serializationManager .ReadItemFile(GetItemFileInfo(parentDirectory, child.Id)); item = ItemManager.CreateItem( itemFile.Name, parent, ID.Parse(itemFile.TemplateId), ID.Parse(itemFile.Id), SecurityCheck.Disable); } CorePipeline.Run(revert ? "serialization.revertitem" : "serialization.loaditem", new CustomSerializationPipelineArgs() { SerializationManager = serializationManager, Item = item }); LoadDescendants(child, item, serializationManager, parentDirectory); } }
public void UpdateIndexFile(IndexFileItem indexFileItem, Item item, bool recurseAllDescendants = false) { Assert.ArgumentNotNull(indexFileItem, "indexFileItem"); Assert.ArgumentNotNull(item, "item"); IndexFileItem postitionInTree = indexFileItem; // Iterate ancestors to ensure they are present in the tree var ancestorsAndSelf = item.Axes.GetAncestors().Skip(1); if (item.ID != ItemIDs.RootID) { ancestorsAndSelf = ancestorsAndSelf.Concat(new[] { item }); } foreach (var it in ancestorsAndSelf) { IndexFileItem current = postitionInTree.Children.FirstOrDefault(i => i.Id == it.ID.ToGuid()); if (current == null) { current = new IndexFileItem() { Id = it.ID.ToGuid() }; postitionInTree.Children.Add(current); } postitionInTree = current; } // If required, iterate all descendants and add them to the tree as well if (recurseAllDescendants) { AddDescendantsToTree(postitionInTree, item); } }
private static void AddAllDescendants(List <IndexFileItem> itemList, IndexFileItem indexFileItem) { itemList.AddRange(indexFileItem.Children); foreach (IndexFileItem it in indexFileItem.Children) { AddAllDescendants(itemList, it); } }
public void ShouldGetNullIfUnavailable() { IndexFileItem indexFileItem = new IndexFileItem() { Id = Guid.NewGuid() }; indexFileItem.GetDescendantOrSelf(Guid.NewGuid()).Should().BeNull(); }
public void ShouldGetSelf() { IndexFileItem indexFileItem = new IndexFileItem() { Id = Guid.NewGuid() }; indexFileItem.GetDescendantOrSelf(indexFileItem.Id).Should().BeSameAs(indexFileItem); }
protected override void DoProcess(CustomSerializationPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.IsNotNull(args.IndexFile, "No IndexFile found; needed for determining item tree structure"); IndexFileItem indexFileItem = args.IndexFile.GetDescendantOrSelf(args.Item.ID.ToGuid()); Assert.IsNotNull(indexFileItem, string.Format("Could not find item with ID {0} in serialized data", args.Item.ID)); DirectoryInfo parentDirectory = GetIndexFileInfo(args.Item.Database.Name).Directory; SerializationManager serializationManager = new SerializationManager(); CorePipeline.Run(revert ? "serialization.revertitem" : "serialization.loaditem", new CustomSerializationPipelineArgs() { SerializationManager = serializationManager, Item = args.Item }); LoadDescendants(indexFileItem, args.Item, serializationManager, parentDirectory); }
public void ShouldGetDescendant() { IndexFileItem indexFileItem = new IndexFileItem() { Id = Guid.NewGuid() }; IndexFileItem child = new IndexFileItem() { Id = Guid.NewGuid() }; indexFileItem.Children.Add(child); IndexFileItem grandChild = new IndexFileItem() { Id = Guid.NewGuid() }; child.Children.Add(grandChild); indexFileItem.GetDescendantOrSelf(grandChild.Id).Should().BeSameAs(grandChild); }
private void AddDescendantsToTree(IndexFileItem indexFileItem, Item item) { if (!item.HasChildren) { return; } foreach (Item child in item.GetChildren().InnerChildren) { IndexFileItem fileItem = indexFileItem.Children.FirstOrDefault(c => c.Id == child.ID.ToGuid()); if (fileItem == null) { fileItem = new IndexFileItem() { Id = child.ID.ToGuid() }; indexFileItem.Children.Add(fileItem); } AddDescendantsToTree(fileItem, child); } }
public void ShouldSortTemplatesFirst() { IndexFileItem indexFileItem = new IndexFileItem() { Id = ItemIDs.RootID.ToGuid() }; // Set children for tree root indexFileItem.Children.Add(new IndexFileItem() { Id = ItemIDs.ContentRoot.ToGuid() //0DE95AE4 }); indexFileItem.Children.Add(new IndexFileItem() { Id = ItemIDs.MediaLibraryRoot.ToGuid() //3D6658D8 }); indexFileItem.Children.Add(new IndexFileItem() { Id = ItemIDs.LayoutRoot.ToGuid() //EB2E4FFD }); indexFileItem.Children.Add(new IndexFileItem() { Id = ItemIDs.SystemRoot.ToGuid() //13D6D6C6 }); IndexFileItem templatesIndexFileItem = new IndexFileItem() { Id = ItemIDs.TemplateRoot.ToGuid() //3C1715FE }; indexFileItem.Children.Add(templatesIndexFileItem); // Set children below templates root Guid guid1 = new Guid("f11cd74b-099b-48c6-aaed-44927164e9e7"); templatesIndexFileItem.Children.Add(new IndexFileItem() { Id = guid1 }); templatesIndexFileItem.Children.Add(new IndexFileItem() { Id = ItemIDs.BranchesRoot.ToGuid() }); Guid guid2 = new Guid("62e71efe-bcc8-48dc-9868-4dd2fdbfc2dc"); templatesIndexFileItem.Children.Add(new IndexFileItem() { Id = guid2 }); // Check if template root is first indexFileItem.Children.Select(c => c.Id).ShouldBeEquivalentTo(new[] { ItemIDs.TemplateRoot.ToGuid(), ItemIDs.ContentRoot.ToGuid(), ItemIDs.SystemRoot.ToGuid(), ItemIDs.MediaLibraryRoot.ToGuid(), ItemIDs.LayoutRoot.ToGuid() }, options => options.WithStrictOrdering()); // Check if branches root is last templatesIndexFileItem.Children.Select(c => c.Id).ShouldBeEquivalentTo(new[] { guid2, guid1, ItemIDs.BranchesRoot.ToGuid() }, options => options.WithStrictOrdering()); }