public ActionResult GetItemYamlWithChildren(RevisionModel data)
        {
            var guid = Guid.Parse(data.Id);

            using (new SecurityDisabler())
            {
                IItemData   item          = _sitecore.GetItemData(guid);
                var         localRev      = _sitecore.GetItemAndChildrenRevision(guid);
                List <Guid> GrandChildren = new List <Guid>();
                var         items         = new List <KeyValuePair <Guid, string> >();
                if (data.Rev == null || !data.Rev.ContainsKey(item.Id) || data.Rev[item.Id] != localRev[item.Id])
                {
                    using (var stream = new MemoryStream())
                    {
                        _yamlSerializationService.WriteSerializedItem(item, stream);
                        stream.Seek(0, SeekOrigin.Begin);

                        using (var reader = new StreamReader(stream))
                        {
                            items.Add(new KeyValuePair <Guid, string>(item.Id, reader.ReadToEnd()));
                        }
                    }
                }
                else
                {
                    items.Add(new KeyValuePair <Guid, string>(item.Id, null));
                }
                if (item.Path.StartsWith("/sitecore/media library/"))
                {
                    GrandChildren.AddRange(item.GetChildren().Select(x => x.Id));
                }
                else
                {
                    items.AddRange(item.GetChildren().Select(x =>
                    {
                        GrandChildren.AddRange(x.GetChildren().Select(c => c.Id));
                        if (data.Rev != null && data.Rev.ContainsKey(x.Id) && localRev.ContainsKey(x.Id) && data.Rev[x.Id] == localRev[x.Id])
                        {
                            return(new KeyValuePair <Guid, string>(x.Id, null));
                        }
                        using (var stream = new MemoryStream())
                        {
                            _yamlSerializationService.WriteSerializedItem(x, stream);
                            stream.Seek(0, SeekOrigin.Begin);

                            using (var reader = new StreamReader(stream))
                            {
                                return(new KeyValuePair <Guid, string>(x.Id, reader.ReadToEnd()));
                            }
                        }
                    }));
                }
                return(ScsJson(new ChildrenItemDataModel
                {
                    Items = items,
                    GrandChildren = GrandChildren
                }));
            }
        }
Exemple #2
0
 public IEnumerable <IItemData> GetChildren(IItemData parent)
 {
     using (new SecurityDisabler())
     {
         return(parent.GetChildren());
     }
 }
Exemple #3
0
        private static TemplateField[] GetTemplateFields(IItemData item, Template template)
        {
            var results = new List <TemplateField>();

            var sections = item.GetChildren().Where(child => child.TemplateId == TemplateSectionTemplateId);

            foreach (var section in sections)
            {
                var fields = section.GetChildren().Where(child => child.TemplateId == TemplateFieldTemplateId);

                foreach (var field in fields)
                {
                    results.Add(new TemplateField
                    {
                        Id          = field.Id,
                        Template    = template,
                        DisplayName = GetFieldValue(field, TemplateFieldTitleFieldId, null) ??
                                      GetFieldValue(field, DisplayNameFieldId, string.Empty),
                        Name      = field.Name,
                        Path      = field.Path,
                        Section   = section.Name,
                        SortOrder = GetFieldValueAsInt(field, SortOrderFieldId, 100),
                        Source    = GetFieldValue(field, SourceFieldId, string.Empty),
                        Type      = GetFieldValue(field, FieldTypeFieldId, string.Empty)
                    });
                }
            }

            return(results.ToArray());
        }
Exemple #4
0
        public void GatherItems_GetsChildren_ProcessesChildren()
        {
            Guid      parentGuid       = Guid.NewGuid();
            Guid      childGuid        = Guid.NewGuid();
            IItemData expectedItemData = Substitute.For <IItemData>();

            expectedItemData.Name.Returns("ExpectedName");
            expectedItemData.GetChildren().Returns(new List <IItemData> {
                Substitute.For <IItemData>()
            });

            ContentItemPuller contentItemPuller = CreateInstance <ContentItemPuller>();

            GetSubstitute <IRemoteContentService>().GetRemoteItemDataWithChildren(parentGuid, Arg.Any <string>()).Returns(new ChildrenItemDataModel {
                GrandChildren = new List <Guid> {
                    childGuid
                }
            });
            GetSubstitute <IRemoteContentService>().GetRemoteItemDataWithChildren(childGuid, Arg.Any <string>()).Returns(new ChildrenItemDataModel());
            GetSubstitute <IYamlSerializationService>().DeserializeYaml(Arg.Any <string>(), Arg.Any <string>()).Returns(expectedItemData);
            contentItemPuller.ProcessingIds.Add(parentGuid);

            contentItemPuller.GatherItems(true, "", CancellationToken.None, false);

            contentItemPuller.GatheredRemoteItems.Count.Should().Be(2);
        }
Exemple #5
0
        protected virtual TemplateFieldInfo[] ParseTemplateFields(IItemData templateItem)
        {
            var results = new List <TemplateFieldInfo>();

            var sections = templateItem.GetChildren().Where(child => child.TemplateId == TemplateSectionTemplateId);

            foreach (var section in sections)
            {
                var fields = section.GetChildren().Where(child => child.TemplateId == TemplateFieldTemplateId);

                foreach (var field in fields)
                {
                    results.Add(new TemplateFieldInfo
                    {
                        Id          = field.Id,
                        DisplayName = GetFieldValue(field, TemplateFieldTitleFieldId, null) ?? GetFieldValue(field, DisplayNameFieldId, string.Empty),
                        HelpText    = GetFieldValue(field, HelpTextFieldId, string.Empty),
                        Name        = field.Name,
                        Path        = field.Path,
                        Section     = section.Name,
                        SortOrder   = GetFieldValueAsInt(field, SortOrderFieldId, 100),
                        Source      = GetFieldValue(field, SourceFieldId, string.Empty),
                        Type        = GetFieldValue(field, FieldTypeFieldId, string.Empty)
                    });
                }
            }

            return(results.ToArray());
        }
 private void Initialize(IItemData item, bool open)
 {
     if (item == null)
     {
         return;
     }
     DatabaseName = item.DatabaseName;
     Open         = open;
     SetIcon(item);
     DisplayName = item.Name;
     Id          = item.Id.ToString();
     if (Open)
     {
         Nodes = item.GetChildren().Select(c => new ContentTreeNode(c, false)).ToList();
     }
 }
Exemple #7
0
        public IEnumerable <IItemData> GetChildren(IItemData item)
        {
            var dilithiumItem = item as SqlItemData;

            // if the item is not from Dilithium it will have to use its original data store to get children
            if (dilithiumItem == null)
            {
                return(item.GetChildren());
            }

            var core = GetCore(item.DatabaseName);

            if (core == null)
            {
                return(Enumerable.Empty <IItemData>());
            }

            return(core.GetChildren(dilithiumItem));
        }
Exemple #8
0
        public void GatherItems_DoNotGetChildren_DoesNotGetChildren()
        {
            IItemData expectedItemData = Substitute.For <IItemData>();

            expectedItemData.Name.Returns("ExpectedName");
            expectedItemData.GetChildren().Returns(new List <IItemData> {
                Substitute.For <IItemData>()
            });

            ContentItemPuller contentItemPuller = CreateInstance <ContentItemPuller>();

            GetSubstitute <IRemoteContentService>().GetRemoteItemDataWithChildren(Arg.Any <Guid>(), Arg.Any <string>()).Returns(new ChildrenItemDataModel());
            GetSubstitute <IYamlSerializationService>().DeserializeYaml(Arg.Any <string>(), Arg.Any <string>()).Returns(expectedItemData);
            contentItemPuller.ProcessingIds.Add(Guid.NewGuid());

            contentItemPuller.GatherItems(false, "", CancellationToken.None, false);

            contentItemPuller.GatheredRemoteItems.Count.Should().Be(1);
        }
Exemple #9
0
        public static ISetting Create(IItemData item, List <ITemplate> allTemplates)
        {
            var setting = new Setting
            {
                Id         = item.Id,
                TemplateId = item.TemplateId,
                Name       = item.Name,
                Template   = GetTemplate(item, allTemplates),
                Path       = item.Path,
                Fields     = GetFields(item)
            };

            foreach (var itemData in item.GetChildren().ToList())
            {
                setting.Children.Add(Create(itemData, allTemplates));
            }

            return(setting);
        }
Exemple #10
0
        public async Task GatherItems_MultipleThreads_AllCompleteWhenFinished()
        {
            int       expectedCount    = 1000;
            IItemData expectedItemData = Substitute.For <IItemData>();

            expectedItemData.Name.Returns("ExpectedName");
            expectedItemData.GetChildren().Returns(new List <IItemData> {
                Substitute.For <IItemData>()
            });

            ContentItemPuller contentItemPuller = CreateInstance <ContentItemPuller>();

            GetSubstitute <IRemoteContentService>().GetRemoteItemDataWithChildren(Arg.Any <Guid>(), Arg.Any <string>()).Returns(new ChildrenItemDataModel());
            GetSubstitute <IYamlSerializationService>().DeserializeYaml(Arg.Any <string>(), Arg.Any <string>()).Returns(expectedItemData);
            for (int i = 0; i < expectedCount; i++)
            {
                contentItemPuller.ProcessingIds.Add(Guid.NewGuid());
            }

            var cancellationTokenSource = new CancellationTokenSource();

            Task[] taskList =
            {
                Task.Run(() =>
                {
                    contentItemPuller.GatherItems(false, "", cancellationTokenSource.Token, false);
                }),
                Task.Run(() =>
                {
                    contentItemPuller.GatherItems(false, "", cancellationTokenSource.Token, false);
                }),
                Task.Run(() =>
                {
                    contentItemPuller.GatherItems(false, "", cancellationTokenSource.Token, false);
                })
            };

            await Task.WhenAny(taskList);

            contentItemPuller.GatheredRemoteItems.Count.Should().Be(expectedCount);
            taskList.All(t => t.IsCompleted).Should().BeTrue();
        }
        public ActionResult GetItemYamlWithChildren(string id)
        {
            Assert.ArgumentNotNullOrEmpty(id, "id");
            using (var stream = new MemoryStream())
            {
                using (new SecurityDisabler())
                {
                    IItemData item = _sitecore.GetItemData(Guid.Parse(id));
                    _yamlSerializationService.WriteSerializedItem(item, stream);
                    stream.Seek(0, SeekOrigin.Begin);

                    using (var reader = new StreamReader(stream))
                    {
                        return(ScsJson(new ChildrenItemDataModel
                        {
                            Item = reader.ReadToEnd(),
                            Children = item.GetChildren().Select(x => x.Id).ToList()
                        }));
                    }
                }
            }
        }
 private static IEnumerable <IItemData> GetTemplateFields(IItemData template)
 {
     return(template.GetChildren().SelectMany(templateSection => templateSection.GetChildren()));
 }
 public IEnumerable <IItemDataAdapter> GetChildren()
 {
     return(_itemData.GetChildren().Select(c => new RainbowItemDataAdapter(c)));
 }
Exemple #14
0
 public virtual IEnumerable <IItemData> GetChildren()
 {
     return(InnerItem.GetChildren());
 }