public bool PromptUserForLicenseIfTrialHasExpired() { if (license == null || LicenseExpirationChecker.HasLicenseExpired(license)) { var trialExpiredDlg = new TrialExpired { IsTrialLicense = license != null && license.IsTrialLicense }; trialExpiredDlg.ShowDialog(); if (trialExpiredDlg.ResultingLicenseText == null) { return false; } new RegistryLicenseStore() .StoreLicense(trialExpiredDlg.ResultingLicenseText); license = LicenseDeserializer.Deserialize(trialExpiredDlg.ResultingLicenseText); return true; } return true; }
public bool PromptUserForLicenseIfTrialHasExpired() { if (license == null || LicenseExpirationChecker.HasLicenseExpired(license)) { var trialExpiredDlg = new TrialExpired { CurrentLicense = license }; trialExpiredDlg.ShowDialog(); if (trialExpiredDlg.ResultingLicenseText == null) { return(false); } new RegistryLicenseStore() .StoreLicense(trialExpiredDlg.ResultingLicenseText); license = LicenseDeserializer.Deserialize(trialExpiredDlg.ResultingLicenseText); return(true); } return(true); }
private bool PromptUserForLicenseInternal() { if (license.LicenseType == LicenseType.Standard) { return(true); } else if (license.LicenseType == LicenseType.Trial && (license.ExpirationDate - DateTime.Now).TotalDays >= TRIAL_NOTIFICATION_DAYS) { return(false); } //prompt user for license file using (var form = new TrialExpired()) { form.CurrentLicenseExpireDate = license.ExpirationDate; form.ValidateLicenseFile = (f, s) => { StringLicenseValidator licenseValidator = null; try { string selectedLicenseText = ReadAllTextWithoutLocking(s); licenseValidator = new StringLicenseValidator(LicenseDescriptor.PublicKey, selectedLicenseText); licenseValidator.AssertValidLicense(); using (var registryKey = Registry.CurrentUser.CreateSubKey(String.Format(@"SOFTWARE\ParticularSoftware\Studio\{0}", SoftwareVersion.ToString(2)))) { if (registryKey == null) { return(false); } registryKey.SetValue("License", selectedLicenseText, RegistryValueKind.String); } return(true); } catch (UnauthorizedAccessException ex) { tracer.Warn("Could not write to the registry.", ex); f.DisplayError(); } catch (LicenseExpiredException) { if (licenseValidator != null) { f.DisplayExpiredLicenseError(licenseValidator.ExpirationDate); } else { f.DisplayError(); } } catch (Exception) { f.DisplayError(); } return(false); }; if (trialPeriodHasExpired) { form.ExpiredTrialVersion(); } else { form.TrialVersion((license.ExpirationDate - DateTime.Now).Days); } //if user specifies a valid license file then run with that license validator = CreateValidator(); Validate(); if (license.LicenseType == LicenseType.Standard) { return(true); } else if (license.LicenseType == LicenseType.Trial && trialPeriodHasExpired) { throw new LicenseExpiredException(); } return(false); } }
private bool PromptUserForLicenseInternal() { if (license.LicenseType == LicenseType.Standard) { return true; } else if (license.LicenseType == LicenseType.Trial && (license.ExpirationDate - DateTime.Now).TotalDays >= TRIAL_NOTIFICATION_DAYS) { return false; } //prompt user for license file using (var form = new TrialExpired()) { form.CurrentLicenseExpireDate = license.ExpirationDate; form.ValidateLicenseFile = (f, s) => { StringLicenseValidator licenseValidator = null; try { string selectedLicenseText = ReadAllTextWithoutLocking(s); licenseValidator = new StringLicenseValidator(LicenseDescriptor.PublicKey, selectedLicenseText); licenseValidator.AssertValidLicense(); using (var registryKey = Registry.CurrentUser.CreateSubKey(String.Format(@"SOFTWARE\ParticularSoftware\Studio\{0}", SoftwareVersion.ToString(2)))) { if (registryKey == null) { return false; } registryKey.SetValue("License", selectedLicenseText, RegistryValueKind.String); } return true; } catch (UnauthorizedAccessException ex) { tracer.Warn("Could not write to the registry.", ex); f.DisplayError(); } catch (LicenseExpiredException) { if (licenseValidator != null) { f.DisplayExpiredLicenseError(licenseValidator.ExpirationDate); } else { f.DisplayError(); } } catch (Exception) { f.DisplayError(); } return false; }; if (trialPeriodHasExpired) { form.ExpiredTrialVersion(); } else { form.TrialVersion((license.ExpirationDate - DateTime.Now).Days); } //if user specifies a valid license file then run with that license validator = CreateValidator(); Validate(); if (license.LicenseType == LicenseType.Standard) { return true; } else if (license.LicenseType == LicenseType.Trial && trialPeriodHasExpired) { throw new LicenseExpiredException(); } return false; } }