コード例 #1
0
        private string GetScreenTitle()
        {
            var expired = LicenseExpirationChecker.HasLicenseExpired(licenseManager.CurrentLicense);


            if (licenseManager.CurrentLicense.IsCommercialLicense)
            {
                if (expired)
                {
                    return(string.Format("ServiceInsight - License Expired"));
                }
                else
                {
                    return(string.Format("ServiceInsight"));
                }
            }
            else
            {
                if (HasRemainingTrial)
                {
                    return(string.Format("ServiceInsight - {0} day(s) left on your free trial", TrialDaysRemaining));
                }
                else
                {
                    return(string.Format("ServiceInsight - {0} Trial Expired", TrialTypeText));
                }
            }
        }
コード例 #2
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);
                    }
                }
            }
        }
コード例 #3
0
ファイル: LicenseManager.cs プロジェクト: zsybupt/NServiceBus
        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, $"NServiceBus-{GitFlowVersion.MajorMinor}", out createdNew))
            {
                if (!createdNew)
                {
                    //Dialog already displaying for this software version by another process, so we just use the already assigned license.
                    return;
                }

                if (license == null || LicenseExpirationChecker.HasLicenseExpired(license))
                {
                    var licenseProvidedByUser = LicenseExpiredFormDisplayer.PromptUserForLicense(license);

                    if (licenseProvidedByUser != null)
                    {
                        license = licenseProvidedByUser;
                    }
                }
            }
        }
コード例 #4
0
ファイル: LicenseManager.cs プロジェクト: xqfgbc/NServiceBus
        internal static void InitializeLicense()
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                licenseText = GetExistingLicense();
            }

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

            LicenseVerifier.Verify(licenseText);

            var foundLicense = LicenseDeserializer.Deserialize(licenseText);

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

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

            license = foundLicense;
        }
コード例 #5
0
        public void LoadLicense()
        {
            var dialog = _dialogManager.OpenFileDialog(new FileDialogModel
            {
                Filter      = "License files (*.xml)|*.xml|All files (*.*)|*.*",
                FilterIndex = 1
            });

            var validLicense = false;

            if (dialog.Result.GetValueOrDefault(false))
            {
                var licenseContent = ReadAllTextWithoutLocking(dialog.FileName);

                validLicense = licenseManager.TryInstallLicense(licenseContent);
            }

            if (validLicense && !LicenseExpirationChecker.HasLicenseExpired(licenseManager.CurrentLicense))
            {
                TryClose(true);
            }
            else
            {
                //todo: Display error saying that the license was invalid
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        static Particular.Licensing.License GetTrialLicense()
        {
            var trialStartDate = TrialStartDateStore.GetTrialStartDate();
            var trialLicense   = Particular.Licensing.License.TrialLicense(trialStartDate);

            //Check trial is still valid
            if (LicenseExpirationChecker.HasLicenseExpired(trialLicense))
            {
                Logger.WarnFormat("Trial for the Particular Service Platform has expired");
            }
            else
            {
                var message = string.Format("Trial for Particular Service Platform is still active, trial expires on {0}. Configuring NServiceBus to run in trial mode.", trialLicense.ExpirationDate.Value.ToLocalTime().ToShortDateString());
                Logger.Info(message);
            }

            return(trialLicense);
        }
コード例 #8
0
        static License GetTrialLicense()
        {
            var trialStartDate = TrialStartDateStore.GetTrialStartDate();
            var trialLicense   = License.TrialLicense(trialStartDate);

            //Check trial is still valid
            if (LicenseExpirationChecker.HasLicenseExpired(trialLicense))
            {
                Logger.WarnFormat("Trial for the Particular Service Platform has expired");
            }
            else
            {
                var message = $"Trial for Particular Service Platform is still active, trial expires on {trialLicense.ExpirationDate.Value.ToLocalTime().ToShortDateString()}.";
                Logger.Info(message);
            }

            return(trialLicense);
        }
コード例 #9
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;
        }
コード例 #10
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);
 }
コード例 #11
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;
        }
コード例 #12
0
        License GetTrialLicense()
        {
            if (UserSidChecker.IsNotSystemSid())
            {
                var trialStartDate = TrialStartDateStore.GetTrialStartDate();
                var trialLicense   = License.TrialLicense(trialStartDate);

                //Check trial is still valid
                if (LicenseExpirationChecker.HasLicenseExpired(trialLicense))
                {
                    tracer.Warn("Trial for the Particular Service Platform has expired");
                }
                else
                {
                    var message = string.Format("Trial for Particular Service Platform is still active, trial expires on {0}. Configuring NServiceBus to run in trial mode.", trialLicense.ExpirationDate.Value.ToShortDateString());
                    tracer.Info(message);
                }
                return(trialLicense);
            }

            tracer.Error("Could not access registry for the current user sid. Please ensure that the license has been properly installed.");
            return(null);
        }
コード例 #13
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);
                    }
                }
            }
        }
コード例 #14
0
 public bool IsLicenseExpired() => LicenseExpirationChecker.HasLicenseExpired(CurrentLicense);
コード例 #15
0
ファイル: LicenseManager.cs プロジェクト: zsybupt/NServiceBus
 internal bool HasLicenseExpired()
 {
     return(license == null || LicenseExpirationChecker.HasLicenseExpired(license));
 }
コード例 #16
0
 public bool IsLicenseExpired()
 {
     return(LicenseExpirationChecker.HasLicenseExpired(CurrentLicense));
 }