private static Activation GetSavedActivation(Product?product) { if (product == null) { return(null); } var licenseServerHelper = new LicenseServerHelper(); var hklmLicenseChecker = licenseServerHelper.BuildLicenseChecker((Product)product, RegistryHive.LocalMachine); var localMachineActivation = hklmLicenseChecker.GetSavedActivation(); var hkcuLicenseChecker = licenseServerHelper.BuildLicenseChecker((Product)product, RegistryHive.CurrentUser); var currentUserActivation = hkcuLicenseChecker.GetSavedActivation(); if ((localMachineActivation.TimeOfActivation == DateTime.MinValue) && (currentUserActivation.TimeOfActivation == DateTime.MinValue)) { if (!string.IsNullOrWhiteSpace(currentUserActivation.Key)) { return(currentUserActivation); } return(localMachineActivation); } return(localMachineActivation.TimeOfActivation >= currentUserActivation.TimeOfActivation ? localMachineActivation : currentUserActivation); }
private void RenewActivation() { var lastActivation = EditionFactory.Instance.Edition.Activation; if (lastActivation == null) { return; } var remainingActivationTime = lastActivation.ActivatedTill - DateTime.Now; if (remainingActivationTime > TimeSpan.FromDays(4)) { return; } try { var licenseServerHelper = new LicenseServerHelper(); var licenseChecker = licenseServerHelper.BuildLicenseChecker(lastActivation.Product, RegistryHive.CurrentUser); licenseChecker.ActivateWithKey(lastActivation.Key); } finally { EditionFactory.Instance.ReloadEdition(); } }
private void OfflineActivationButton_OnClick(object sender, RoutedEventArgs e) { var licenseServerHelper = new LicenseServerHelper(); var product = ViewModel.Edition.Activation.Product; var licenseChecker = licenseServerHelper.BuildLicenseChecker(product, RegistryHive.CurrentUser); var viewModel = new OfflineActivationViewModel(licenseChecker); viewModel.LicenseKey = ViewModel.LicenseKey; var offlineActivationWindow = new OfflineActivationWindow(viewModel); if (offlineActivationWindow.ShowDialog() == true) { Activation activation; try { activation = licenseChecker.ActivateOfflineActivationStringFromLicenseServer(viewModel.LicenseServerAnswer); } catch (FormatException) { activation = new Activation(); } ViewModel.UpdateActivation(licenseChecker, activation, viewModel.LicenseKey); } }