NServiceBus.LicenseExpiredFormDisplayer.PromptUserForLicense C# (CSharp) Method

PromptUserForLicense() public static method

public static PromptUserForLicense ( License currentLicense ) : License
currentLicense Particular.Licensing.License
return Particular.Licensing.License
        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);
            }
        }
    }

Usage Example

Example #1
0
        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;
                    }
                }
            }
        }
LicenseExpiredFormDisplayer