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"); } }
private bool ScanForProjects() { _logger.LogInformation(string.Format("Scanning '{0}' for DNX projects", _env.Path)); var anyProjects = false; // Single project in this folder var projectInThisFolder = Path.Combine(_env.Path, "project.json"); if (File.Exists(projectInThisFolder)) { if (_context.TryAddProject(projectInThisFolder)) { _logger.LogInformation(string.Format("Found project '{0}'.", projectInThisFolder)); anyProjects = true; } } else { IEnumerable<string> paths; #if DNX451 if (_options.Projects != "**/project.json") { var matcher = new Matcher(); matcher.AddIncludePatterns(_options.Projects.Split(';')); paths = matcher.GetResultsInFullPath(_env.Path); } else { paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json"); } #else // The matcher works on CoreCLR but Omnisharp still targets aspnetcore50 instead of // dnxcore50 paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json"); #endif foreach (var path in paths) { string projectFile = null; if (Path.GetFileName(path) == "project.json") { projectFile = path; } else { projectFile = Path.Combine(path, "project.json"); if (!File.Exists(projectFile)) { projectFile = null; } } if (string.IsNullOrEmpty(projectFile)) { continue; } if (!_context.TryAddProject(projectFile)) { continue; } _logger.LogInformation(string.Format("Found project '{0}'.", projectFile)); anyProjects = true; } } return anyProjects; }
public string CompressDirectory(string path, Matcher matcher, IProgress<string> progress, CancellationToken ct) { string zipFilePath = Path.GetTempFileName(); using (FileStream zipStream = new FileStream(zipFilePath, FileMode.Create)) using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create)) { Queue<string> dirs = new Queue<string>(); dirs.Enqueue(path); while (dirs.Count > 0) { var dir = dirs.Dequeue(); var subdirs = Directory.GetDirectories(dir); foreach(var subdir in subdirs) { dirs.Enqueue(subdir); } var files = matcher.GetResultsInFullPath(dir); foreach (var file in files) { if (ct.IsCancellationRequested) { return string.Empty; } progress?.Report(file); string entryName = file.MakeRelativePath(dir).Replace('\\', '/'); archive.CreateEntryFromFile(file, entryName); } } } return zipFilePath; }