public void WithNonMaxThresholds()
        {
            var license = LicenseDeserializer.Deserialize(ResourceReader.ReadResourceAsString("Licensing.LicenseWithNonMaxThresholds.xml"));

            Assert.AreEqual(2, license.AllowedNumberOfWorkerNodes);
            Assert.AreEqual(2, license.MaxThroughputPerSecond);
        }
        public static License PromptUserForLicense(License currentLicense)
        {
            SynchronizationContext synchronizationContext = null;

            try
            {
                synchronizationContext = SynchronizationContext.Current;
                using (var form = new LicenseExpiredForm())
                {
                    form.CurrentLicense = currentLicense;
                    form.ShowDialog();
                    if (form.ResultingLicenseText == null)
                    {
                        return(null);
                    }

                    new RegistryLicenseStore()
                    .StoreLicense(form.ResultingLicenseText);

                    return(LicenseDeserializer.Deserialize(form.ResultingLicenseText));
                }
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(synchronizationContext);
            }
        }
Пример #3
0
        private void Browse_Click(object sender, RoutedEventArgs 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 == System.Windows.Forms.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.\r\nEither extend your trial or contact sales to obtain a new license. Or try a different file.");
                            MessageBox.Show(this, message, "License expired", MessageBoxButton.OK, MessageBoxImage.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);
                        MessageBox.Show(this, message, "Error parsing license", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
        public bool TryInstallLicense(string licenseText)
        {
            try
            {
                if (!LicenseVerifier.TryVerify(licenseText, out _))
                {
                    return(false);
                }

                CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                if (!CurrentLicense.ValidForApplication("ServiceInsight"))
                {
                    return(false);
                }

                new RegistryLicenseStore().StoreLicense(licenseText);
                new FilePathLicenseStore().StoreLicense(FilePathLicenseStore.UserLevelLicenseLocation, licenseText);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Warning(ex, "Can't install license: {ex}", ex);
                return(false);
            }
        }
        public void ParseAllTheLicenses()
        {
            //Set an environment variable to a path containing all the licenses to run this test
            var allTheLicensesDir = Environment.GetEnvironmentVariable("NServiceBusLicensesPath");

            foreach (var licensePath in Directory.EnumerateFiles(allTheLicensesDir, "license.xml", SearchOption.AllDirectories))
            {
                var licenseManager = LicenseDeserializer.Deserialize(File.ReadAllText(licensePath));
                Debug.WriteLine(licenseManager.UpgradeProtectionExpiration);
            }
        }
        public void WithAllProperties()
        {
            var license = LicenseDeserializer.Deserialize(ResourceReader.ReadResourceAsString("Licensing.LicenseWithAllProperties.xml"));

            var dateTimeOffset = new DateTime(2014, 2, 6, 0, 0, 0, DateTimeKind.Utc);

            Assert.AreEqual(dateTimeOffset, license.ExpirationDate);
            Assert.AreEqual(int.MaxValue, license.AllowedNumberOfWorkerNodes);
            Assert.AreEqual(0, license.MaxThroughputPerSecond);
            Assert.AreEqual(new DateTime(2013, 11, 6, 0, 0, 0, DateTimeKind.Utc), license.UpgradeProtectionExpiration);
        }
Пример #7
0
 static bool TryDeserializeLicense(string licenseText, out License license)
 {
     license = null;
     try
     {
         license = LicenseDeserializer.Deserialize(licenseText);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #8
0
 public static License PromptUserForLicense()
 {
     using (var form = new LicenseExpiredForm())
     {
         form.ShowDialog();
         if (form.ResultingLicenseText == null)
         {
             return(LicenseDeserializer.GetBasicLicense());
         }
         LicenseLocationConventions.StoreLicenseInRegistry(form.ResultingLicenseText);
         return(LicenseDeserializer.Deserialize(form.ResultingLicenseText));
     }
 }
Пример #9
0
        static ActiveLicense DetermineActiveLicense()
        {
            var activeLicense = new ActiveLicense
            {
                IsValid = false
            };

            var licenseText = TryFindLicense();

            if (string.IsNullOrEmpty(licenseText))
            {
                Logger.Warn("No valid license could be found, falling back to trial license");

                activeLicense.Details = License.TrialLicense(TrialStartDateStore.GetTrialStartDate());
            }
            else
            {
                Exception validationFailure;

                if (!LicenseVerifier.TryVerify(licenseText, out validationFailure))
                {
                    Logger.WarnFormat("Found license was not valid: {0}", validationFailure);
                    return(activeLicense);
                }


                var licenseDetails = LicenseDeserializer.Deserialize(licenseText);

                if (!licenseDetails.ValidForApplication("ServiceControl"))
                {
                    Logger.WarnFormat("Found license was is not valid for ServiceControl. Valid apps: '{0}'", string.Join(",", licenseDetails.ValidApplications));
                    return(activeLicense);
                }

                activeLicense.Details = licenseDetails;
            }

            activeLicense.HasExpired = LicenseExpirationChecker.HasLicenseExpired(activeLicense.Details);

            if (activeLicense.HasExpired)
            {
                Logger.WarnFormat("Found license has expired");
            }
            else
            {
                activeLicense.IsValid = true;
            }

            return(activeLicense);
        }
        public AppLicenseManager()
        {
            var licenseText = GetExistingLicense();

            if (!String.IsNullOrEmpty(licenseText))
            {
                Exception ex;
                if (LicenseVerifier.TryVerify(licenseText, out ex))
                {
                    CurrentLicense = LicenseDeserializer.Deserialize(licenseText);
                    return;
                }
            }

            CurrentLicense = CreateTrialLicense();
        }
Пример #11
0
        public AppLicenseManager()
        {
            string licenseText;

            if (licenseStore.TryReadLicense(out licenseText))
            {
                Exception ex;

                if (LicenseVerifier.TryVerify(licenseText, out ex))
                {
                    CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                    return;
                }
            }

            CurrentLicense = CreateTrialLicense();
        }
Пример #12
0
        internal void InitializeLicense(string licenseText)
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                licenseText = GetExistingLicense();
            }

            if (string.IsNullOrWhiteSpace(licenseText))
            {
                license = GetTrialLicense();
                PromptUserForLicenseIfTrialHasExpired();
                return;
            }

            LicenseVerifier.Verify(licenseText);

            var foundLicense = LicenseDeserializer.Deserialize(licenseText);

            if (LicenseExpirationChecker.HasLicenseExpired(foundLicense))
            {
                // If the found license is a trial license then it is actually a extended trial license not a locally generated trial.
                // Set the property to indicate that it is an extended license as it's not set by the license generation
                if (foundLicense.IsTrialLicense)
                {
                    foundLicense.IsExtendedTrial = true;
                    PromptUserForLicenseIfTrialHasExpired();
                    return;
                }
                Logger.Fatal("Your license has expired! You can renew it at https://particular.net/licensing.");
                return;
            }

            if (foundLicense.UpgradeProtectionExpiration != null)
            {
                Logger.InfoFormat("License upgrade protection expires on: {0}", foundLicense.UpgradeProtectionExpiration);
            }
            else
            {
                Logger.InfoFormat("License expires on {0}", foundLicense.ExpirationDate);
            }

            license = foundLicense;
        }
Пример #13
0
 public bool PromptUserForLicenseIfTrialHasExpired()
 {
     if (license == null || LicenseExpirationChecker.HasLicenseExpired(license))
     {
         var trialExpiredDlg = new TrialExpired
         {
             CurrentLicense = license
         };
         trialExpiredDlg.ShowDialog();
         if (trialExpiredDlg.ResultingLicenseText == null)
         {
             return(false);
         }
         new RegistryLicenseStore()
         .StoreLicense(trialExpiredDlg.ResultingLicenseText);
         license = LicenseDeserializer.Deserialize(trialExpiredDlg.ResultingLicenseText);
         return(true);
     }
     return(true);
 }
Пример #14
0
        void InitializeLicense()
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                //look in the new platform locations
                if (!(new RegistryLicenseStore().TryReadLicense(out licenseText)))
                {
                    //TODO: Check legacy locations for Service Matrix.
                    if (string.IsNullOrWhiteSpace(licenseText))
                    {
                        license = GetTrialLicense();
                        return;
                    }
                }
            }

            LicenseVerifier.Verify(licenseText);

            var foundLicense = LicenseDeserializer.Deserialize(licenseText);

            if (LicenseExpirationChecker.HasLicenseExpired(foundLicense))
            {
                tracer.Error("You can renew it at http://particular.net/licensing.");
                return;
            }

            if (foundLicense.UpgradeProtectionExpiration != null)
            {
                tracer.Info(string.Format("UpgradeProtectionExpiration: {0}", foundLicense.UpgradeProtectionExpiration));
            }
            else
            {
                tracer.Info(string.Format("Expires on {0}", foundLicense.ExpirationDate));
            }

            license = foundLicense;
        }
Пример #15
0
        public bool TryInstallLicense(string licenseText)
        {
            try
            {
                Exception verificationException;

                if (!LicenseVerifier.TryVerify(licenseText, out verificationException))
                {
                    return(false);
                }

                CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                new RegistryLicenseStore().StoreLicense(licenseText);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Warning(ex, "Can't install license: {ex}", ex);
                return(false);
            }
        }
Пример #16
0
        public bool TryInstallLicense(string licenseText)
        {
            try
            {
                Exception verificationException;

                if (!LicenseVerifier.TryVerify(licenseText, out verificationException))
                {
                    return(false);
                }

                CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                licenseStore.StoreLicense(licenseText);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.WarnFormat("Can't install license: {0}", ex);
                return(false);
            }
        }
Пример #17
0
        public static void AssertRemoteValidationCheckPasses(KeyHubWebDriver site,
                                                             string domain,
                                                             Guid appKey,
                                                             Guid featureCode,
                                                             string vendorPublicKey)
        {
            var licensingUrl = site.UrlFor("/api/LicenseValidation");

            var licensesAndSignature = new LicenseDownloader().RequestLicenses(licensingUrl, appKey,
                                                                               new Dictionary <string, List <Guid> >()
            {
                { domain, new List <Guid>()
                  {
                      featureCode
                  } }
            });

            var newLicenses = new LicenseDeserializer().DeserializeAll(vendorPublicKey, licensesAndSignature);

            DomainLicense license = newLicenses[domain].Single();

            Assert.Equal(license.Domain, domain);
            Assert.Contains(featureCode, license.Features);
        }
Пример #18
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);
                    }
                }
            }
        }
Пример #19
0
        public void WithNoUpgradeProtection()
        {
            var license = LicenseDeserializer.Deserialize(ResourceReader.ReadResourceAsString("Licensing.LicenseWithNoUpgradeProtection.xml"));

            Assert.IsNull(license.UpgradeProtectionExpiration);
        }