Esempio n. 1
0
        internal static void PromptUserForLicenseIfTrialHasExpired()
        {
            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}", NServiceBusVersion.MajorAndMinor), out createdNew))
            {
                if (!createdNew)
                {
                    //Dialog already displaying for this software version by another process, so we just use the already assigned license.
                    return;
                }

                //TODO: should we display dialog if UpgradeProtection is not valid?
                if (ExpiryChecker.IsExpired(License.ExpirationDate))
                {
                    license = LicenseExpiredFormDisplayer.PromptUserForLicense();
                }
            }
        }
Esempio n. 2
0
        private void ConfigureNServiceBusToRunInTrialMode()
        {
            var trialExpirationDate = DateTime.UtcNow.Date;

            var windowsIdentity = WindowsIdentity.GetCurrent();

            if (windowsIdentity != null && windowsIdentity.User != null &&
                !windowsIdentity.User.IsWellKnown(WellKnownSidType.LocalSystemSid))
            {
                //If first time run, configure expire date
                try
                {
                    string trialStartDateString;
                    using (var registryKey = Registry.CurrentUser.CreateSubKey(String.Format(@"SOFTWARE\NServiceBus\{0}", SoftwareVersion.ToString(2))))
                    {
                        if (registryKey == null)
                        {
                            Logger.Warn("Falling back to run in Basic1 license mode.");

                            trialPeriodHasExpired = true;

                            //if trial expired, run in Basic1
                            RunInBasic1Mode(trialExpirationDate);
                        }

                        if ((trialStartDateString = (string)registryKey.GetValue("TrialStart", null)) == null)
                        {
                            trialStartDateString = DateTime.UtcNow.ToString("yyyy-MM-dd");
                            registryKey.SetValue("TrialStart", trialStartDateString, RegistryValueKind.String);

                            Logger.DebugFormat("First time running NServiceBus v{0}, setting trial license start.",
                                               SoftwareVersion.ToString(2));
                        }
                    }

                    var trialStartDate = DateTime.ParseExact(trialStartDateString, "yyyy-MM-dd",
                                                             CultureInfo.InvariantCulture,
                                                             DateTimeStyles.AssumeUniversal);

                    trialExpirationDate = trialStartDate.Date.AddDays(TRIAL_DAYS);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Logger.Debug("Could not write to the registry. Because we didn't find a license file we assume the trial has expired.", ex);
                }
            }

            //Check trial is still valid
            if (trialExpirationDate > DateTime.UtcNow.Date)
            {
                Logger.DebugFormat("Trial for NServiceBus v{0} is still active, trial expires on {1}.",
                                   SoftwareVersion.ToString(2), trialExpirationDate.ToLocalTime().ToShortDateString());
                Logger.Info("Configuring NServiceBus to run in trial mode.");

                //Run in unlimited mode during trial period
                license = new License
                {
                    LicenseType    = LicenseType.Trial,
                    ExpirationDate = trialExpirationDate
                };

                ConfigureLicenseBasedOnAttribute(license.LicenseType, new Dictionary <string, string>
                {
                    { AllowedNumberOfWorkerNodesLicenseKey, UnlimitedNumberOfWorkerNodes },
                    { WorkerThreadsLicenseKey, MaxWorkerThreads },
                    { MaxMessageThroughputPerSecondLicenseKey, MaxMessageThroughputPerSecond },
                });
            }
            else
            {
                Logger.DebugFormat("Trial for NServiceBus v{0} has expired.", SoftwareVersion.ToString(2));
                Logger.Warn("Falling back to run in Basic1 license mode.");

                trialPeriodHasExpired = true;

                //if trial expired, run in Basic1
                RunInBasic1Mode(trialExpirationDate);
            }
        }
Esempio n. 3
0
        static void ConfigureNServiceBusToRunInTrialMode()
        {
            if (UserSidChecker.IsNotSystemSid())
            {
                var trialExpirationDate = TrialLicenseReader.GetTrialExpirationFromRegistry();
                //Check trial is still valid
                if (ExpiryChecker.IsExpired(trialExpirationDate))
                {
                    Logger.WarnFormat("Trial for NServiceBus v{0} has expired. Falling back to run in Basic1 license mode.", NServiceBusVersion.MajorAndMinor);

                    license = LicenseDeserializer.GetBasicLicense();
                }
                else
                {
                    var message = string.Format("Trial for NServiceBus v{0} is still active, trial expires on {1}. Configuring NServiceBus to run in trial mode.", NServiceBusVersion.MajorAndMinor, trialExpirationDate.ToLocalTime().ToShortDateString());
                    Logger.Info(message);

                    //Run in unlimited mode during trial period
                    license = LicenseDeserializer.GetTrialLicense(trialExpirationDate);
                }
                return;
            }

            Logger.Warn("Could not access registry for the current user sid. Falling back to run in Basic license mode.");

            license = LicenseDeserializer.GetBasicLicense();
        }
Esempio n. 4
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();
        }