public void Setup()
 {
     _activation     = new Activation(acceptExpiredActivation: true);
     _licenseChecker = Substitute.For <ILicenseChecker>();
     _licenseChecker.GetSavedActivation().Returns(x => _activation.SomeNotNull(LicenseError.NoActivation));
     _interactionInvoker = Substitute.For <IInteractionInvoker>();
     _gpoSettings        = Substitute.For <IGpoSettings>();
 }
Ejemplo n.º 2
0
        public StartupConditionResult Check()
        {
            var activation = RenewActivation();

            if (activation.Exists(a => a.IsActivationStillValid()))
            {
                return(StartupConditionResult.BuildSuccess());
            }

            _logger.Error("Invalid or expired license.");

            var editionWithVersionNumber = _applicationNameProvider.ApplicationName + " " + _versionHelper.FormatWithThreeDigits();

            _settingsManager.LoadAllSettings();
            var settingsProvider = _settingsManager.GetSettingsProvider();

            if (settingsProvider.GpoSettings.HideLicenseTab)
            {
                var errorMessage = _translation.GetFormattedLicenseInvalidGpoHideLicenseTab(editionWithVersionNumber);
                return(StartupConditionResult.BuildErrorWithMessage((int)ExitCode.LicenseInvalidAndHiddenWithGpo, errorMessage));
            }

            var caption = _applicationNameProvider.ApplicationName;
            var message = _translation.GetFormattedLicenseInvalidTranslation(editionWithVersionNumber);
            var result  = ShowMessage(message, caption, MessageOptions.YesNo, MessageIcon.Exclamation);

            if (result != MessageResponse.Yes)
            {
                return(StartupConditionResult.BuildErrorWithMessage((int)ExitCode.LicenseInvalidAndNotReactivated, "The license is invalid!", showMessage: false));
            }

            var interaction = new LicenseInteraction();

            _interactionInvoker.Invoke(interaction);

            //Check latest edition for validity
            activation = _licenseChecker.GetSavedActivation();

            if (activation.Exists(a => a.IsActivationStillValid()))
            {
                return(StartupConditionResult.BuildSuccess());
            }

            return(StartupConditionResult.BuildErrorWithMessage((int)ExitCode.LicenseInvalidAfterReactivation, _translation.GetFormattedLicenseInvalidAfterReactivationTranslation(_applicationNameProvider.ApplicationName)));
        }
Ejemplo n.º 3
0
 private Activation GetCurrentUserActivation()
 {
     try
     {
         return(_licenseCheckerHkcu.GetSavedActivation());
     }
     catch (FormatException)
     {
         return(new Activation());
     }
 }
Ejemplo n.º 4
0
 private Activation GetLocalMachineActivation()
 {
     try
     {
         return(_licenseCheckerHklm.GetSavedActivation());
     }
     catch (FormatException)
     {
         return(new Activation());
     }
 }
Ejemplo n.º 5
0
        public void Setup()
        {
            _savedActivation = new Activation(acceptExpiredActivation: false);
            _licenseChecker  = Substitute.For <ILicenseChecker>();
            _licenseChecker.GetSavedActivation().Returns(x => _savedActivation.SomeNotNull(LicenseError.NoActivation));
            _interactionInvoker = Substitute.For <IInteractionInvoker>();
            _gpoSettings        = Substitute.For <IGpoSettings>();
            _translation        = new ProgramTranslation();

            _editionWithVersionNumber = _applicationName + " " + _versionWithTreeDigits;
        }
        public void Setup()
        {
            _savedActivation      = null;
            _expectedLicenseKey   = null;
            _activationFromServer = null;

            _process        = Substitute.For <IProcessStarter>();
            _licenseChecker = Substitute.For <ILicenseChecker>();
            _licenseChecker.GetSavedActivation().Returns(x => _savedActivation.SomeNotNull(LicenseError.NoActivation));
            _licenseChecker.ActivateWithoutSaving(Arg.Any <string>()).Returns(key => _activationFromServer.SomeNotNull(LicenseError.NoActivation));
            _offlineActivator   = Substitute.For <IOfflineActivator>();
            _interactionRequest = new UnitTestInteractionRequest();
        }
Ejemplo n.º 7
0
        public LicenseSettingsViewModel(IProcessStarter processStarter, ILicenseChecker licenseChecker, IOfflineActivator offlineActivator,
                                        IInteractionRequest interactionRequest, ITranslationUpdater translationUpdater, IGpoSettings gpoSettings) : base(translationUpdater)
        {
            ShareLicenseForAllUsersEnabled = true;
            _processStarter   = processStarter;
            _licenseChecker   = licenseChecker;
            _offlineActivator = offlineActivator;

            _interactionRequest = interactionRequest;
            _gpoSettings        = gpoSettings;

            OnlineActivationAsyncCommand  = new AsyncCommand(OnlineActivationCommandExecute, OnlineActivationCommandCanExecute);
            OfflineActivationAsyncCommand = new AsyncCommand(OfflineActivationCommandExecute, OfflineActivationCommandCanExecute);
            ManageLicensesCommand         = new DelegateCommand(ManageLicensesCommandExecute);

            _activation = licenseChecker.GetSavedActivation();
        }
        public void SetUp()
        {
            _savedActivationCurrentUser        = new Activation();
            _savedActivationCurrentUser.Exists = true; //must be set for LicenseStillValid/ActivationStillValid
            _savedActivationCurrentUser.Key    = "CurrentUserKey";
            _licenseCheckerCurrentUser         = Substitute.For <ILicenseChecker>();
            _licenseCheckerCurrentUser.GetSavedActivation().Returns(_savedActivationCurrentUser);

            _savedActivationLocalMachine        = new Activation();
            _savedActivationLocalMachine.Exists = true; //must be set for LicenseStillValid/ActivationStillValid
            _savedActivationLocalMachine.Key    = "LocalMachineKey";
            _licenseCheckerLocalMachine         = Substitute.For <ILicenseChecker>();
            _licenseCheckerLocalMachine.GetSavedActivation().Returns(_savedActivationLocalMachine);

            _licenseServerHelper = Substitute.For <ILicenseServerHelper>();
            _licenseServerHelper.BuildLicenseChecker(RegistryHive.CurrentUser).Returns(_licenseCheckerCurrentUser);
            _licenseServerHelper.BuildLicenseChecker(RegistryHive.LocalMachine).Returns(_licenseCheckerLocalMachine);
        }
Ejemplo n.º 9
0
        public LicenseTabViewModel(IProcessStarter processStarter, ILicenseChecker licenseChecker, IOfflineActivator offlineActivator,
                                   IInteractionInvoker interactionInvoker, IDispatcher dispatcher, LicenseTabTranslation translation)
        {
            ShareLicenseForAllUsersEnabled = true;
            _processStarter   = processStarter;
            _licenseChecker   = licenseChecker;
            _offlineActivator = offlineActivator;

            _interactionInvoker = interactionInvoker;
            _dispatcher         = dispatcher;

            _translation = translation;

            Translation = translation;

            OnlineActivationCommand  = new DelegateCommand(OnlineActivationCommandExecute, OnlineActivationCommandCanExecute);
            OfflineActivationCommand = new DelegateCommand(OfflineActivationCommandExecute, OfflineActivationCommandCanExecute);
            ManageLicensesCommand    = new DelegateCommand(ManageLicensesCommandExecute);

            _activation = licenseChecker.GetSavedActivation();
        }
        public void ResultLicenseLimitReached_GetLicenseStatusText_LicenseStatusLimitReached(Result result, String propName, LicenseStatusForView status)
        {
            var activation = new Activation(false);

            activation.ActivatedTill = DateTime.Now.Subtract(TimeSpan.FromMinutes(60));
            activation.SetResult(result, $"{result}:{propName}:{status}");

            _licenseChecker.GetSavedActivation().Returns(x => activation.SomeNotNull(LicenseError.NoActivation));

            var viewModel = BuildViewModel();

            var licenseText = viewModel.LicenseStatusText;
            var viewStatus  = viewModel.LicenseStatusForView;

            var translation = typeof(LicenseSettingsTranslation).GetProperty(propName).GetValue(viewModel.Translation);

            Assert.IsTrue(translation.Equals(licenseText));
            Assert.IsTrue(viewStatus.Equals(status));
        }
 public Option <Activation, LicenseError> GetSavedActivation()
 {
     return(_licenseChecker.GetSavedActivation());
 }
 public LicenseExpirationReminder(ILicenseChecker licenseChecker, ICurrentSettings <ApplicationSettings> settingsProvider, IGpoSettings gpoSettings)
 {
     _activation       = licenseChecker.GetSavedActivation();
     _settingsProvider = settingsProvider;
     _gpoSettings      = gpoSettings;
 }