예제 #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;
                }
            });
        }