Esempio n. 1
0
        private static IFileInfo[] GetFiles(
            IEnumerable <string> includes,
            IEnumerable <string> excludes,
            IDirectoryInfo parentDir)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (var include in includes)
            {
                matcher.AddInclude(include);
            }

            foreach (var exclude in excludes)
            {
                matcher.AddExclude(exclude);
            }

            var fileMatchResult =
                matcher.Execute(
                    new Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper(
                        new DirectoryInfo(parentDir.FullName)));

            return(fileMatchResult.Files
                   .Select(f =>
                           parentDir.FileSystem.FileInfo.FromFileName(
                               Path.GetFullPath(Path.Combine(
                                                    parentDir?.ToString() ?? throw new InvalidOperationException("Could not find path."),
                                                    f.Path))))
                   .ToArray());
        }
Esempio n. 2
0
        private static string[] GetFiles(CommandOption includeOption, CommandOption excludeOption, string defaultInclude)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            if (includeOption.HasValue())
            {
                foreach (var include in includeOption.Values)
                {
                    matcher.AddInclude(include);
                }
            }
            else if (!string.IsNullOrEmpty(defaultInclude))
            {
                matcher.AddInclude(defaultInclude);
            }

            foreach (var exclude in excludeOption.Values)
            {
                matcher.AddExclude(exclude);
            }

            var currentDirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
            var directoryInfoWrapper = new DirectoryInfoWrapper(currentDirectoryInfo);

            var fileMatchResult = matcher.Execute(directoryInfoWrapper);

            return(fileMatchResult.Files.Select(f => Path.GetFullPath(f.Path)).ToArray());
        }
Esempio n. 3
0
        public async ValueTask <IFileReference[]> ListAsync(string path, string searchPattern, bool recursive, bool withMetadata)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                path = null;
            }
            else
            {
                if (!path.EndsWith("/"))
                {
                    path = path + "/";
                }
            }

            string prefix        = path;
            var    firstWildCard = searchPattern.IndexOf('*');

            if (firstWildCard >= 0)
            {
                prefix       += searchPattern.Substring(0, firstWildCard);
                searchPattern = searchPattern.Substring(firstWildCard);
            }

            Microsoft.Extensions.FileSystemGlobbing.Matcher matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(StringComparison.Ordinal);
            matcher.AddInclude(searchPattern);

            var operationContext = new OperationContext();
            BlobContinuationToken continuationToken = null;
            List <IListBlobItem>  results           = new List <IListBlobItem>();

            do
            {
                var response = await this.container.Value.ListBlobsSegmentedAsync(prefix, recursive, withMetadata?BlobListingDetails.Metadata : BlobListingDetails.None, null, continuationToken, new BlobRequestOptions(), new OperationContext());

                continuationToken = response.ContinuationToken;
                results.AddRange(response.Results);
            }while (continuationToken != null);

            var pathMap = results.OfType <ICloudBlob>()
                          .Select(blob => new Internal.AzureFileReference(blob, withMetadata: withMetadata))
                          .ToDictionary(x => Path.GetFileName(x.Path));

            var filteredResults = matcher.Execute(new Internal.AzureListDirectoryWrapper(path, pathMap));

            return(filteredResults.Files.Select(x => pathMap[x.Path]).ToArray());
        }
        public Task <IFileReference[]> ListAsync(string path, string searchPattern, bool recursive, bool withMetadata)
        {
            var directoryPath = (string.IsNullOrEmpty(path) || path == "/" || path == "\\") ? this.absolutePath : Path.Combine(this.absolutePath, path);

            if (!Directory.Exists(directoryPath))
            {
                return(Task.FromResult(new IFileReference[0]));
            }

            Microsoft.Extensions.FileSystemGlobbing.Matcher matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(StringComparison.Ordinal);
            matcher.AddInclude(searchPattern);

            var results = matcher.Execute(new Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));

            return(Task.FromResult(results.Files
                                   .Select(match => (IFileReference) new Internal.FileSystemFileReference(Path.Combine(directoryPath, match.Path), Path.Combine(path, match.Path).Trim('/', '\\'), this.Name, this.publicUrlProvider))
                                   .ToArray()));
        }
Esempio n. 5
0
        public static ICollection <string> Execute(string dir, string[] includes, string[] excludes)
        {
            var dirInfo        = new DirectoryInfo(dir);
            var dirInfoWrapper = new DirectoryInfoWrapper(dirInfo);

            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (var incl in includes ?? new string[0])
            {
                matcher.AddInclude(incl);
            }
            foreach (var excl in excludes ?? new string[0])
            {
                matcher.AddExclude(excl);
            }

            var result = matcher.Execute(dirInfoWrapper);

            return(result.Files
                   .Select(f => Path.Combine(dir, f.Path))
                   .ToList()
                   );
        }
        public async ValueTask<IFileReference[]> ListAsync(string path, string searchPattern, bool recursive, bool withMetadata)
        {
            var directoryPath = (string.IsNullOrEmpty(path) || path == "/" || path == "\\") ? this.AbsolutePath : Path.Combine(this.AbsolutePath, path);

            var result = new List<IFileReference>();
            if (Directory.Exists(directoryPath))
            {
                var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(StringComparison.Ordinal);
                matcher.AddInclude(searchPattern);

                var matches = matcher.Execute(new Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));
                var allResultPaths = matches.Files
                    .Select(match => Path.Combine(path, match.Path).Trim('/', '\\'))
                    .ToList();

                foreach (var resultPath in allResultPaths)
                {
                    result.Add(await this.InternalGetAsync(resultPath, withMetadata));
                }
            }

            return result.ToArray();
        }
Esempio n. 7
0
        private static FileInfo[] GetFiles(
            IEnumerable <string> includes,
            IEnumerable <string> excludes,
            DirectoryInfo parentDir)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (var include in includes)
            {
                matcher.AddInclude(include);
            }

            foreach (var exclude in excludes)
            {
                matcher.AddExclude(exclude);
            }

            var fileMatchResult = matcher.Execute(new DirectoryInfoWrapper(parentDir));

            return(fileMatchResult.Files
                   .Select(f => new FileInfo(Path.GetFullPath(Path.Combine(parentDir.ToString(), f.Path))))
                   .ToArray());
        }
 public static void AddIncludePatterns(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, params System.Collections.Generic.IEnumerable <string>[] includePatternsGroups)
 {
 }
 public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, string file)
 {
     throw null;
 }
 public static Microsoft.Extensions.FileSystemGlobbing.PatternMatchingResult Match(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string rootDir, System.Collections.Generic.IEnumerable <string>?files)
 {
     throw null;
 }
 public static System.Collections.Generic.IEnumerable <string> GetResultsInFullPath(this Microsoft.Extensions.FileSystemGlobbing.Matcher matcher, string directoryPath)
 {
     throw null;
 }