public Task <List <ProjectFile> > GetProjectFilesAsync(string path, CancellationToken cancellationToken) { var task = Task.Run(async() => { var files = SearchProjectFiles(path, cancellationToken); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var imageService = await _package.GetServiceAsync(typeof(SVsImageService)) as IVsImageService2; var fileMonikers = new Dictionary <string, ImageMoniker>(); var projectFiles = new List <ProjectFile>(); foreach (var file in files) { cancellationToken.ThrowIfCancellationRequested(); var extension = Path.GetExtension(file); if (!fileMonikers.TryGetValue(extension, out var moniker)) { moniker = imageService?.GetImageMonikerForFile(file) ?? KnownMonikers.AddDocument; fileMonikers[extension] = moniker; } var project = ProjectFile.FromFile(file, moniker); projectFiles.Add(project); } return(projectFiles); }, cancellationToken); return(task); }
private static int Compile(string input, string outputPath) { string intermediateDirectory = Path.Combine(Path.GetDirectoryName(input), ".peu", Path.GetFileNameWithoutExtension(input)); string logPath = Path.Combine(intermediateDirectory, "compile.log"); ErrorCollection errors = new ErrorCollection(); ProjectFile project = ProjectFile.FromFile(input, errors); if (AssertErrors()) { return(1); } ProjectCompiler compiler = ProjectCompiler.Create ( project, intermediateDirectory, outputPath, errors ); compiler.Compile(); if (AssertErrors()) { return(1); } try { errors.WriteToConsole(); errors.ToFile(logPath); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Successfully compiled " + Path.GetFileName(outputPath) + " (" + new FileInfo(outputPath).Length + " bytes)."); } finally { Console.ResetColor(); Console.WriteLine(); } return(0); bool AssertErrors() { if (errors.HasErrors) { errors.WriteToConsole(); Directory.CreateDirectory(Path.GetDirectoryName(logPath)); errors.ToFile(logPath); return(true); } else { return(false); } } }