Ejemplo n.º 1
0
        private IEnumerable <DirectoryInfo> JobsMatchingSegment(List <DirectoryInfo> nextSegmentRoots, DirectoryInfo directoryInfo, Segment segment)
        {
            switch (segment)
            {
            case DirectorySegment directorySegment:
                // consume DirectorySegment
                var pathJobs = (from directory in _options.GetDirectories(directoryInfo)
                                where directorySegment.MatchesSegment(directory.Name, _options.CaseSensitive)
                                select directory).ToArray();

                nextSegmentRoots.AddRange(pathJobs);

                return(_emptyPathJobArray);

            case DirectoryWildcard _:
            {
                // match zero path segments, consuming DirectoryWildcard
                nextSegmentRoots.Add(directoryInfo);

                // match consume 1 path segment but not the Wildcard
                return(_options.GetDirectories(directoryInfo));
            }

            default:
                return(_emptyPathJobArray);
            }
        }
Ejemplo n.º 2
0
        internal static IEnumerable <FileSystemInfo> Traverse(DirectoryInfo root, Segment[] segments, int segmentIndex,
                                                              TraverseOptions options)
        {
            if (segmentIndex == segments.Length)
            {
                return(options.EmitDirectories
                    ? Enumerable.Repeat <FileSystemInfo>(root, 1)
                    : emptyFileSystemInfoArray);
            }

            var segment = segments[segmentIndex];

            switch (segment)
            {
            case DirectorySegment directorySegment:
            {
                var filesToEmit =
                    (options.EmitFiles && segmentIndex == segments.Length - 1)
                                ? options.GetFiles(root).Where(file => directorySegment.MatchesSegment(file.Name, options.CaseSensitive)).Cast <FileSystemInfo>()
                                : emptyFileSystemInfoArray;

                var dirSegmentItems = from directory in options.GetDirectories(root)
                                      where directorySegment.MatchesSegment(directory.Name, options.CaseSensitive)
                                      from item in Traverse(directory, segments, segmentIndex + 1, options)
                                      select item;

                return(filesToEmit.Concat(dirSegmentItems));
            }

            case DirectoryWildcard _:
            {
                var filesToEmit =
                    (options.EmitFiles && segmentIndex == segments.Length - 1)
                                ? options.GetFiles(root).Cast <FileSystemInfo>()
                                : emptyFileSystemInfoArray;

                // match zero path segments, consuming DirectoryWildcard
                var zeroMatch = Traverse(root, segments, segmentIndex + 1, options);

                // match consume 1 path segment but not the Wildcard
                var files = from directory in options.GetDirectories(root)
                            from item in Traverse(directory, segments, segmentIndex, options)
                            select item;

                return(filesToEmit.Concat(zeroMatch).Concat(files));
            }

            default:
                return(emptyFileSystemInfoArray);
            }
        }