コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: zsy960/PDFCreator
        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();
            }
        }
コード例 #3
0
        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);
            }
        }