Esempio n. 1
0
        /// <summary>
        /// Activates the license.
        /// </summary>
        /// <param name="licenseCode">The license code.</param>
        /// <returns></returns>
        public static bool ActivateLicense(string licenseCode)
        {
            try
            {
                var validator = new LicenseValidation();

                var codebase     = Assembly.GetExecutingAssembly().CodeBase;
                var uri          = new UriBuilder(codebase);
                var path         = Uri.UnescapeDataString(uri.Path);
                var assemblyPath = Path.GetDirectoryName(path);

                var licenseFilePath = Path.Combine(assemblyPath, Strings.LicenseFileName);

                var lqr = validator.ValidateLicense(licenseCode, Strings.ApplicationId);

                if (lqr.ValidLicense)
                {
                    validator.CreateLicense(new FileInfo(licenseFilePath), licenseCode);
                }

                return(lqr.ValidLicense);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the license.
        /// </summary>
        /// <returns></returns>
        private static LicenseQueryResult ValidateLicense()
        {
            try
            {
                var validator = new LicenseValidation();

                var codebase     = Assembly.GetExecutingAssembly().CodeBase;
                var uri          = new UriBuilder(codebase);
                var path         = Uri.UnescapeDataString(uri.Path);
                var assemblyPath = Path.GetDirectoryName(path);

                var licenseFilePath = Path.Combine(assemblyPath, Strings.LicenseFileName);

                var lqr = validator.ValidateLicense(new FileInfo(licenseFilePath), Strings.ApplicationId);

                if (!lqr.ValidLicense)
                {
                    // if first use (no license file exists), will auto generate a trial license for the product
                    validator.CreateLicense(new FileInfo(licenseFilePath), Strings.TrialCode);
                    lqr = validator.ValidateLicense(new FileInfo(licenseFilePath), Strings.ApplicationId);
                }

                return(lqr);
            }
            catch (Exception)
            {
                return(new LicenseQueryResult()
                {
                    CurrentLicenseStatus = LicenseStatus.InValid
                });
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GetChocolatey"/> class.
 /// </summary>
 public GetChocolatey()
 {
     Log4NetAppenderConfiguration.configure();
     Bootstrap.initialize();
     _license   = LicenseValidation.validate();
     _container = SimpleInjectorContainer.Container;
 }
        public async Task <HttpResponseMessage> Validate([FromBody] LicenseValidation licenseValidation)
        {
            Argument.IsNotNull(() => licenseValidation);

            var licenseValidationResult = await _licenseValidationService.ValidateLicenseAsync(licenseValidation.License);

            return(new HttpResponseMessage
            {
                Content = new JsonContent(licenseValidationResult)
            });
        }
Esempio n. 5
0
// ReSharper disable InconsistentNaming
        private static void Main(string[] args)
// ReSharper restore InconsistentNaming
        {
            try
            {
                string loggingLocation = ApplicationParameters.LoggingLocation;
                //no file system at this point
                if (!Directory.Exists(loggingLocation))
                {
                    Directory.CreateDirectory(loggingLocation);
                }

                Log4NetAppenderConfiguration.configure(loggingLocation);
                Bootstrap.initialize();
                Bootstrap.startup();

                var container  = SimpleInjectorContainer.Container;
                var config     = container.GetInstance <ChocolateyConfiguration>();
                var fileSystem = container.GetInstance <IFileSystem>();

                var warnings = new List <string>();

                ConfigurationBuilder.set_up_configuration(
                    args,
                    config,
                    fileSystem,
                    container.GetInstance <IXmlService>(),
                    warning => { warnings.Add(warning); }
                    );
                Config.initialize_with(config);

                report_version_and_exit_if_requested(args, config);

                trap_exit_scenarios(config);

                if (config.RegularOutput)
                {
                    "logfile".Log().Info(() => "".PadRight(60, '='));
#if DEBUG
                    "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} v{1} (DEBUG BUILD)".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion));
#else
                    "chocolatey".Log().Info(ChocolateyLoggers.Important, () => "{0} v{1}".format_with(ApplicationParameters.Name, config.Information.ChocolateyProductVersion));
#endif
                }


                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)
                {
                    pause_execution_if_debug();
                    Environment.Exit(-1);
                }

                Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, ChocolateyLoggers.Verbose.to_string());
                Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug);
                "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));

                warn_when_admin_needs_elevation(config);
                remove_old_chocolatey_exe(fileSystem);

                LicenseValidation.validate(fileSystem);

                //refactor - thank goodness this is temporary, cuz manifest resource streams are dumb
                IList <string> folders = new List <string>
                {
                    "helpers",
                    "functions",
                    "redirects",
                    "tools"
                };
                AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(ChocolateyResourcesAssembly)), ApplicationParameters.InstallLocation, folders, ApplicationParameters.ChocolateyFileResources);

                var application = new ConsoleApplication();
                application.run(args, config, container);
            }
            catch (Exception ex)
            {
                var debug = false;
                // no access to the good stuff here, need to go a bit primitive in parsing args
                foreach (var arg in args.or_empty_list_if_null())
                {
                    if (arg.Contains("debug") || arg.is_equal_to("-d") || arg.is_equal_to("/d"))
                    {
                        debug = true;
                        break;
                    }
                }

                if (debug)
                {
                    "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));
                }

                Environment.ExitCode = 1;
            }
            finally
            {
                "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);
            }
        }
Esempio n. 6
0
        // ReSharper disable InconsistentNaming
        private static void Main(string[] args)
        // ReSharper restore InconsistentNaming
        {
            try
            {
                string loggingLocation = ApplicationParameters.LoggingLocation;
                //no file system at this point
                if (!Directory.Exists(loggingLocation))
                {
                    Directory.CreateDirectory(loggingLocation);
                }

                Log4NetAppenderConfiguration.configure(loggingLocation);
                Bootstrap.initialize();
                Bootstrap.startup();

                var license = LicenseValidation.validate();
                if (license.is_licensed_version())
                {
                    try
                    {
                        var licensedAssembly = Assembly.LoadFile(ApplicationParameters.LicensedAssemblyLocation);
                        license.AssemblyLoaded = true;
                        license.Assembly       = licensedAssembly;
                        license.Version        = VersionInformation.get_current_informational_version(licensedAssembly);
                        Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: false, ignoreCase: true);
                        SimpleInjectorContainer.add_component_registry_class(licensedComponent);
                    }
                    catch (Exception ex)
                    {
                        "chocolatey".Log().Error(
                            @"Error when attempting to load chocolatey licensed assembly. Ensure
 that chocolatey.licensed.dll exists at 
 '{0}'.
 The error message itself may be helpful as well:{1} {2}".format_with(
                                ApplicationParameters.LicensedAssemblyLocation,
                                Environment.NewLine,
                                ex.Message
                                ));
                    }
                }
                var container = SimpleInjectorContainer.Container;

                var config     = container.GetInstance <ChocolateyConfiguration>();
                var fileSystem = container.GetInstance <IFileSystem>();

                var warnings = new List <string>();

                ConfigurationBuilder.set_up_configuration(
                    args,
                    config,
                    container,
                    license,
                    warning => { warnings.Add(warning); }
                    );
                Config.initialize_with(config);

                report_version_and_exit_if_requested(args, config);

                trap_exit_scenarios(config);

                if (config.RegularOutput)
                {
                    "logfile".Log().Info(() => "".PadRight(60, '='));
#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
                    if (config.Information.ChocolateyVersion == config.Information.ChocolateyProductVersion && args.Any())
                    {
                        "logfile".Log().Info(() => "{0} v{1}{2}".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 (warnings.Count != 0 && config.RegularOutput)
                {
                    foreach (var warning in warnings.or_empty_list_if_null())
                    {
                        "chocolatey".Log().Warn(ChocolateyLoggers.Important, warning);
                    }
                }

                if (config.HelpRequested)
                {
                    pause_execution_if_debug();
                    Environment.Exit(-1);
                }

                Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug, excludeLoggerName: "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
                Log4NetAppenderConfiguration.set_verbose_logger_when_verbose(config.Verbose, config.Debug, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));
                "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);

                //refactor - thank goodness this is temporary, cuz manifest resource streams are dumb
                IList <string> folders = new List <string>
                {
                    "helpers",
                    "functions",
                    "redirects",
                    "tools"
                };
                AssemblyFileExtractor.extract_all_resources_to_relative_directory(fileSystem, Assembly.GetAssembly(typeof(ChocolateyResourcesAssembly)), ApplicationParameters.InstallLocation, folders, ApplicationParameters.ChocolateyFileResources);

                var application = new ConsoleApplication();
                application.run(args, config, container);
            }
            catch (Exception ex)
            {
                var debug = false;
                // no access to the good stuff here, need to go a bit primitive in parsing args
                foreach (var arg in args.or_empty_list_if_null())
                {
                    if (arg.Contains("debug") || arg.is_equal_to("-d") || arg.is_equal_to("/d"))
                    {
                        debug = true;
                        break;
                    }
                }

                if (debug)
                {
                    "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));
                }

                Environment.ExitCode = 1;
            }
            finally
            {
                "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);
            }
        }
Esempio n. 7
0
 public LicenseValidationTests()
 {
     licenseValidation = new LicenseValidation();
 }