Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        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(openDialog.ShowDialog);
                if (dialogResult == DialogResult.OK)
                {
                    var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(openDialog.FileName);
                    try
                    {
                        LicenseVerifier.Verify(licenseText);
                        var license = LicenseDeserializer.Deserialize(licenseText);

                        if (LicenseExpirationChecker.HasLicenseExpired(license))
                        {
                            var message = string.Format("The license you provided has expired, please select another file.");
                            Logger.Warn(message);
                            MessageBox.Show(this, message, "License expired", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        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);
                    }
                }
            }
        }
        public static string TryFindLicenseText()
        {
            var appConfigLicenseString = ConfigurationManager.AppSettings["NServiceBus/License"];

            if (!String.IsNullOrEmpty(appConfigLicenseString))
            {
                Logger.Info(@"Using embedded license supplied via config file AppSettings/NServiceBus/License.");
                return(appConfigLicenseString);
            }

            var appConfigLicenseFile = ConfigurationManager.AppSettings["NServiceBus/LicensePath"];

            if (!String.IsNullOrEmpty(appConfigLicenseFile))
            {
                if (File.Exists(appConfigLicenseFile))
                {
                    Logger.InfoFormat(@"Using license supplied via config file AppSettings/NServiceBus/LicensePath ({0}).", appConfigLicenseFile);
                    return(NonLockingFileReader.ReadAllTextWithoutLocking(appConfigLicenseFile));
                }
                //TODO: should we throw if file does not exist?
                throw new Exception(string.Format("You have a configured licensing via AppConfigLicenseFile to use the file at '{0}'. However this file does not exist. Either place a valid license at this location or remove the app setting.", appConfigLicenseFile));
            }

            var localLicenseFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"NServiceBus\License.xml");

            if (File.Exists(localLicenseFile))
            {
                Logger.InfoFormat(@"Using license in current folder ({0}).", localLicenseFile);
                return(NonLockingFileReader.ReadAllTextWithoutLocking(localLicenseFile));
            }

            var oldLocalLicenseFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"License\License.xml");

            if (File.Exists(oldLocalLicenseFile))
            {
                Logger.InfoFormat(@"Using license in current folder ({0}).", oldLocalLicenseFile);
                return(NonLockingFileReader.ReadAllTextWithoutLocking(oldLocalLicenseFile));
            }

            var registryLicence = LoadLicenseFromRegistry();

            if (!String.IsNullOrEmpty(registryLicence))
            {
                return(registryLicence);
            }

            registryLicence = LoadLicenseFromPreviousRegistryLocation("4.3");
            if (!String.IsNullOrEmpty(registryLicence))
            {
                return(registryLicence);
            }

            registryLicence = LoadLicenseFromPreviousRegistryLocation("4.2");
            if (!String.IsNullOrEmpty(registryLicence))
            {
                return(registryLicence);
            }

            registryLicence = LoadLicenseFromPreviousRegistryLocation("4.1");
            if (!String.IsNullOrEmpty(registryLicence))
            {
                return(registryLicence);
            }

            registryLicence = LoadLicenseFromPreviousRegistryLocation("4.0");
            if (!String.IsNullOrEmpty(registryLicence))
            {
                return(registryLicence);
            }

            return(null);
        }