public static void Main(string[] args) { try { int exitCode = ExitCode.Ok; var options = new ProgamOptions(); if (Parser.Default.ParseArguments(args, options)) { if (options.ExecuteCommand == "project") { exitCode = CheckProject(options); } if (options.ExecuteCommand == "solution") { exitCode = CheckSolution(options); } } else { exitCode = ExitCode.Error; } Environment.Exit(exitCode); } catch (Exception exception) { Console.WriteLine("[ FATAL ] An unhandled {0} occured. Please see exception message below.", exception.GetType()); Console.WriteLine(exception.Message); } }
public static int CheckProject(ProgamOptions options) { var fileSystem = new FileSystem(); var globalReferencesRegistry = new ReferenceRegistry(); string[] projectFileNames = new string[0]; var severity = (ReportSeverity)Enum.Parse(typeof (ReportSeverity), options.Verbosity, true); if (!String.IsNullOrEmpty(options.GlobalReferencesFileName) && fileSystem.FileInfo.FromFileName(options.GlobalReferencesFileName).Exists) { globalReferencesRegistry = ReferenceRegistry.FromLinesInFile(options.GlobalReferencesFileName, fileSystem); } else if (options.GlobalReferences.Length > 0) { globalReferencesRegistry = ReferenceRegistry.FromReferenceNames(options.GlobalReferences); } if (!String.IsNullOrEmpty(options.ProjectFileNamesFile) && fileSystem.FileInfo.FromFileName(options.ProjectFileNamesFile).Exists) { projectFileNames = fileSystem.File.ReadAllLines(options.ProjectFileNamesFile); } else if (options.ProjectFileNames.Length > 0) { projectFileNames = options.ProjectFileNames; } var externalLibrariesDirectoryName = options.ExternalLibrariesDirectoryName; var integrity = new ProjectIntegrity(globalReferencesRegistry, externalLibrariesDirectoryName); bool hasError = projectFileNames .Select(projectFileName => OutputReports( integrity.Report(projectFileName), OutputProjectFileName, projectFileName, severity)) .Aggregate(false, (current, reports) => current || reports.Any(r => !r.IsOk)); if (!hasError && severity <= ReportSeverity.Error) { Console.WriteLine("[ Check ] All projects ok."); } return hasError ? ExitCode.Error : ExitCode.Ok; }
public static int CheckSolution(ProgamOptions options) { var integrity = new SolutionIntegrity(); var severity = (ReportSeverity)Enum.Parse(typeof(ReportSeverity), options.Verbosity, true); bool hasError = options.SolutionFileNames .Select(solutionFileName => OutputReports(integrity.Report(solutionFileName), OutputSolutionFileName, solutionFileName, severity)) .Aggregate(false, (current, reports) => current || reports.Any(r => !r.IsOk)); if (!hasError && severity <= ReportSeverity.Error) { Console.WriteLine("[ Check ] All solutions ok."); } return hasError ? ExitCode.Error : ExitCode.Ok; }