public void Main(string[] args) { var matcher = new Matcher(); matcher.AddInclude(@"**\*.cs"); matcher.AddExclude(OutputFileName); var inputFiles = new List<string>(); var latestChange = DateTime.MinValue; foreach (var f in matcher.GetResultsInFullPath(_projectDir)) { inputFiles.Add(f); var change = File.GetLastWriteTimeUtc(f); if (change > latestChange) latestChange = change; } var outputFile = Path.Combine(_projectDir, OutputFileName); if (!File.Exists(outputFile) || latestChange > File.GetLastWriteTimeUtc(outputFile)) { Console.WriteLine("Rewriting async methods in " + _projectDir); var asyncCode = new Rewriter().RewriteAndMerge(inputFiles.ToArray()); File.WriteAllText(outputFile, asyncCode); } else { Console.WriteLine("Skipping async rewriting, generated code up to date"); } }
public static IEnumerable <(string Path, string Stem)> GetFileList(string basedir, string[] includes, string[] excludes, bool ignoreCase) { var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture); if (excludes != null) { foreach (var exclude in excludes) { matcher.AddExclude(exclude); } } if (includes != null && includes.Length != 0) { foreach (var include in includes) { matcher.AddInclude(include); } } else { matcher.AddInclude("**/*"); } var di = new DirectoryInfo(basedir); var diwrapper = new DirectoryInfoWrapper(di); var result = matcher.Execute(diwrapper); if (!result.HasMatches) { return(Array.Empty <(string, string)>()); } else { return(result.Files.Select(x => (x.Path, x.Stem))); } }
/// <summary> /// Adds multiple exclude patterns to <see cref="Matcher" />. <seealso cref="Matcher.AddExclude(string)" /> /// </summary> /// <param name="matcher">The matcher to which the exclude patterns are added</param> /// <param name="excludePatternsGroups">A list of globbing patterns</param> public static void AddExcludePatterns(this Matcher matcher, params IEnumerable <string>[] excludePatternsGroups) { foreach (IEnumerable <string> group in excludePatternsGroups) { foreach (string pattern in group) { matcher.AddExclude(pattern); } } }
public Listener(StreamJsonRpc.JsonRpc rpc, IVsFolderWorkspaceService workspaceService, IServiceProvider site) { this._rpc = rpc; this._rpc.Disconnected += _rpc_Disconnected; // Ignore some common directories _matcher.AddExclude("**/.vs/**/*.*"); // Ignore files that end with ~ or TMP _matcher.AddExclude("**/*~"); _matcher.AddExclude("**/*TMP"); // Depending upon if this is a workspace or a solution, listen to different change events. if (workspaceService != null && workspaceService.CurrentWorkspace != null) { workspaceService.CurrentWorkspace.GetService <IFileWatcherService>().OnFileSystemChanged += OnFileChanged; _root = workspaceService.CurrentWorkspace.Location; } else { var path = GetSolutionDirectory(site); if (path != null) { _solutionWatcher = new System.IO.FileSystemWatcher(); _solutionWatcher.Path = path; _solutionWatcher.IncludeSubdirectories = true; _solutionWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.Size; _solutionWatcher.Changed += OnFileChanged_Sync; _solutionWatcher.Created += OnFileChanged_Sync; _solutionWatcher.Deleted += OnFileChanged_Sync; _solutionWatcher.Renamed += OnFileChanged_Sync; _solutionWatcher.EnableRaisingEvents = true; _root = _solutionWatcher.Path; } } }
// Initially based on code from Reliak.FileSystemGlobbingExtensions (https://github.com/reliak/Reliak.FileSystemGlobbingExtensions) public static IEnumerable<IFile> GetFiles(IDirectory directory, IEnumerable<string> patterns) { Matcher matcher = new Matcher(StringComparison.Ordinal); // Expand braces IEnumerable<string> expandedPatterns = patterns .SelectMany(ExpandBraces) .Select(f => f.Replace("\\{", "{").Replace("\\}", "}")); // Unescape braces // Add the patterns, any that start with ! are exclusions foreach (string expandedPattern in expandedPatterns) { bool isExclude = expandedPattern[0] == '!'; string finalPattern = isExclude ? expandedPattern.Substring(1) : expandedPattern; finalPattern = finalPattern .Replace("\\!", "!") // Unescape negation .Replace("\\", "/"); // Normalize slashes // No support for absolute paths if (System.IO.Path.IsPathRooted(finalPattern)) { throw new ArgumentException($"Rooted globbing patterns are not supported ({expandedPattern})", nameof(patterns)); } // Add exclude or include pattern to matcher if (isExclude) { matcher.AddExclude(finalPattern); } else { matcher.AddInclude(finalPattern); } } DirectoryInfoBase directoryInfo = new DirectoryInfo(directory); PatternMatchingResult result = matcher.Execute(directoryInfo); return result.Files.Select(match => directory.GetFile(match.Path)); }
/// <summary> /// Enumerate all the PowerShell (ps1, psm1, psd1) files in the workspace in a recursive manner. /// </summary> /// <returns>An enumerator over the PowerShell files found in the workspace.</returns> public IEnumerable <string> EnumeratePSFiles( string[] excludeGlobs, string[] includeGlobs, int maxDepth, bool ignoreReparsePoints ) { if (WorkspacePath == null || !Directory.Exists(WorkspacePath)) { yield break; } var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher(); foreach (string pattern in includeGlobs) { matcher.AddInclude(pattern); } foreach (string pattern in excludeGlobs) { matcher.AddExclude(pattern); } var fsFactory = new WorkspaceFileSystemWrapperFactory( WorkspacePath, maxDepth, Utils.IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework, ignoreReparsePoints, logger ); var fileMatchResult = matcher.Execute(fsFactory.RootDirectory); foreach (FilePatternMatch item in fileMatchResult.Files) { yield return(Path.Combine(WorkspacePath, item.Path)); } }