Beispiel #1
0
        internal static void Verify()
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                licenseText = LicenseLocationConventions.TryFindLicenseText();
                if (string.IsNullOrWhiteSpace(licenseText))
                {
                    ConfigureNServiceBusToRunInTrialMode();
                    return;
                }
            }
            SignedXmlVerifier.VerifyXml(licenseText);
            var tempLicense = LicenseDeserializer.Deserialize(licenseText);

            string message;

            if (LicenseDowngrader.ShouldLicenseDowngrade(tempLicense, out message))
            {
                message = message + " You can renew it at http://particular.net/licensing. Downgrading to basic mode";
                Logger.Warn(message);
                license = LicenseDeserializer.GetBasicLicense();
            }
            else
            {
                license = tempLicense;
            }
            WriteLicenseInfo();
        }
        void browseButton_Click(object sender, EventArgs e)
        {
            using (var openDialog = new OpenFileDialog())
            {
                openDialog.InitializeLifetimeService();
                openDialog.Filter = "License files (*.xml)|*.xml|All files (*.*)|*.*";
                openDialog.Title  = "Select License file";

                var dialogResult = StaThreadRunner.ShowDialogInSTA(() => { return(openDialog.ShowDialog()); });
                if (dialogResult == DialogResult.OK)
                {
                    var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(openDialog.FileName);
                    try
                    {
                        SignedXmlVerifier.VerifyXml(licenseText);
                        var license = LicenseDeserializer.Deserialize(licenseText);

                        string downgradeReason;
                        if (LicenseDowngrader.ShouldLicenseDowngrade(license, out downgradeReason))
                        {
                            var message = string.Format("The license you provided has expired.\r\nReason:{0}\r\nClick 'Purchase' to obtain a new license. Or try a different file.\r\nThis message has been appended to your log.", downgradeReason);
                            Logger.Warn(message);
                            MessageBox.Show(this, message, "License expired", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        MessageBox.Show(this, "The new license has been verified. It will now be stored in the Registry for future use.", "License applied", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ResultingLicenseText = licenseText;
                        Close();
                    }
                    catch (Exception exception)
                    {
                        var message = string.Format("An error occurred when parsing the license.\r\nMessage: {0}\r\nThe exception details have been appended to your log.", exception.Message);
                        Logger.Warn("Error parsing license", exception);
                        MessageBox.Show(this, message, "Error parsing license", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }