private static void set_licensed_options(ChocolateyConfiguration config, ChocolateyLicense license, ConfigFileSettings configFileSettings) { config.Information.IsLicensedVersion = license.is_licensed_version(); config.Information.LicenseType = license.LicenseType.get_description_or_value(); if (license.AssemblyLoaded) { Type licensedConfigBuilder = license.Assembly.GetType(ApplicationParameters.LicensedConfigurationBuilder, throwOnError: false, ignoreCase: true); if (licensedConfigBuilder == null) { if (config.RegularOutput) { "chocolatey".Log().Warn(ChocolateyLoggers.Important, @"Unable to set licensed configuration. Please upgrade to a newer licensed version (choco upgrade chocolatey.extension)."); } return; } try { object componentClass = Activator.CreateInstance(licensedConfigBuilder); licensedConfigBuilder.InvokeMember( SET_CONFIGURATION_METHOD, BindingFlags.InvokeMethod, null, componentClass, new Object[] { config, configFileSettings } ); } catch (Exception ex) { var isDebug = ApplicationParameters.is_debug_mode_cli_primitive(); if (config.Debug) { isDebug = true; } var message = isDebug ? ex.ToString() : ex.Message; if (isDebug && ex.InnerException != null) { message += "{0}{1}".format_with(Environment.NewLine, ex.ToString()); } "chocolatey".Log().Error( ChocolateyLoggers.Important, @"Error when setting configuration for '{0}':{1} {2}".format_with( licensedConfigBuilder.FullName, Environment.NewLine, message )); } } }
private static void set_license_options(ChocolateyConfiguration config, ChocolateyLicense license) { config.Information.LicenseExpirationDate = license.ExpirationDate; config.Information.LicenseIsValid = license.IsValid; config.Information.LicenseVersion = license.Version ?? string.Empty; config.Information.LicenseType = license.is_licensed_version() ? license.LicenseType.get_description_or_value() : string.Empty; var licenseName = license.Name.to_string(); if (licenseName.Contains("@")) { licenseName = licenseName.Remove(licenseName.IndexOf("@", StringComparison.InvariantCulture)) + "[at REDACTED])"; } config.Information.LicenseUserName = licenseName; }
private static void set_licensed_options(ChocolateyConfiguration config, ChocolateyLicense license, ConfigFileSettings configFileSettings) { config.Information.IsLicensedVersion = license.is_licensed_version(); if (license.AssemblyLoaded) { Type licensedConfigBuilder = license.Assembly.GetType(ApplicationParameters.LicensedConfigurationBuilder, throwOnError: false, ignoreCase: true); if (licensedConfigBuilder == null) { if (config.RegularOutput) { "chocolatey".Log().Warn(ChocolateyLoggers.Important, @"Unable to set licensed configuration. Please upgrade to a newer licensed version."); } return; } try { object componentClass = Activator.CreateInstance(licensedConfigBuilder); licensedConfigBuilder.InvokeMember( SET_CONFIGURATION_METHOD, BindingFlags.InvokeMethod, null, componentClass, new Object[] { config, configFileSettings } ); } catch (Exception ex) { "chocolatey".Log().Error( ChocolateyLoggers.Important, @"Error when setting configuration for '{0}':{1} {2}".format_with( licensedConfigBuilder.FullName, Environment.NewLine, ex.Message )); } } }
private static void set_licensed_options(ChocolateyConfiguration config, ChocolateyLicense license, ConfigFileSettings configFileSettings) { config.Information.IsLicensedVersion = license.is_licensed_version(); config.Information.LicenseType = license.LicenseType.get_description_or_value(); if (license.AssemblyLoaded) { Type licensedConfigBuilder = license.Assembly.GetType(ApplicationParameters.LicensedConfigurationBuilder, throwOnError: false, ignoreCase: true); if (licensedConfigBuilder == null) { if (config.RegularOutput) "chocolatey".Log().Warn(ChocolateyLoggers.Important, @"Unable to set licensed configuration. Please upgrade to a newer licensed version."); return; } try { object componentClass = Activator.CreateInstance(licensedConfigBuilder); licensedConfigBuilder.InvokeMember( SET_CONFIGURATION_METHOD, BindingFlags.InvokeMethod, null, componentClass, new Object[] { config, configFileSettings } ); } catch (Exception ex) { "chocolatey".Log().Error( ChocolateyLoggers.Important, @"Error when setting configuration for '{0}':{1} {2}".format_with( licensedConfigBuilder.FullName, Environment.NewLine, ex.Message )); } } }
// ReSharper disable InconsistentNaming private static void Main(string[] args) // ReSharper restore InconsistentNaming { ChocolateyConfiguration config = null; ChocolateyLicense license = null; try { add_assembly_resolver(); string loggingLocation = ApplicationParameters.LoggingLocation; //no file system at this point if (!Directory.Exists(loggingLocation)) { Directory.CreateDirectory(loggingLocation); } Log4NetAppenderConfiguration.configure(loggingLocation, excludeLoggerNames: ChocolateyLoggers.Trace.to_string()); Bootstrap.initialize(); Bootstrap.startup(); license = License.validate_license(); var container = SimpleInjectorContainer.Container; "LogFileOnly".Log().Info(() => "".PadRight(60, '=')); config = Config.get_configuration_settings(); var fileSystem = container.GetInstance <IFileSystem>(); var warnings = new List <string>(); ConfigurationBuilder.set_up_configuration( args, config, container, license, warning => { warnings.Add(warning); } ); if (license.is_licensed_version() && !license.IsCompatible && !config.DisableCompatibilityChecks) { write_warning_for_incompatible_versions(); } if (config.Features.LogWithoutColor) { ApplicationParameters.Log4NetConfigurationResource = @"chocolatey.infrastructure.logging.log4net.nocolor.config.xml"; Log4NetAppenderConfiguration.configure(loggingLocation, excludeLoggerNames: ChocolateyLoggers.Trace.to_string()); } if (!string.IsNullOrWhiteSpace(config.AdditionalLogFileLocation)) { Log4NetAppenderConfiguration.configure_additional_log_file(fileSystem.get_full_path(config.AdditionalLogFileLocation)); } report_version_and_exit_if_requested(args, config); trap_exit_scenarios(config); warn_on_nuspec_or_nupkg_usage(args, config); if (config.RegularOutput) { #if DEBUG "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} v{1}{2} (DEBUG BUILD)".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion, license.is_licensed_version() ? " {0}".format_with(license.LicenseType) : string.Empty)); #else "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} v{1}{2}".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion, license.is_licensed_version() ? " {0}".format_with(license.LicenseType) : string.Empty)); #endif if (args.Length == 0) { "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "Please run 'choco -?' or 'choco <command> -?' for help menu."); } } if (warnings.Count != 0 && config.RegularOutput) { foreach (var warning in warnings.or_empty_list_if_null()) { "chocolatey".Log().Warn(ChocolateyLoggers.Important, warning); } } if (config.HelpRequested || config.UnsuccessfulParsing) { pause_execution_if_debug(); Environment.Exit(config.UnsuccessfulParsing ? 1 : 0); } var verboseAppenderName = "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()); var traceAppenderName = "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Trace.to_string()); Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug, verboseAppenderName, traceAppenderName); Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, config.Debug, verboseAppenderName); Log4NetAppenderConfiguration.set_trace_logger_when_trace(config.Trace, traceAppenderName); "chocolatey".Log().Debug(() => "{0} is running on {1} v {2}".format_with(ApplicationParameters.Name, config.Information.PlatformType, config.Information.PlatformVersion.to_string())); //"chocolatey".Log().Debug(() => "Command Line: {0}".format_with(Environment.CommandLine)); remove_old_chocolatey_exe(fileSystem); AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(Program)), ApplicationParameters.InstallLocation, new List <string>(), "chocolatey.console", throwError: false); //refactor - thank goodness this is temporary, cuz manifest resource streams are dumb IList <string> folders = new List <string> { "helpers", "functions", "redirects", "tools" }; #if !NoResources AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(ChocolateyResourcesAssembly)), ApplicationParameters.InstallLocation, folders, ApplicationParameters.ChocolateyFileResources, throwError: false); #endif var application = new ConsoleApplication(); application.run(args, config, container); } catch (Exception ex) { if (ApplicationParameters.is_debug_mode_cli_primitive()) { "chocolatey".Log().Error(() => "{0} had an error occur:{1}{2}".format_with( ApplicationParameters.Name, Environment.NewLine, ex.ToString())); } else { "chocolatey".Log().Error(ChocolateyLoggers.Important, () => "{0}".format_with(ex.Message)); "chocolatey".Log().Error(ChocolateyLoggers.LogFileOnly, () => "More Details: {0}".format_with(ex.ToString())); } if (Environment.ExitCode == 0) { Environment.ExitCode = 1; } } finally { if (license != null && license.is_licensed_version() && !license.IsCompatible && config != null && !config.DisableCompatibilityChecks) { write_warning_for_incompatible_versions(); } "chocolatey".Log().Debug(() => "Exiting with {0}".format_with(Environment.ExitCode)); #if DEBUG "chocolatey".Log().Info(() => "Exiting with {0}".format_with(Environment.ExitCode)); #endif pause_execution_if_debug(); Bootstrap.shutdown(); Environment.Exit(Environment.ExitCode); } }