Example #1
0
        public static ChocolateyLicense validate()
        {
            var chocolateyLicense = new ChocolateyLicense
            {
                LicenseType = ChocolateyLicenseType.Unknown
            };

            string licenseFile = ApplicationParameters.LicenseFileLocation;

            //no file system at this point
            if (File.Exists(licenseFile))
            {
                var license = new LicenseValidator(PUBLIC_KEY, licenseFile);

                try
                {
                    license.AssertValidLicense();
                    chocolateyLicense.IsValid = true;
                }
                catch (Exception e)
                {
                    //license may be invalid
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
                }

                switch (license.LicenseType)
                {
                case LicenseType.Professional:
                    chocolateyLicense.LicenseType = ChocolateyLicenseType.Professional;
                    break;

                case LicenseType.Business:
                    chocolateyLicense.LicenseType = ChocolateyLicenseType.Business;
                    break;

                case LicenseType.Enterprise:
                    chocolateyLicense.LicenseType = ChocolateyLicenseType.Enterprise;
                    break;
                }

                chocolateyLicense.ExpirationDate = license.ExpirationDate;
                chocolateyLicense.Name           = license.Name;
                chocolateyLicense.Id             = license.UserId.to_string();

                //todo: if it is expired, provide a warning.
                // one month after it should stop working
            }
            else
            {
                //free version
                chocolateyLicense.LicenseType = ChocolateyLicenseType.Foss;
            }

            return(chocolateyLicense);
        }
Example #2
0
        public static ChocolateyLicense validate()
        {
            var chocolateyLicense = new ChocolateyLicense
            {
                LicenseType = ChocolateyLicenseType.Unknown
            };

            string licenseFile = ApplicationParameters.LicenseFileLocation;
            //no file system at this point
            if (File.Exists(licenseFile))
            {
                var license = new LicenseValidator(PUBLIC_KEY, licenseFile);

                try
                {
                    license.AssertValidLicense();
                    chocolateyLicense.IsValid = true;
                }
                catch (Exception e)
                {
                    //license may be invalid
                    chocolateyLicense.IsValid = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
                }

                switch (license.LicenseType)
                {
                    case LicenseType.Professional :
                        chocolateyLicense.LicenseType = ChocolateyLicenseType.Professional;
                        break;
                    case LicenseType.Business :
                        chocolateyLicense.LicenseType = ChocolateyLicenseType.Business;
                        break;
                    case LicenseType.Enterprise :
                        chocolateyLicense.LicenseType = ChocolateyLicenseType.Enterprise;
                        break;
                }

                chocolateyLicense.ExpirationDate = license.ExpirationDate;
                chocolateyLicense.Name = license.Name;
                chocolateyLicense.Id = license.UserId.to_string();

                //todo: if it is expired, provide a warning. 
                // one month after it should stop working
            }
            else
            {
                //free version
                chocolateyLicense.LicenseType = ChocolateyLicenseType.Foss;
            }

            return chocolateyLicense;
        }
Example #3
0
        public static ChocolateyLicense validate()
        {
            var chocolateyLicense = new ChocolateyLicense
            {
                LicenseType  = ChocolateyLicenseType.Unknown,
                IsCompatible = true
            };

            var regularLogOutput = determine_if_regular_output_for_logging();

            string licenseFile     = ApplicationParameters.LicenseFileLocation;
            var    userLicenseFile = ApplicationParameters.UserLicenseFileLocation;

            if (File.Exists(userLicenseFile))
            {
                licenseFile = userLicenseFile;
            }

            // no IFileSystem at this point
            if (!File.Exists(licenseFile))
            {
                var licenseFileName  = Path.GetFileName(ApplicationParameters.LicenseFileLocation);
                var licenseDirectory = Path.GetDirectoryName(ApplicationParameters.LicenseFileLocation);

                // look for misnamed files and locations
                // - look in the license directory for misnamed files
                if (Directory.Exists(licenseDirectory))
                {
                    if (Directory.GetFiles(licenseDirectory).Length != 0)
                    {
                        "chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Files found in directory '{0}' but not a
 valid license file. License should be named '{1}'.".format_with(licenseDirectory, licenseFileName));
                        "chocolatey".Log().Warn(ChocolateyLoggers.Important, @" Rename license file to '{0}' to allow commercial features.".format_with(licenseFileName));
                    }
                }


                // - user put the license file in the top level location and/or forgot to rename it
                if (File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName)) || File.Exists(Path.Combine(ApplicationParameters.InstallLocation, licenseFileName + ".txt")))
                {
                    "chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, @"Chocolatey license found in the wrong location. File must be located at
 '{0}'.".format_with(ApplicationParameters.LicenseFileLocation));
                    "chocolatey".Log().Warn(regularLogOutput ? ChocolateyLoggers.Important : ChocolateyLoggers.LogFileOnly, @" Move license file to '{0}' to allow commercial features.".format_with(ApplicationParameters.LicenseFileLocation));
                }
            }

            // no IFileSystem at this point
            if (File.Exists(licenseFile))
            {
                "chocolatey".Log().Debug("Evaluating license file found at '{0}'".format_with(licenseFile));
                var license = new LicenseValidator(PUBLIC_KEY, licenseFile);

                try
                {
                    license.AssertValidLicense();

                    // There is a lease expiration timer within Rhino.Licensing, which by
                    // default re-asserts the license every 5 minutes.  Since we assert a
                    // valid license on each attempt to execute an action with Chocolatey,
                    // re-checking of the license for the current session is not required.
                    license.DisableFutureChecks();

                    chocolateyLicense.IsValid = true;
                }
                catch (LicenseFileNotFoundException e)
                {
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, "A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message,
                                                                                                                                                                                                                    "A license was also not found in the user profile: '{0}'.".format_with(ApplicationParameters.UserLicenseFileLocation)));
                }
                catch (Exception e)
                {
                    //license may be invalid
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error(regularLogOutput ? ChocolateyLoggers.Normal : ChocolateyLoggers.LogFileOnly, "A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
                }

                var chocolateyLicenseType = ChocolateyLicenseType.Unknown;
                try
                {
                    Enum.TryParse(license.LicenseType.to_string(), true, out chocolateyLicenseType);
                }
                catch (Exception)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.Unknown;
                }

                if (license.LicenseType == LicenseType.Trial)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.BusinessTrial;
                }
                else if (license.LicenseType == LicenseType.Education)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.Educational;
                }

                chocolateyLicense.LicenseType    = chocolateyLicenseType;
                chocolateyLicense.ExpirationDate = license.ExpirationDate;
                chocolateyLicense.Name           = license.Name;
                chocolateyLicense.Id             = license.UserId.to_string();

                //todo: #2584 if it is expired, provide a warning.
                // one month after it should stop working
            }
            else
            {
                //free version
                chocolateyLicense.LicenseType = ChocolateyLicenseType.Foss;
            }

            return(chocolateyLicense);
        }
Example #4
0
        public static ChocolateyLicense validate()
        {
            var chocolateyLicense = new ChocolateyLicense
            {
                LicenseType = ChocolateyLicenseType.Unknown
            };

            string licenseFile     = ApplicationParameters.LicenseFileLocation;
            var    userLicenseFile = ApplicationParameters.UserLicenseFileLocation;

            if (File.Exists(userLicenseFile))
            {
                licenseFile = userLicenseFile;
            }

            //no IFileSystem at this point
            if (File.Exists(licenseFile))
            {
                var license = new LicenseValidator(PUBLIC_KEY, licenseFile);

                try
                {
                    license.AssertValidLicense();
                    chocolateyLicense.IsValid = true;
                }
                catch (LicenseFileNotFoundException e)
                {
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message,
                                                                                                                                       "A license was also not found in the user profile: '{0}'.".format_with(ApplicationParameters.UserLicenseFileLocation)));
                }
                catch (Exception e)
                {
                    //license may be invalid
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
                }

                var chocolateyLicenseType = ChocolateyLicenseType.Unknown;
                try
                {
                    Enum.TryParse(license.LicenseType.to_string(), true, out chocolateyLicenseType);
                }
                catch (Exception)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.Unknown;
                }

                if (license.LicenseType == LicenseType.Trial)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.BusinessTrial;
                }
                else if (license.LicenseType == LicenseType.Education)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.Educational;
                }

                chocolateyLicense.LicenseType    = chocolateyLicenseType;
                chocolateyLicense.ExpirationDate = license.ExpirationDate;
                chocolateyLicense.Name           = license.Name;
                chocolateyLicense.Id             = license.UserId.to_string();

                //todo: if it is expired, provide a warning.
                // one month after it should stop working
            }
            else
            {
                //free version
                chocolateyLicense.LicenseType = ChocolateyLicenseType.Foss;
            }

            return(chocolateyLicense);
        }
Example #5
0
        public static ChocolateyLicense validate()
        {
            var chocolateyLicense = new ChocolateyLicense
            {
                LicenseType = ChocolateyLicenseType.Unknown
            };

            string licenseFile     = ApplicationParameters.LicenseFileLocation;
            var    userLicenseFile = ApplicationParameters.UserLicenseFileLocation;

            if (File.Exists(userLicenseFile))
            {
                licenseFile = userLicenseFile;
            }

            //no IFileSystem at this point
            if (File.Exists(licenseFile))
            {
                "chocolatey".Log().Debug("Evaluating license file found at '{0}'".format_with(licenseFile));
                var license = new LicenseValidator(PUBLIC_KEY, licenseFile);

                try
                {
                    license.AssertValidLicense();

                    // There is a lease expiration timer within Rhino.Licensing, which by
                    // default re-asserts the license every 5 minutes.  Since we assert a
                    // valid license on each attempt to execute an action with Chocolatey,
                    // re-checking of the license for the current session is not required.
                    license.DisableFutureChecks();

                    chocolateyLicense.IsValid = true;
                }
                catch (LicenseFileNotFoundException e)
                {
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was not found for a licensed version of Chocolatey:{0} {1}{0} {2}".format_with(Environment.NewLine, e.Message,
                                                                                                                                       "A license was also not found in the user profile: '{0}'.".format_with(ApplicationParameters.UserLicenseFileLocation)));
                }
                catch (Exception e)
                {
                    //license may be invalid
                    chocolateyLicense.IsValid       = false;
                    chocolateyLicense.InvalidReason = e.Message;
                    "chocolatey".Log().Error("A license was found for a licensed version of Chocolatey, but is invalid:{0} {1}".format_with(Environment.NewLine, e.Message));
                }

                var chocolateyLicenseType = ChocolateyLicenseType.Unknown;
                try
                {
                    Enum.TryParse(license.LicenseType.to_string(), true, out chocolateyLicenseType);
                }
                catch (Exception)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.Unknown;
                }

                if (license.LicenseType == LicenseType.Trial)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.BusinessTrial;
                }
                else if (license.LicenseType == LicenseType.Education)
                {
                    chocolateyLicenseType = ChocolateyLicenseType.Educational;
                }

                chocolateyLicense.LicenseType    = chocolateyLicenseType;
                chocolateyLicense.ExpirationDate = license.ExpirationDate;
                chocolateyLicense.Name           = license.Name;
                chocolateyLicense.Id             = license.UserId.to_string();

                //todo: if it is expired, provide a warning.
                // one month after it should stop working
            }
            else
            {
                //free version
                chocolateyLicense.LicenseType = ChocolateyLicenseType.Foss;
            }

            return(chocolateyLicense);
        }