Example #1
0
        private IEnumerable <int> Enumerate(int volume, int chapter, [NotNull] string group)
        {
            var components = ("/" + metadata.Structure.Raw)
                             .Split('/', '\\');
            var rest = components.Zip(components.Skip(1), (current, next) => (current, next))
                       .TakeWhile(c => !c.current.Contains("{" + group + "}"))
                       .Select(c => c.next)
                       .ToList();
            var matcher = new Regex(Regex.Escape(rest[rest.Count - 1])
                                    .Replace("\\{volume}", GetRegexComponent(metadata.Structure.Volume, "volume"))
                                    .Replace("\\{chapter}", GetRegexComponent(metadata.Structure.Chapter, "chapter"))
                                    .Replace("\\{page}", GetRegexComponent(metadata.Structure.Page, "page")));

            var rootVolumePath = Path.Combine(
                rest
                .Take(rest.Count - 1)
                .Select(c => c.Replace("{volume}", FillPlaceholder(metadata.Structure.Volume, volume)))
                .Select(c => c.Replace("{chapter}", FillPlaceholder(metadata.Structure.Chapter, chapter)))
                .ToArray());

            return(readOnlyFileSystem.List(rootVolumePath)
                   .Select(p => matcher.Match(p))
                   .Where(m => m.Success)
                   .Select(m => int.Parse(m.Groups[group].Value))
                   .Distinct()
                   .OrderBy(x => x));
        }