Example #1
0
        /// <summary>
        /// Starts a background verification procedure for given key and displays a progress bar
        ///		if no license && not required -> end licensesetbasicfeatures
        ///		check license:
        ///		if ok -> end licensestore
        ///		if licensedeny -> end openlicensechange(denied/ended)
        ///		if connectionerror -> end openlicenseunreachable
        /// </summary>
        /// <param name="newLicense">the license key to be verified</param>
        private void LicenseVerify(string newLicense)
        {
            // no license and it's not required
            if (!context.RequireLicense && string.IsNullOrEmpty(newLicense))
            {
                log.Info("No license set nor required, using basic feature set.");
                LicenseSetBasicFeatures();
                return;
            }

            // start license verification in background
            Task.Factory.StartNew(async() =>
            {
                await Task.Delay(500);                  // fake delay so it looks like more wo

                try
                {
                    inLicenseVerification        = true;
                    LicenseNinja.License license = await LicenseNinja.Verify(context.ProductCode, newLicense, context.InstallId);
                    log.Info("License verified");
                    if (dialogWasOrIsOpen)
                    {
                        context.LicenseVerified();
                    }
                    Execute.OnUIThread(() =>
                    {
                        LicenseStore(newLicense, license);
                    });
                }
                catch (LicenseNinja.TimeEndedException ex)
                {
                    log.Error(ex, $"License timed out");
                    Execute.OnUIThread(() => OpenLicenseChange(LicenseChangeReason.licenseEnded, newLicense));
                }
                catch (LicenseNinja.LicenseDeniedException ex)
                {
                    log.Error(ex, $"License denied");
                    var reason = string.IsNullOrEmpty(newLicense)
                                                ?LicenseChangeReason.licenseRequired
                                                :LicenseChangeReason.licenseUnknown;
                    Execute.OnUIThread(() => OpenLicenseChange(reason, newLicense));
                }
                catch (LicenseNinja.NoLicenseServerConnectionException ex)
                {
                    log.Error(ex, $"No connection to license server: {ex}");
                    Execute.OnUIThread(() => OpenLicenseServerUnreachable(newLicense));
                }
                catch (LicenseNinja.LicenseException ex)
                {
                    log.Error(ex, "Other error");
                    Execute.OnUIThread(() => OpenLicenseServerUnreachable(newLicense));
                }
                finally
                {
                    inLicenseVerification = false;
                }
            });
        }
Example #2
0
        void LicenseStore(string licenseCode, LicenseNinja.License license)
        {
            // store new license code
            if (context.LicenseCode != licenseCode)
            {
                log.Info($"New license code: {licenseCode}, license: {license}");
                context.LicenseCode = licenseCode;
            }

            // continue to LicenseCommit
            LicenseCommit(license);
        }
Example #3
0
        /// <summary>
        /// Saves the license key (if not saved already), sets the features
        /// and closes the license manager.
        /// </summary>
        /// <param name="license">object with features to be granted from licensing server</param>
        void LicenseCommit(LicenseNinja.License license)
        {
            if (license == null && context.RequireLicense)
            {
                // this should not be reached with the user flow, probably a logic bug
                throw new Exception("Set basic features cannot work with a required license");
            }

            if (license == null || license.grant == null)
            {
                context.LicenseUpdated(null);
            }
            else
            {
                context.LicenseUpdated(license);
            }

            DialogCloseIfOpen();
        }