Base license validator.
Inheritance: IDisposable
示例#1
0
        private LicenseManager(string licenseText)
        {
            ChangeRhinoLicensingLogLevelToWarn();

            validator = CreateValidator(licenseText);

            Validate();
        }
示例#2
0
        public LicenseManager()
        {
            ChangeRhinoLicensingLogLevelToWarn();

            validator = CreateValidator();

            Validate();
        }
示例#3
0
		private bool TryLoadLicense(InMemoryRavenConfiguration config)
		{
			string publicKey;
			using (
				var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
			{
				if (stream == null)
					throw new InvalidOperationException("Could not find public key for the license");
				publicKey = new StreamReader(stream).ReadToEnd();
			}

			config.Container.SatisfyImportsOnce(this);

			var value = config.Settings["Raven/License"];
			if (LicenseProvider != null && !string.IsNullOrEmpty(LicenseProvider.License))
			{
				value = LicenseProvider.License;
			}

			var fullPath = GetLicensePath(config).ToFullPath();
			if (string.IsNullOrEmpty(value) == false)
			{
				licenseValidator = new StringLicenseValidator(publicKey, value);
			}
			else if (File.Exists(fullPath))
			{
				licenseValidator = new LicenseValidator(publicKey, fullPath);
			}
			else 
			{
				CurrentLicense = new LicensingStatus
				{
					Status = "AGPL - Open Source",
					Error = false,
					Message = "No license file was found at " + fullPath +
							  "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted."
				};
				return false;
			}
			licenseValidator.DisableFloatingLicenses = true;
			licenseValidator.SubscriptionEndpoint = "http://uberprof.com/Subscriptions.svc";
			licenseValidator.LicenseInvalidated += OnLicenseInvalidated;
			licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered;

			return true;
		}
示例#4
0
        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();
                    }
                }
            }
        }
示例#5
0
		private bool TryLoadLicense(string licenseText)
		{
			string publicKey;
			using (
				var stream = typeof (ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
			{
				if (stream == null)
					throw new InvalidOperationException("Could not find public key for the license");
				publicKey = new StreamReader(stream).ReadToEnd();
			}


			licenseValidator = new StringLicenseValidator(publicKey, licenseText)
			{
				DisableFloatingLicenses = true,
				SubscriptionEndpoint = "http://uberprof.com/Subscriptions.svc"
			};
			licenseValidator.LicenseInvalidated += OnLicenseInvalidated;
			licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered;

			if (string.IsNullOrEmpty(licenseText))
			{
				CurrentLicense = new LicensingStatus
				{
					Status = "AGPL - Open Source",
					Error = false,
					Message = "No license file was found at " + licenseText +
					          "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted."
				};
				return false;
			}
			return true;
		}
示例#6
0
        private bool TryLoadLicense(InMemoryRavenConfiguration config)
        {
            string publicKey;
            using (
                var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
            {
                if (stream == null)
                    throw new InvalidOperationException("Could not find public key for the license");
                publicKey = new StreamReader(stream).ReadToEnd();
            }

            var value = GetLicenseText(config);

            var fullPath = GetLicensePath(config).ToFullPath();

            if (IsSameLicense(value, fullPath))
                return licenseValidator != null;

            if (licenseValidator != null)
                licenseValidator.Dispose();

            if (File.Exists(fullPath))
            {
                if (logger.IsDebugEnabled)
                    logger.Debug("Creating new license validator for file: {0}", fullPath);
                licenseValidator = new LicenseValidator(publicKey, fullPath);
            }
            else if (string.IsNullOrEmpty(value) == false)
            {
                if(logger.IsDebugEnabled)
                    logger.Debug("Creating new license validator for string: {0}", value.Substring(0, Math.Min(100, value.Length)));
                licenseValidator = new StringLicenseValidator(publicKey, value);
            }
            else
            {
                CurrentLicense = new LicensingStatus
                {
                    Status = "AGPL - Open Source",
                    Error = false,
                    Message = "No license file was found at " + fullPath +
                              "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted."
                };
                return false;
            }

            licenseValidator.DisableFloatingLicenses = true;
            licenseValidator.SubscriptionEndpoint = "http://licensing.ravendb.net/Subscriptions.svc";
            licenseValidator.LicenseInvalidated += OnLicenseInvalidated;
            licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered;

            return true;
        }
 public void Initialize(string license = null)
 {
     _validator = CreateValidator(license);
     Validate(license);
 }
示例#8
0
        private LicenseManager(string licenseText)
        {
            validator = CreateValidator(licenseText);

            Validate();
        }
示例#9
0
        private LicenseManager()
        {
            validator = CreateValidator();

            Validate();
        }
示例#10
0
		public void Execute(DocumentDatabase database)
		{
			if (alreadyRun)
				return;

			alreadyRun = true;

			string publicKey;
			using(var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public"))
			{
				if(stream == null)
					throw new InvalidOperationException("Could not find public key for the license");
				publicKey = new StreamReader(stream).ReadToEnd();
			}
			
			var licensePath = GetLicensePath(database);
			var licenseText = GetLicenseText(database);
			
			licenseValidator = new StringLicenseValidator(publicKey, licenseText)
			{
				DisableFloatingLicenses = true,
			};
			licenseValidator.LicenseInvalidated+=LicenseValidatorOnLicenseInvalidated;
			licenseValidator.MultipleLicensesWereDiscovered += LicenseValidatorOnMultipleLicensesWereDiscovered;

			if (string.IsNullOrEmpty(licenseText))
			{
				CurrentLicense = new LicensingStatus
				{
					Status = "AGPL - Open Source",
					Error = false,
					Message = "No license file was found at " + licenseText +
					          "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted."
				};
				return;
			}

			try
			{
				licenseValidator.AssertValidLicense(()=>
				{
					string value;
					if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) &&
						"true".Equals(value, StringComparison.InvariantCultureIgnoreCase))
					{
						licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense;
					}
				});
				

				CurrentLicense = new LicensingStatus
				{
					Status = "Commercial - " + licenseValidator.LicenseType,
					Error = false,
					Message = "Valid license at " + licensePath
				};
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not validate license at "  + licensePath + ", " + licenseText, e);

				CurrentLicense = new LicensingStatus
				{
					Status = "AGPL - Open Source",
					Error = true,
					Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e
				};
			}
		}
示例#11
0
        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;
            }
        }