public static bool TryImportLicense(string licenseFile, out string errorMessage)
        {
            var licenseText = NonBlockingReader.ReadAllTextWithoutLocking(licenseFile);

            if (!LicenseVerifier.TryVerify(licenseText, out _))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!TryDeserializeLicense(licenseText, out var license))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!license.ValidForApplication("ServiceControl"))
            {
                errorMessage = "License is not for ServiceControl";
                return(false);
            }

            if (license.HasExpired())
            {
                errorMessage = "Failed to import because the license has expired";
                return(false);
            }

            try
            {
                new RegistryLicenseStore(Registry.LocalMachine).StoreLicense(licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the registry";
                return(false);
            }

            try
            {
                var machineLevelLicenseLocation = LicenseFileLocationResolver.GetPathFor(Environment.SpecialFolder.CommonApplicationData);

                new FilePathLicenseStore().StoreLicense(machineLevelLicenseLocation, licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the filesystem";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
        public LicenseInstallationResult TryInstallLicense(string licenseText)
        {
            ValidationResult = LicenseDialogSource.Validate(licenseText);
            if (ValidationResult.License != null)
            {
                if (ValidationResult.License.HasExpired())
                {
                    return(LicenseInstallationResult.Expired);
                }

                new RegistryLicenseStore().StoreLicense(licenseText);
                new FilePathLicenseStore().StoreLicense(LicenseFileLocationResolver.GetPathFor(Environment.SpecialFolder.LocalApplicationData), licenseText);

                CurrentLicense = ValidationResult.License;

                return(LicenseInstallationResult.Succeeded);
            }

            LogTo.Warning($"Can't install license: {ValidationResult.Result}");

            return(LicenseInstallationResult.Failed);
        }
        public void Refresh()
        {
            Logger.Debug("Checking License Status");
            var sources = new LicenseSource[]
            {
                new LicenseSourceFilePath(LicenseFileLocationResolver.GetPathFor(Environment.SpecialFolder.CommonApplicationData))
            };
            var result = ActiveLicense.Find("ServiceControl", sources);

            if (result.License.HasExpired())
            {
                foreach (var report in result.Report)
                {
                    Logger.Info(report);
                }

                Logger.Warn("License has expired");
            }

            IsValid = !result.License.HasExpired();
            Details = result.License;
        }
 static string GetMachineLevelLicenseLocation()
 {
     return(LicenseFileLocationResolver.GetPathFor(Environment.SpecialFolder.CommonApplicationData));
 }