private void UpdateActivation(Option <Activation, LicenseError> activation) { var oldKey = _activation.Match(a => a.Key, e => ""); //Save only valid activation. Invalid activations might throw exceptions during saving. if (activation.Exists(a => a.IsLicenseStillValid())) { activation.MatchSome(a => { _activation = activation; _licenseChecker.SaveActivation(a); }); } //Save activation if current key is blocked else if (activation.Exists(a => (a.Result == Result.BLOCKED) && a.Key == oldKey)) { activation.MatchSome(a => { _activation = activation; _licenseChecker.SaveActivation(a); }); } //Notify user InvokeActivationResponse(activation); CloseLicenseWindowEvent?.Invoke(this, new ActivationResponseEventArgs(activation)); }
public void UpdateActivation(ILicenseChecker licenseChecker, Activation activation, string key) { var oldLicenseWasValid = Edition.IsLicenseValid; var newEdition = _editionFactory.DetermineEdition(activation); //Save only valid activation. Invalid activations might throw exceptions durin saving. if (newEdition.IsLicenseValid) { licenseChecker.SaveActivation(newEdition.Activation); Edition = _editionFactory.ReloadEdition(); //Set Edition by (re)loading it from registry } else if (!oldLicenseWasValid) { //set key to make it visible in view and as preset for activation with "new" key newEdition.Activation.Key = key; Edition = newEdition; } RaisePropertyChanged(nameof(Edition)); //Notify user InvokeActivationResponse(newEdition); }
private Option <Activation, LicenseError> RenewActivation() { var activation = _licenseChecker.GetSavedActivation(); if (activation.Exists(a => a.ActivationMethod == ActivationMethod.Offline)) { return(activation); } if (activation.Exists(IsActivationPeriodStillValid)) { return(activation); } var licenseKey = activation.Match( some: a => a.Key.Some <string, LicenseError>(), none: e => _licenseChecker.GetSavedLicenseKey()); return(licenseKey.Match( some: key => { var newActivation = _licenseChecker.ActivateWithoutSaving(key); // Only save if we receive a valid license or the license was blocked newActivation .Filter(a => a.IsActivationStillValid() || a.Result == Result.BLOCKED, LicenseError.NoActivation) .MatchSome(a => _licenseChecker.SaveActivation(a)); // If the online activation failed and the old activation is still valid, return the current activation if (!newActivation.HasValue && activation.Exists(a => a.IsActivationStillValid())) { return activation; } return newActivation; }, none: e => Option.None <Activation, LicenseError>(LicenseError.NoLicenseKey))); }
public void SaveActivation() { _licenseCheckerHkcu.SaveActivation(Activation); }