diff --git a/src/Leprechaun.InputProviders.Sitecore/Adapters/SitecoreItemDataAdapter.cs b/src/Leprechaun.InputProviders.Sitecore/Adapters/SitecoreItemDataAdapter.cs index 83aad0f..edf5b11 100644 --- a/src/Leprechaun.InputProviders.Sitecore/Adapters/SitecoreItemDataAdapter.cs +++ b/src/Leprechaun.InputProviders.Sitecore/Adapters/SitecoreItemDataAdapter.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Leprechaun.Adapters; using Leprechaun.InputProviders.Sitecore.Extensions; using Leprechaun.TemplateReaders; @@ -28,10 +29,11 @@ public SitecoreItemDataAdapter(IItemData itemData, FilesystemTreeDataStore dataS public IEnumerable SharedFields => _itemData.SharedFields.Select(sf => new SitecoreItemFieldValueAdapter(sf)); public IEnumerable UnversionedFields => _itemData.UnversionedFields.Select(id => new SitecoreItemLanguageAdapter(id)); public IEnumerable Versions => _itemData.Versions.Select(x => new SitecoreItemVersionAdapter(x)); - public IEnumerable GetChildren() + public IEnumerable GetChildren() => GetChildrenAsync().GetAwaiter().GetResult(); + public async Task> GetChildrenAsync() { - IItemTreeNode templateRootNode = _dataStore.GetTreeNodeSync(_itemData.Path); - return templateRootNode.GetChildrenSync().Select(n => new SitecoreItemDataAdapter(_dataStore.GetItemDataSync(n), _dataStore)).ToArray(); + IItemTreeNode templateRootNode = await _dataStore.GetTreeNode(_itemData.Path); + return (await templateRootNode.GetChildren()).Select(n => new SitecoreItemDataAdapter(_dataStore.GetItemDataSync(n), _dataStore)).ToArray(); } } } \ No newline at end of file diff --git a/src/Leprechaun.InputProviders.Sitecore/Filters/SitecoreTemplatePredicate.cs b/src/Leprechaun.InputProviders.Sitecore/Filters/SitecoreTemplatePredicate.cs index b6d1cf2..2c4cc76 100644 --- a/src/Leprechaun.InputProviders.Sitecore/Filters/SitecoreTemplatePredicate.cs +++ b/src/Leprechaun.InputProviders.Sitecore/Filters/SitecoreTemplatePredicate.cs @@ -1,7 +1,9 @@ -using System.Xml; +using System.Collections.Generic; +using System.Xml; using Configy.Containers; using Leprechaun.Filters; using Leprechaun.InputProviders.Sitecore.Configuration; +using Sitecore.DevEx.Serialization.Client.Datasources.Filesystem.Configuration; namespace Leprechaun.InputProviders.Sitecore.Filters { @@ -33,5 +35,16 @@ public LeprechaunModuleConfiguration GetModule() { return _leprechaunModule; } + + public IEnumerable GetTreeSpecs() + { + foreach (var treeNode in _leprechaunModule.SerializationModule.Items.Includes) + { + if (_includeNames.Contains(treeNode.Name.ToLowerInvariant())) + { + yield return treeNode; + } + } + } } } diff --git a/src/Leprechaun.InputProviders.Sitecore/Leprechaun.config b/src/Leprechaun.InputProviders.Sitecore/Leprechaun.config index 917cfad..4049e2b 100644 --- a/src/Leprechaun.InputProviders.Sitecore/Leprechaun.config +++ b/src/Leprechaun.InputProviders.Sitecore/Leprechaun.config @@ -82,9 +82,13 @@ --> - + - + diff --git a/src/Leprechaun.InputProviders.Sitecore/TemplateReaders/SitecoreTemplateReader.cs b/src/Leprechaun.InputProviders.Sitecore/TemplateReaders/SitecoreTemplateReader.cs index 33d7d4c..4cc8d8a 100644 --- a/src/Leprechaun.InputProviders.Sitecore/TemplateReaders/SitecoreTemplateReader.cs +++ b/src/Leprechaun.InputProviders.Sitecore/TemplateReaders/SitecoreTemplateReader.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using System.Xml; using Leprechaun.Filters; using Leprechaun.InputProviders.Sitecore.Adapters; @@ -9,13 +10,14 @@ using Leprechaun.InputProviders.Sitecore.Filters; using Leprechaun.Model; using Leprechaun.TemplateReaders; +using Sitecore.DevEx.Serialization; +using Sitecore.DevEx.Serialization.Client.Query; namespace Leprechaun.InputProviders.Sitecore.TemplateReaders { public class SitecoreTemplateReader : BaseTemplateReader, ITemplateReader { - public SitecoreTemplateReader(XmlNode configNode) : base(configNode) { } @@ -24,22 +26,39 @@ public override TemplateInfo[] GetTemplates(ITemplatePredicate predicate) { if (predicate is SitecoreTemplatePredicate scPredicate) { - return GetTemplates(scPredicate.GetModule()).ToArray(); + return GetTemplates(scPredicate).GetAwaiter().GetResult().ToArray(); } return new TemplateInfo[0]; } - - public IEnumerable GetTemplates(LeprechaunModuleConfiguration module) + + public async Task> GetTemplates(SitecoreTemplatePredicate predicate) { - return module.SerializationModule.Items.Includes - .AsParallel() - .SelectMany(fsTreeSpec => + var module = predicate.GetModule(); + var tasks = new List>>(); + foreach (var fstree in predicate.GetTreeSpecs()) + { + if (fstree.Scope == TreeScope.DescendantsOnly) { - var templateItemData = module.DataStore.GetItemDataSync(module.DataStore.GetTreeNodeSync(fsTreeSpec.Path)); - var itemAdapter = new SitecoreItemDataAdapter(templateItemData, module.DataStore); - return ParseTemplates(itemAdapter); - }) - .ToArray(); + var templates = (await module.DataStore + .GetChildren(fstree.Path)) + .Select(child => ConvertTreeToTemplates(module, child)); + + tasks.AddRange(templates); + } + else + { + tasks.Add(ConvertTreeToTemplates(module, await module.DataStore.GetTreeNode(fstree.Path))); + } + } + + return (await Task.WhenAll(tasks)).SelectMany(x => x); + } + + private async Task> ConvertTreeToTemplates(LeprechaunModuleConfiguration module, IItemTreeNode tn) + { + var templateItemData = await module.DataStore.GetItemData(tn); + var itemAdapter = new SitecoreItemDataAdapter(templateItemData, module.DataStore); + return ParseTemplates(itemAdapter); } protected override Guid[] ParseMultilistValue(string value) diff --git a/src/Leprechaun/Filters/BaseTemplatePredicate.cs b/src/Leprechaun/Filters/BaseTemplatePredicate.cs index 5c979b1..4f99d7f 100644 --- a/src/Leprechaun/Filters/BaseTemplatePredicate.cs +++ b/src/Leprechaun/Filters/BaseTemplatePredicate.cs @@ -12,6 +12,7 @@ namespace Leprechaun.Filters public abstract class BaseTemplatePredicate : ITemplatePredicate { protected readonly IList _includeEntries; + protected readonly ISet _includeNames; protected readonly IContainer _configuration; protected readonly string _rootNamespace; @@ -24,6 +25,7 @@ protected BaseTemplatePredicate(XmlNode configNode, IContainer configuration, st _rootNamespace = rootNamespace; _includeEntries = ParsePreset(configNode); + _includeNames = new HashSet(_includeEntries.Select(x => x.Name.ToLowerInvariant())); EnsureEntriesExist(configuration?.Name ?? "Unknown"); } /// diff --git a/src/Leprechaun/TemplateReaders/BaseTemplateReader.cs b/src/Leprechaun/TemplateReaders/BaseTemplateReader.cs index 9796fe4..4619d96 100644 --- a/src/Leprechaun/TemplateReaders/BaseTemplateReader.cs +++ b/src/Leprechaun/TemplateReaders/BaseTemplateReader.cs @@ -58,8 +58,6 @@ protected void ParseExcludedTemplates(XmlNode configNode) public abstract TemplateInfo[] GetTemplates(ITemplatePredicate predicate); - //public abstract TemplateInfo[] GetTemplates(params ITreeRoot[] rootPaths); - protected virtual IEnumerable ParseTemplates(IItemDataAdapter root) { var processQueue = new Queue();