コード例 #1
0
ファイル: License.cs プロジェクト: yakhtarali/choco
        public static ChocolateyLicense validate_license()
        {
            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}'.
 Install with `choco install chocolatey.extension`.
 The error message itself may be helpful as well:{1} {2}".format_with(
                            ApplicationParameters.LicensedAssemblyLocation,
                            Environment.NewLine,
                            ex.Message
                            ));
                }
            }

            return(license);
        }
コード例 #2
0
ファイル: License.cs プロジェクト: stjordanis/choco
        public static ChocolateyLicense validate_license()
        {
            var license = LicenseValidation.validate();

            if (license.is_licensed_version())
            {
                try
                {
                    var licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, ApplicationParameters.OfficialChocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation);

#if !FORCE_CHOCOLATEY_OFFICIAL_KEY
                    if (licensedAssembly == null)
                    {
                        licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, ApplicationParameters.UnofficialChocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation);
                    }
#endif
                    if (licensedAssembly == null)
                    {
                        throw new ApplicationException("Unable to load licensed assembly.");
                    }
                    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:{1} {2}".format_with(
                            ApplicationParameters.LicensedAssemblyLocation,
                            Environment.NewLine,
                            ex.Message
                            ));
                    "chocolatey".Log().Warn(ChocolateyLoggers.Important, @" Install the Chocolatey Licensed Extension package with
 `choco install chocolatey.extension` to remove this license warning.
 TRIALS: If you have a trial license, you cannot use the above command
 as is and be successful. You need to download nupkgs from the links in
 the trial email as your license will not be registered on the licensed
 repository. Please reference
 https://chocolatey.org/docs/installation-licensed#how-do-i-install-the-trial-edition
 for specific instructions.");
                }
            }

            return(license);
        }
コード例 #3
0
        public static ChocolateyLicense validate_license()
        {
            var license = LicenseValidation.validate();

            if (license.is_licensed_version())
            {
                try
                {
#if FORCE_CHOCOLATEY_OFFICIAL_KEY
                    var chocolateyPublicKey = ApplicationParameters.OfficialChocolateyPublicKey;
#else
                    var chocolateyPublicKey = ApplicationParameters.UnofficialChocolateyPublicKey;
#endif
                    var licensedAssembly = AssemblyResolution.resolve_or_load_assembly(ApplicationParameters.LicensedChocolateyAssemblySimpleName, chocolateyPublicKey, ApplicationParameters.LicensedAssemblyLocation);

                    if (licensedAssembly == null)
                    {
                        throw new ApplicationException("Unable to load licensed assembly.");
                    }

                    license.AssemblyLoaded = true;
                    license.Assembly       = licensedAssembly;
                    license.Version        = VersionInformation.get_current_informational_version(licensedAssembly);

                    // The licensed assembly is installed, check its supported Chocolatey versions and/or the assembly
                    // version so we can attempt to determine whether it's compatible with this version of Chocolatey.
                    var minimumChocolateyVersionString = VersionInformation.get_minimum_chocolatey_version(licensedAssembly);
                    "chocolatey".Log().Debug("Minimum Chocolatey Version: '{0}'".format_with(minimumChocolateyVersionString));
                    var currentChocolateyVersionString = VersionInformation.get_current_assembly_version();
                    "chocolatey".Log().Debug("Current Chocolatey Version: '{0}'".format_with(currentChocolateyVersionString));
                    var currentChocolateyLicensedVersionString = VersionInformation.get_current_assembly_version(licensedAssembly);
                    "chocolatey".Log().Debug("Current Chocolatey Licensed Version: '{0}'".format_with(currentChocolateyLicensedVersionString));

                    var minimumChocolateyVersion         = new Version(minimumChocolateyVersionString);
                    var currentChocolateyVersion         = new Version(currentChocolateyVersionString);
                    var currentChocolateyLicensedVersion = new Version(currentChocolateyLicensedVersionString);

                    license.IsCompatible = true;

                    if (currentChocolateyVersion < minimumChocolateyVersion || (minimumChocolateyVersion == Version.Parse("1.0.0") && currentChocolateyLicensedVersion.Major < 4))
                    {
                        license.IsCompatible = false;
                    }

                    Type licensedComponent = licensedAssembly.GetType(ApplicationParameters.LicensedComponentRegistry, throwOnError: false, ignoreCase: true);
                    SimpleInjectorContainer.add_component_registry_class(licensedComponent);
                }
                catch (Exception ex)
                {
                    "chocolatey".Log().Error(
                        @"A valid Chocolatey license was found, but the chocolatey.licensed.dll assembly could not be loaded:
  {0}
Ensure that the chocolatey.licensed.dll exists at the following path:
 '{1}'".format_with(ex.Message, ApplicationParameters.LicensedAssemblyLocation));

                    "chocolatey".Log().Warn(
                        ChocolateyLoggers.Important,
                        @"To resolve this, install the Chocolatey Licensed Extension package with
 `choco install chocolatey.extension`");
                }
            }

            return(license);
        }