Ejemplo n.º 1
0
        /// <summary>
        /// Allows user to specify the path for the license file.
        /// </summary>
        /// <param name="config">The current <see cref="BusConfiguration"/>.</param>
        /// <param name="licenseFile">A relative or absolute path to the license file.</param>
        public static void LicensePath(this BusConfiguration config, string licenseFile)
        {
            if (!File.Exists(licenseFile))
            {
                throw new FileNotFoundException("License file not found", licenseFile);
            }

            var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(licenseFile);

            config.License(licenseText);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows user to specify the path for the license file.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
        /// <param name="licenseFile">A relative or absolute path to the license file.</param>
        public static void LicensePath(this EndpointConfiguration config, string licenseFile)
        {
            Guard.AgainstNull(nameof(config), config);
            Guard.AgainstNullAndEmpty(nameof(licenseFile), licenseFile);
            if (!File.Exists(licenseFile))
            {
                throw new FileNotFoundException("License file not found", licenseFile);
            }

            var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(licenseFile);

            config.License(licenseText);
        }
Ejemplo n.º 3
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 = "The license you provided has expired, 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 = $"An error occurred when parsing the license.\r\nMessage: {exception.Message}\r\nThe exception details have been appended to the log.";
                        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($"You have a configured licensing via AppConfigLicenseFile to use the file at '{appConfigLicenseFile}'. However this file does not exist. Either place a valid license at this location or remove the app setting.");
            }

            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 registryLicense = LoadLicenseFromRegistry();

            if (!string.IsNullOrEmpty(registryLicense))
            {
                return(registryLicense);
            }

            registryLicense = LoadLicenseFromPreviousRegistryLocation("4.3");
            if (!string.IsNullOrEmpty(registryLicense))
            {
                return(registryLicense);
            }

            registryLicense = LoadLicenseFromPreviousRegistryLocation("4.2");
            if (!string.IsNullOrEmpty(registryLicense))
            {
                return(registryLicense);
            }

            registryLicense = LoadLicenseFromPreviousRegistryLocation("4.1");
            if (!string.IsNullOrEmpty(registryLicense))
            {
                return(registryLicense);
            }

            registryLicense = LoadLicenseFromPreviousRegistryLocation("4.0");
            if (!string.IsNullOrEmpty(registryLicense))
            {
                return(registryLicense);
            }

            return(null);
        }