示例#1
0
        /// <summary>
        /// Is called, if specified command line arguments have successfully been validated.
        /// </summary>
        /// <param name="options">Command line options.</param>
        /// <returns>Exit code the application should return.</returns>
        private static ExitCode RunOptionsAndReturnExitCode(Options options)
        {
            // configure the log verbosity
            var configuration = new VolatileLogConfiguration();

            configuration.AddLogWriterDefault(x => x.WithBaseLevel(options.Verbose ? LogLevel.All: LogLevel.Note));
            Log.Configuration = configuration;

            sLog.Write(LogLevel.Developer, "LicenseCollector v{0}", Assembly.GetExecutingAssembly().GetName().Version);
            sLog.Write(LogLevel.Developer, "--------------------------------------------------------------------------------");
            sLog.Write(LogLevel.Developer, "Verbose:            '{0}'", options.Verbose);
            sLog.Write(LogLevel.Developer, "SolutionFile:       '{0}'", options.SolutionFilePath);
            sLog.Write(LogLevel.Developer, "Configuration:      '{0}'", options.Configuration);
            sLog.Write(LogLevel.Developer, "Platform:           '{0}'", options.Platform);
            sLog.Write(LogLevel.Developer, "SearchPattern:      '{0}'", options.SearchPattern);
            sLog.Write(LogLevel.Developer, "LicenseTemplatePath '{0}'", options.LicenseTemplatePath);
            sLog.Write(LogLevel.Developer, "OutputPath:         '{0}'", options.OutputLicensePath);
            sLog.Write(LogLevel.Developer, "--------------------------------------------------------------------------------");

            // the given path for the solution does not exist
            if (!File.Exists(options.SolutionFilePath))
            {
                sLog.Write(LogLevel.Error, "The path to the solution file under '{0}' does not exist.", options.SolutionFilePath);
                return(ExitCode.FileNotFound);
            }
            // the given path is not a solution file
            if (!Path.GetExtension(options.SolutionFilePath).Equals(".sln"))
            {
                sLog.Write(LogLevel.Error, "The path '{0}' is not a solution file.", options.SolutionFilePath);
                return(ExitCode.ArgumentError);
            }
            // convert given relative paths to absolute paths if necessary
            if (!Path.IsPathRooted(options.SolutionFilePath))
            {
                options.SolutionFilePath = Path.GetFullPath(options.SolutionFilePath);
            }
            if (!Path.IsPathRooted(options.OutputLicensePath))
            {
                options.OutputLicensePath = Path.GetFullPath(options.OutputLicensePath);
            }
            if (!string.IsNullOrEmpty(options.LicenseTemplatePath) && !Path.IsPathRooted(options.LicenseTemplatePath))
            {
                options.LicenseTemplatePath = Path.GetFullPath(options.LicenseTemplatePath);
            }

            var app = new AppCore(options.SolutionFilePath, options.Configuration, options.Platform,
                                  options.OutputLicensePath, options.SearchPattern, options.LicenseTemplatePath);

            try
            {
                app.CollectProjects();

                app.GetNuGetPackages();

                app.GetNuGetLicenseInfo();

                app.GetStaticLicenseInfo();

                app.GenerateOutputFileAsync().Wait();
            }
            catch (Exception ex)
            {
                sLog.Write(LogLevel.Error, "Caught exception during processing. Exception: {0}", ex);
                return(ExitCode.GeneralError);
            }

            return(ExitCode.Success);
        }
示例#2
0
        /// <summary>
        /// Is called, if specified command line arguments have successfully been validated.
        /// </summary>
        /// <param name="options">Command line options.</param>
        /// <returns>Exit code the application should return.</returns>
        private static ExitCode RunOptionsAndReturnExitCode(Options options)
        {
            // configure the log
            Log.Initialize <VolatileLogConfiguration>(
                configuration =>
            {
                configuration.AddLogWriterDefault(
                    config =>
                {
                    config.WithBaseLevel(options.Verbose ? LogLevel.All : LogLevel.Notice);
                });
            },
                builder => builder.Add <ConsoleWriterPipelineStage>(
                    "Console",
                    stage =>
            {
                var formatter = new TableMessageFormatter();
                formatter.AddTimestampColumn("yyyy-MM-dd HH:mm:ss.fff");
                formatter.AddLogLevelColumn();
                formatter.AddTextColumn();
                stage.Formatter = formatter;
            }));

            sLog.Write(LogLevel.Debug, "LicenseCollector v{0}", Assembly.GetExecutingAssembly().GetName().Version);
            sLog.Write(LogLevel.Debug, "--------------------------------------------------------------------------------");
            sLog.Write(LogLevel.Debug, "Verbose:            '{0}'", options.Verbose);
            sLog.Write(LogLevel.Debug, "SolutionFile:       '{0}'", options.SolutionFilePath);
            sLog.Write(LogLevel.Debug, "Configuration:      '{0}'", options.Configuration);
            sLog.Write(LogLevel.Debug, "Platform:           '{0}'", options.Platform);
            sLog.Write(LogLevel.Debug, "SearchPattern:      '{0}'", options.SearchPattern);
            sLog.Write(LogLevel.Debug, "LicenseTemplatePath '{0}'", options.LicenseTemplatePath);
            sLog.Write(LogLevel.Debug, "OutputPath:         '{0}'", options.OutputLicensePath);
            sLog.Write(LogLevel.Debug, "--------------------------------------------------------------------------------");

            // the given path for the solution does not exist
            if (!File.Exists(options.SolutionFilePath))
            {
                sLog.Write(LogLevel.Error, "The path to the solution file under '{0}' does not exist.", options.SolutionFilePath);
                return(ExitCode.FileNotFound);
            }

            // the given path is not a solution file
            if (!Path.GetExtension(options.SolutionFilePath).Equals(".sln"))
            {
                sLog.Write(LogLevel.Error, "The path '{0}' is not a solution file.", options.SolutionFilePath);
                return(ExitCode.ArgumentError);
            }

            // convert given relative paths to absolute paths if necessary
            if (!Path.IsPathRooted(options.SolutionFilePath))
            {
                options.SolutionFilePath = Path.GetFullPath(options.SolutionFilePath);
            }
            if (!Path.IsPathRooted(options.OutputLicensePath))
            {
                options.OutputLicensePath = Path.GetFullPath(options.OutputLicensePath);
            }
            if (!string.IsNullOrEmpty(options.LicenseTemplatePath) && !Path.IsPathRooted(options.LicenseTemplatePath))
            {
                options.LicenseTemplatePath = Path.GetFullPath(options.LicenseTemplatePath);
            }

            var app = new AppCore(
                options.SolutionFilePath,
                options.Configuration,
                options.Platform,
                options.OutputLicensePath,
                options.SearchPattern,
                options.LicenseTemplatePath);

            try
            {
                app.CollectProjects();

                app.GetNuGetPackages();

                app.GetNuGetLicenseInfo();

                app.GetStaticLicenseInfo();

                app.GenerateOutputFileAsync().Wait();
            }
            catch (Exception ex)
            {
                sLog.Write(LogLevel.Error, "Caught exception during processing. Exception: {0}", ex);
                return(ExitCode.GeneralError);
            }

            return(ExitCode.Success);
        }