public IEnumerable <ContentItemGroup> FindItemGroups(ContentPatternDefinition definition) { var groupPatterns = definition.GroupPatterns .Select(pattern => Tuple.Create(pattern, new PatternExpression(pattern.Pattern))) .ToList(); var groupAssets = new List <Tuple <ContentItem, Asset> >(); foreach (var asset in _assets) { foreach (var groupParser in groupPatterns) { ContentItem item = groupParser.Item2.Match(asset.Path, definition.PropertyDefinitions); if (item != null) { foreach (var pair in groupParser.Item1.Defaults) { item.Properties[pair.Key] = pair.Value; } groupAssets.Add(Tuple.Create(item, asset)); } } } foreach (var grouping in groupAssets.GroupBy(key => key.Item1, new GroupComparer())) { var group = new ContentItemGroup(); foreach (var property in grouping.Key.Properties) { group.Properties.Add(property.Key, property.Value); } foreach (var item in FindItemsImplementation(definition, grouping.Select(match => match.Item2))) { group.Items.Add(item); } yield return(group); } }
private IEnumerable <ContentItem> FindItemsImplementation(ContentPatternDefinition definition, IEnumerable <Asset> assets) { var pathPatterns = definition.PathPatterns .Select(pattern => Tuple.Create(pattern, new PatternExpression(pattern.Pattern))) .ToList(); foreach (var asset in assets) { foreach (var pathPattern in pathPatterns) { ContentItem contentItem = pathPattern.Item2.Match(asset.Path, definition.PropertyDefinitions); if (contentItem != null) { foreach (var pair in pathPattern.Item1.Defaults) { contentItem.Properties[pair.Key] = pair.Value; } yield return(contentItem); break; } } } }
public PatternDefinitions() { Properties = new PropertyDefinitions(); ManagedAssemblies = new ContentPatternDefinition { GroupPatterns = { "runtimes/{rid}/lib/{tfm}/{any?}", "lib/{tfm}/{any?}" }, PathPatterns = { "runtimes/{rid}/lib/{tfm}/{assembly}", "lib/{tfm}/{assembly}" }, PropertyDefinitions = Properties.Definitions }; ManagedAssemblies.GroupPatterns.Add(new PatternDefinition { Pattern = "lib/{assembly?}", Defaults = new Dictionary<string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); ManagedAssemblies.PathPatterns.Add(new PatternDefinition { Pattern = "lib/{assembly}", Defaults = new Dictionary<string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); CompileTimeAssemblies = new ContentPatternDefinition { GroupPatterns = { "ref/{tfm}/{any?}", }, PathPatterns = { "ref/{tfm}/{assembly}", }, PropertyDefinitions = Properties.Definitions, }; ResourceAssemblies = new ContentPatternDefinition { GroupPatterns = { "runtimes/{rid}/lib/{tfm}/{locale?}/{any?}", "lib/{tfm}/{locale?}/{any?}" }, PathPatterns = { "runtimes/{rid}/lib/{tfm}/{locale}/{resources}", "lib/{tfm}/{locale}/{resources}" }, PropertyDefinitions = Properties.Definitions }; ResourceAssemblies.GroupPatterns.Add(new PatternDefinition { Pattern = "lib/{locale}/{resources?}", Defaults = new Dictionary<string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); ResourceAssemblies.PathPatterns.Add(new PatternDefinition { Pattern = "lib/{locale}/{resources}", Defaults = new Dictionary<string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); NativeLibraries = new ContentPatternDefinition { GroupPatterns = { "runtimes/{rid}/native/{any?}", "native/{any?}", }, PathPatterns = { "runtimes/{rid}/native/{any}", "native/{any}", }, PropertyDefinitions = Properties.Definitions, }; }
public PatternDefinitions() { Properties = new PropertyDefinitions(); ManagedAssemblies = new ContentPatternDefinition { GroupPatterns = { "runtimes/{rid}/lib/{tfm}/{any?}", "lib/{tfm}/{any?}" }, PathPatterns = { "runtimes/{rid}/lib/{tfm}/{assembly}", "lib/{tfm}/{assembly}" }, PropertyDefinitions = Properties.Definitions }; ManagedAssemblies.GroupPatterns.Add(new PatternDefinition { Pattern = "lib/{assembly?}", Defaults = new Dictionary <string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); ManagedAssemblies.PathPatterns.Add(new PatternDefinition { Pattern = "lib/{assembly}", Defaults = new Dictionary <string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); CompileTimeAssemblies = new ContentPatternDefinition { GroupPatterns = { "ref/{tfm}/{any?}", }, PathPatterns = { "ref/{tfm}/{assembly}", }, PropertyDefinitions = Properties.Definitions, }; ResourceAssemblies = new ContentPatternDefinition { GroupPatterns = { "runtimes/{rid}/lib/{tfm}/{locale?}/{any?}", "lib/{tfm}/{locale?}/{any?}" }, PathPatterns = { "runtimes/{rid}/lib/{tfm}/{locale}/{resources}", "lib/{tfm}/{locale}/{resources}" }, PropertyDefinitions = Properties.Definitions }; ResourceAssemblies.GroupPatterns.Add(new PatternDefinition { Pattern = "lib/{locale}/{resources?}", Defaults = new Dictionary <string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); ResourceAssemblies.PathPatterns.Add(new PatternDefinition { Pattern = "lib/{locale}/{resources}", Defaults = new Dictionary <string, object> { { "tfm", DnxVersionUtility.ParseFrameworkName("net") } } }); NativeLibraries = new ContentPatternDefinition { GroupPatterns = { "runtimes/{rid}/native/{any?}", "native/{any?}", }, PathPatterns = { "runtimes/{rid}/native/{any}", "native/{any}", }, PropertyDefinitions = Properties.Definitions, }; }
public IEnumerable <ContentItem> FindItems(ContentPatternDefinition definition) { return(FindItemsImplementation(definition, _assets)); }