private void PromptUserForLicenseIfTrialHasExpiredInternal() { if (!(Debugger.IsAttached && SystemInformation.UserInteractive)) { //We only prompt user if user is in debugging mode and we are running in interactive mode return; } bool createdNew; using (new Mutex(true, string.Format("NServiceBus-{0}", SoftwareVersion.ToString(2)), out createdNew)) { if (!createdNew) { //Dialog already displaying for this software version by another process, so we just use the already assigned license. return; } //prompt user for license file if (trialPeriodHasExpired) { bool validLicense; 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\NServiceBus\{0}", SoftwareVersion.ToString(2)))) { if (registryKey == null) { return false; } registryKey.SetValue("License", selectedLicenseText, RegistryValueKind.String); } return true; } catch (UnauthorizedAccessException ex) { Logger.Debug("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; }; validLicense = form.ShowDialog() == DialogResult.OK; } if (validLicense) { //if user specifies a valid license file then run with that license validator = CreateValidator(); Validate(); } } } }
private void PromptUserForLicenseIfTrialHasExpiredInternal() { if (!(Debugger.IsAttached && SystemInformation.UserInteractive)) { //We only prompt user if user is in debugging mode and we are running in interactive mode return; } bool createdNew; using (new Mutex(true, string.Format("NServiceBus-{0}", SoftwareVersion.ToString(2)), out createdNew)) { if (!createdNew) { //Dialog already displaying for this software version by another process, so we just use the already assigned license. return; } //prompt user for license file if (trialPeriodHasExpired) { bool validLicense; 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\NServiceBus\{0}", SoftwareVersion.ToString(2)))) { if (registryKey == null) { return(false); } registryKey.SetValue("License", selectedLicenseText, RegistryValueKind.String); } return(true); } catch (UnauthorizedAccessException ex) { Logger.Debug("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); }; validLicense = form.ShowDialog() == DialogResult.OK; } if (validLicense) { //if user specifies a valid license file then run with that license validator = CreateValidator(); Validate(); } } } }