예제 #1
0
        /// <summary>
        /// Compare a bunch of license sources and choose an active license
        /// </summary>
        public static ActiveLicenseFindResult Find(string applicationName, params LicenseSource[] licenseSources)
        {
            var results       = licenseSources.Select(licenseSource => licenseSource.Find(applicationName)).ToList();
            var activeLicense = new ActiveLicenseFindResult();

            foreach (var result in results.Where(p => !string.IsNullOrWhiteSpace(p.Result)).Select(p => p.Result))
            {
                activeLicense.Report.Add(result);
            }

            var licenseSourceResultToUse = LicenseSourceResult.DetermineBestLicenseSourceResult(results.ToArray());

            if (licenseSourceResultToUse != null)
            {
                var selectedLicenseReportItem = $"Selected active license from {licenseSourceResultToUse.Location}";
                activeLicense.Report.Add(selectedLicenseReportItem);
                activeLicense.SelectedLicenseReport.Add(selectedLicenseReportItem);

                var details = licenseSourceResultToUse.License;

                if (details.ExpirationDate.HasValue)
                {
                    var licenseExpirationReportItem = $"License Expiration: {details.ExpirationDate.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}";
                    activeLicense.Report.Add(licenseExpirationReportItem);
                    activeLicense.SelectedLicenseReport.Add(licenseExpirationReportItem);
                }

                if (details.UpgradeProtectionExpiration.HasValue)
                {
                    var upgradeProtectionReportItem = $"Upgrade Protection Expiration: {details.UpgradeProtectionExpiration.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}";
                    activeLicense.Report.Add(upgradeProtectionReportItem);
                    activeLicense.SelectedLicenseReport.Add(upgradeProtectionReportItem);
                }

                activeLicense.License  = details;
                activeLicense.Location = licenseSourceResultToUse.Location;

                if (activeLicense.License.IsTrialLicense)
                {
                    // If the found license is a trial license then it is actually a extended trial license not a locally generated trial.
                    // Set the property to indicate that it is an extended license as it's not set by the license generation
                    activeLicense.License.IsExtendedTrial = true;
                }
            }

            if (activeLicense.License == null)
            {
                var trialStartDate = TrialStartDateStore.GetTrialStartDate();

                var trialLicenseReportItem = $"No valid license could be found. Falling back to trial license with start date '{trialStartDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}'.";
                activeLicense.Report.Add(trialLicenseReportItem);
                activeLicense.SelectedLicenseReport.Add(trialLicenseReportItem);

                activeLicense.License  = License.TrialLicense(trialStartDate);
                activeLicense.Location = "Trial License";
            }

            return(activeLicense);
        }
예제 #2
0
        public override LicenseSourceResult Find(string applicationName)
        {
            var embeddedLicense = ReadLicenseFromAppConfig(applicationName);
            var externalLicense = ReadExternalLicense(applicationName);

            return(LicenseSourceResult.DetermineBestLicenseSourceResult(embeddedLicense, externalLicense) ?? new LicenseSourceResult
            {
                Location = location,
                Result = $"License not found in {location}"
            });
        }
        public override LicenseSourceResult Find(string applicationName)
        {
            var reg32Result = ReadFromRegistry(RegistryView.Registry32, applicationName);
            var reg64Result = ReadFromRegistry(RegistryView.Registry64, applicationName);

            return(LicenseSourceResult.DetermineBestLicenseSourceResult(reg32Result, reg64Result) ?? new LicenseSourceResult
            {
                Location = location,
                Result = $"License not found in {location}"
            });
        }
예제 #4
0
        protected LicenseSourceResult ValidateLicense(string licenseText, string applicationName)
        {
            if (string.IsNullOrWhiteSpace(applicationName))
            {
                throw new ArgumentException("No application name specified");
            }

            var result = new LicenseSourceResult {
                Location = Location
            };

            Exception validationFailure;

            if (!LicenseVerifier.TryVerify(licenseText, out validationFailure))
            {
                result.Result = $"License found at '{Location}' is not valid - {validationFailure.Message}";
                return(result);
            }

            License license;

            try
            {
                license = LicenseDeserializer.Deserialize(licenseText);
            }
            catch
            {
                result.Result = $"License found at '{Location}' could not be deserialized";
                return(result);
            }

            if (license.ValidForApplication(applicationName))
            {
                result.License = license;
                result.Result  = $"License found at '{Location}'";
            }
            else
            {
                result.Result = $"License found at '{Location}' was not valid for '{applicationName}'. Valid apps: '{string.Join(",", license.ValidApplications)}'";
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Compare a bunch of license sources and choose an active license
        /// </summary>
        public static ActiveLicenseFindResult Find(string applicationName, params LicenseSource[] licenseSources)
        {
            var results       = licenseSources.Select(licenseSource => licenseSource.Find(applicationName)).ToList();
            var activeLicense = new ActiveLicenseFindResult();

            foreach (var result in results.Where(p => !string.IsNullOrWhiteSpace(p.Result)).Select(p => p.Result))
            {
                activeLicense.Report.Add(result);
            }

            var licenseSourceResultToUse = LicenseSourceResult.DetermineBestLicenseSourceResult(results.ToArray());

            if (licenseSourceResultToUse != null)
            {
                activeLicense.Report.Add($"Selected active license from {licenseSourceResultToUse.Location}");
                var details = licenseSourceResultToUse.License;
                if (details.ExpirationDate.HasValue)
                {
                    activeLicense.Report.Add(string.Format(CultureInfo.InvariantCulture, "License Expiration: {0:dd MMMM yyyy}", details.ExpirationDate.Value));

                    if (details.UpgradeProtectionExpiration.HasValue)
                    {
                        activeLicense.Report.Add(string.Format(CultureInfo.InvariantCulture, "Upgrade Protection Expiration: {0:dd MMMM yyyy}", details.UpgradeProtectionExpiration.Value));
                    }
                }
                activeLicense.License  = details;
                activeLicense.Location = licenseSourceResultToUse.Location;
            }

            if (activeLicense.License == null)
            {
                activeLicense.Report.Add("No valid license could be found, falling back to trial license");
                activeLicense.License  = License.TrialLicense(TrialStartDateStore.GetTrialStartDate());
                activeLicense.Location = "Trial License";
            }
            activeLicense.HasExpired = LicenseExpirationChecker.HasLicenseExpired(activeLicense.License);
            return(activeLicense);
        }
예제 #6
0
        protected LicenseSourceResult ValidateLicense(string licenseText, string applicationName)
        {
            if (string.IsNullOrWhiteSpace(applicationName))
            {
                throw new ArgumentException("No application name specified");
            }

            var result = new LicenseSourceResult { Location = location };

            Exception validationFailure;
            if (!LicenseVerifier.TryVerify(licenseText, out validationFailure))
            {
                result.Result = $"License found at '{location}' is not valid - {validationFailure.Message}";
                return result;
            }

            License license;
            try
            {
                license = LicenseDeserializer.Deserialize(licenseText);
            }
            catch
            {
                result.Result = $"License found at '{location}' could not be deserialized";
                return result;
            }

            if (license.ValidForApplication(applicationName))
            {
                result.License = license;
                result.Result = $"License found at '{location}'";
            }
            else
            {
                result.Result = $"License found at '{location}' was not valid for '{applicationName}'. Valid apps: '{string.Join(",", license.ValidApplications)}'";
            }
            return result;
        }