public override bool Execute() { Log.LogMessage($"Executing {nameof(GenerateEventSourceTask)} for project {ProjectFilePath}"); var projectEventSourceGenerator = new ProjectEventSourceGenerator(); projectEventSourceGenerator.SetLogMessage(m => Log.LogMessage(m)); projectEventSourceGenerator.SetLogWarning(w => Log.LogWarning(w)); projectEventSourceGenerator.SetLogError(e => Log.LogError(e)); var project = projectEventSourceGenerator.Run(ProjectFilePath, CscToolPath, saveChanges: true); Log.LogMessage($"Executed {nameof(GenerateEventSourceTask)} in {ProjectFilePath}"); return(true); }
static void Main(string[] args) { if (args == null || args.Length == 0) { LogMessage("Enter arguments for program:"); var line = Console.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { line = "-o -s -g"; } args = line.Split(' '); } var options = Parser.Default.ParseArguments <ConsoleOptions>(args); options.WithParsed(t => { if (t.Verbose) { LogMessage($"Filename: {t.ProjectFile}"); } if (t.ProjectFile == null) { var possibleProjectFiles = System.IO.Directory.GetFiles("*.csproj"); if (possibleProjectFiles.Any()) { t.ProjectFile = possibleProjectFiles.First(); } } if (!System.IO.File.Exists(t.ProjectFile)) { LogMessage($"The project file {t.ProjectFile} could not be found", EventLevel.Critical); return; } if (!System.IO.Path.IsPathRooted(t.ProjectFile)) { t.ProjectFile = PathExtensions.GetAbsolutePath(t.ProjectFile); } var projectFilePath = t.ProjectFile; var projectEventSourceGenerator = new ProjectEventSourceGenerator(); projectEventSourceGenerator.SetLogMessage(m => LogMessage(m, EventLevel.Informational)); projectEventSourceGenerator.SetLogWarning(w => LogMessage(w, EventLevel.Warning)); projectEventSourceGenerator.SetLogError(e => LogMessage(e, EventLevel.Error)); var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; var roslynDirectory = System.IO.Path.Combine(baseDirectory, "roslyn"); var project = projectEventSourceGenerator.Run(projectFilePath, roslynDirectory, t.SaveChanges, t.ForceUpdate); if (t.DisplayOutput) { foreach (var output in project.ProjectItems.OfType( ProjectItemType.EventSource, ProjectItemType.DefaultGeneratedEventSourceDefinition, ProjectItemType.EventSourceLoggerPartial, ProjectItemType.LoggerImplementation)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"".PadRight(40, '_')}"); Console.WriteLine($"{"".PadRight(40, '=')}"); Console.WriteLine($"File: {output.Name}"); Console.WriteLine($"{"".PadRight(40, '_')}"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output.Output); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"".PadRight(40, '_')}"); Console.WriteLine($"{"".PadRight(40, '=')}"); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"".PadRight(40, '_')}"); Console.WriteLine($"{"".PadRight(40, '=')}"); Console.WriteLine($"File: {projectFilePath}"); Console.WriteLine($"{"".PadRight(40, '_')}"); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"".PadRight(40, '_')}"); Console.WriteLine($"{"".PadRight(40, '=')}"); } if (t.GenerateSchema) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Generating JSON Schema"); var output = SchemaWriter.GenerateSchema(t.SaveChanges).GetAwaiter().GetResult(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"".PadRight(40, '_')}"); Console.WriteLine($"{"".PadRight(40, '=')}"); Console.WriteLine($"File: {output.Name}"); Console.WriteLine($"{"".PadRight(40, '_')}"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(output.Output); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"".PadRight(40, '_')}"); Console.WriteLine($"{"".PadRight(40, '=')}"); Console.WriteLine($"Done generating JSON Schema"); } }); Console.ReadKey(); }