private void LicenseField_PreviewTextInput(object sender, TextCompositionEventArgs e)
 {
     if (e.Text.Length == 1)
     {
         var c = e.Text[0];
         if (!EnterLicenseKeyViewModel.IsValidActivateChar(c))
         {
             e.Handled = true;
         }
     }
 }
        public EnterLicenseKey(IResolver resolver, EnterLicenseKeyViewModel viewModel)
        {
            owner         = ((PBApp)System.Windows.Application.Current).FindWindow <LoginWindow>();
            owner.Topmost = false;
            InitializeComponent();
            this.viewModel = viewModel;
            DataContext    = this.viewModel;
            this.viewModel.InitWithUICallback(CreateCallbacks());

            LicenseField.PreviewTextInput += LicenseField_PreviewTextInput;
            LicenseField.PreviewKeyDown   += LicenseField_PreviewKeyDown;

            TitleGrid.MouseLeftButtonDown += (o, e) => owner.DragMove();
        }
        /// <summary>
        /// navigate to login page
        /// </summary>
        public void NavigateloginScreens(string parameter = "")
        {
            this.Show();
            this.Topmost       = true;
            this.ShowInTaskbar = true;
            if (parameter == ScreenNames.ShowProductTour && !this.pbData.AnyAccountExists())
            {
                var pTour = resolver.GetAllInstancesOf <IProductTour>().FirstOrDefault();
                if (pTour != null)
                {
                    if (this.IsLoaded)
                    {
                        this.Hide();
                        this.ShowInTaskbar = false;
                    }

                    if (!_isProductTourMode)
                    {
                        _isProductTourMode = true;

                        this.Activate();
                        this.Topmost = true;
                        this.Topmost = false;
                        this.Focus();
                        pTour.Show(null);
                        // HACK:
                        // moved down because pTour object get constructed twice, and in second time we loose this binding, which is actually used.
                        // search for NavigateLoginScreens("ShowProductTour")
                        // pTour.DialogClosed += onDialogClosed;
                    }

                    pTour.DialogClosed += onDialogClosed;

                    if (pTour.ContentPanel is Window)
                    {
                        (pTour.ContentPanel as Window).Show();
                    }

                    return;
                }
            }

            if (parameter == ScreenNames.AccountCreation)
            {
                MainFrame.Navigate(new CreateAccount(resolver, createAccountEmptyTask.Result));
            }
            else if (parameter == ScreenNames.LicenseScreen)
            {
                try
                {
                    var  pbSync = resolver.GetInstanceOf <IPBSync>();
                    bool syncRejectLicenseScreen =
                        pbSync.LastSyncData.SubscriptionInfo.Equals("paid", StringComparison.InvariantCultureIgnoreCase) ||
                        pbSync.LastSyncData.SubscriptionInfo.Equals("third-party", StringComparison.InvariantCultureIgnoreCase);

                    if (syncRejectLicenseScreen)
                    {
                        logger.Debug("NavigateLoginScreens - PBSync.SubscriptionInfo signals to NOT show license screen");
                        NavigateloginScreens(ScreenNames.PersonalInfoScreen);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                }

                var licenseActivationBusinessLayer = new BusinessLayer.License.LicenseActivationBusinessLayer(resolver);
                var licenseFactory = new BusinessLayer.License.LicenseFactory();
                var installType    = licenseActivationBusinessLayer.GetInstallTypeRegistryValue();
                var license        = licenseFactory.CreateLicense(installType, licenseActivationBusinessLayer.GetLicenseTermDaysRegistryValue());

                if (license is BusinessLayer.License.DontShowLicenseType)
                {
                    logger.Debug("NavigateLoginScreens - LicenseScreen. License screen not required to show. skip.");
                    NavigateloginScreens(ScreenNames.PersonalInfoScreen);
                }
                else if (license == null)
                {
                    logger.Error("NavigateLoginScreens - LicenseScreen. Critical! Unable to create license screen!");
                    NavigateloginScreens(ScreenNames.PersonalInfoScreen);
                }
                else
                {
                    var enterLicenseKeyViewModel = new EnterLicenseKeyViewModel(resolver, license, licenseActivationBusinessLayer);
                    var dialog = new EnterLicenseKey(resolver, enterLicenseKeyViewModel);
                    MainFrame.Navigate(dialog);
                }
            }
            else if (parameter == ScreenNames.PersonalInfoScreen)
            {
                MainFrame.Navigate(new PersonalInfoSetup(resolver));
            }
            else if (parameter == ScreenNames.BrowserExtention)
            {
                var setupProvider = ViewModel.BrowserExtentions.SetupProviderFactory.GetDefaultBrowser();
                if (setupProvider != null)
                {
                    MainFrame.Navigate(new BrowserExtentionSetup(resolver, setupProvider));
                }
                else
                {
                    logger.Debug("NavigateLoginScreens - BrowserExtention, unable to get default browser, show main window");
                    SystemTray _systemTray = new SystemTray();
                    var        window      = _systemTray.CurrentWindow(DefaultProperties.CurrentLoginWindow);
                    _systemTray.WindowClose(window);
                    var mainWindow = ((PBApp)Application.Current).FindWindow <MainWindow>();
                    if (mainWindow == null)
                    {
                        mainWindow = new MainWindow(resolver);
                    }
                }
            }
            else
            {
                MainFrame.Navigate(Login);
            }
        }