Beispiel #1
0
        public void SetLanguage(string lang = "")
        {
            if (string.IsNullOrEmpty(lang))
            {
                lang = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
            }

            lock (syncLock)
            {
                var textResources = moduleLoader.GetAllInstancesOf <ITextResource>().Where(r => r.Lang == lang).ToList();
                if (textResources.Count < 1 && lang != "en")
                {
                    lang          = "en";
                    textResources = moduleLoader.GetAllInstancesOf <ITextResource>().Where(r => r.Lang == lang).ToList();
                }
                foreach (var r in textResources)
                {
                    if (resourcePaths.ContainsKey(r.ResourceKey))
                    {
                        resourcePaths[r.ResourceKey] = r.ResourcePath;
                    }
                    else
                    {
                        resourcePaths.Add(r.ResourceKey, r.ResourcePath);
                    }
                    LoadAndMerge(r.ResourcePath);
                }
                currentLanguage = lang;
                pbData.ChangeDefaultSetting("last_lang", currentLanguage);
                pbData.ChangeUserSetting("last_sync", null);
            }
            if (webAPI.CurrentLanguage != currentLanguage)
            {
                webAPI.SetLanguage(currentLanguage);
                ManualResetEvent evDone = new ManualResetEvent(false);
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        if (!sync.UpdateTranslations())
                        {
                            logger.Debug("UpdateTranslations failed");
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.ToString());
                    }
                    evDone.Set();
                });
                evDone.WaitOne();
            }
            //Updating text resources for tray menu
            SystemTray.SetLanguageForTrayMenuItems();

            //var m = FindWindow<MainWindow>();
            //if (m != null) m.Reload();
            Logout(true);
        }
Beispiel #2
0
        void pbData_OnUserLoggedIn(object o)
        {
            Application.Current.Dispatcher.BeginInvoke((Action)(() =>
            {
                var vm = accountSettingsUserControl.DataContext as AccountSettingsViewModel;
                if (vm != null)
                {
                    vm.RefreshData();
                }
                showExtMsg = true;

                var c = resolver.GetAllInstancesOf <IUIComponent>().Where(i => i.ID == "SecureBrowser").SingleOrDefault();
                if (c != null)
                {
                    var result = c.ExecuteCommand("ReloadSecureBrowser", null);
                }

                foreach (var sc in subComponents)
                {
                    sc.NotifySubComponent("RefreshStats");
                }

                AccountSettingsClose();
                OpenDefaultMenuItem();
            }));
            SyncAsync();
            LoadForShowOnStartup();
        }
        void sync_OnSyncFinished(bool status)
        {
            try
            {
                IPBSync sync = resolver.GetInstanceOf <IPBSync>();
                sync.OnSyncFinished -= sync_OnSyncFinished;
                var browserImporters = resolver.GetAllInstancesOf <BrowserImportStrategyBase>();

                var results = browserImporters.Select(s => s.Import());

                var importedSitesNum       = results.Sum(r => r.Imported);
                var alredyImportedSitesNum = 0;

                List <SecureItem> userSites = pbData.GetSecureItemsByItemType(PasswordBoss.Helpers.DefaultProperties.SecurityItemType_PasswordVault).Where(x => x.Site.IsRecommendedSite == false).ToList();

                if (userSites.Count == 0)
                {
                    alredyImportedSitesNum = 0; //we didn't have anything previous. alredyImportedSitesNum can also mean overlapping between browsers
                }
                else
                {
                    alredyImportedSitesNum = results.Sum(r => r.AlreadyImported);
                }

                var inAppAnalyitics = resolver.GetInstanceOf <IInAppAnalytics>();
                if (inAppAnalyitics != null)
                {
                    ImportPasswordsItem item = new ImportPasswordsItem(importedSitesNum, ImportPasswordsTrigger.Installer, null);
                    var analytics            = inAppAnalyitics.Get <Events.ImportPasswords, ImportPasswordsItem>();
                    analytics.Log(item);
                }

                pbData.ChangePrivateSetting("setup_wizard_imported_passwords_number", importedSitesNum.ToString());
                pbData.ChangePrivateSetting("setup_wizard_already_passwords_number", alredyImportedSitesNum.ToString());

                AddEmailToPI();

                logger.Debug("sync images");
                SyncImagesHelper syncImages = new SyncImagesHelper(pbData, webApi);
                //syncImages.SyncImagesAsync();
                syncImages.SyncImages();

                logger.Debug("Finished");
            }
            finally
            {
                evDone.Set();
            }
        }
Beispiel #4
0
        public MainWindow([Import(typeof(IResolver))] IResolver resolver)//[ImportMany] IEnumerable<IUIComponent> components, [Import(typeof(IPBData))]IPBData pbData)
        {
            Application.Current.MainWindow = this;
            application = (PBApp)Application.Current;
            //masterDialog = new MasterPwdBox();
            this.resolver = resolver;


            this.components = resolver.GetAllInstancesOf <IUIComponent>();
            if (this.components == null)
            {
                this.components = new List <IUIComponent>();
            }

            this.subComponents = resolver.GetAllInstancesOf <IUISubComponent>();
            if (this.subComponents == null)
            {
                this.subComponents = new List <IUISubComponent>();
            }

            this.dialogs = resolver.GetAllInstancesOf <IDialog>();
            if (this.dialogs == null)
            {
                this.dialogs = new List <IDialog>();
            }

            this.pbData = resolver.GetInstanceOf <IPBData>();
            ServiceLocator.Register <IFolderService>(new FolderService(pbData));

            this.webApi = resolver.GetInstanceOf <IPBWebAPI>();
            this.accountSettingsUserControl = new AccountSettings.AccountSettings(resolver)
            {
                Visibility = System.Windows.Visibility.Collapsed
            };
            this.accountSettingsUserControl.Loaded += accountSettingsUserControl_Loaded;
            this.searchViewModel              = new SearchViewModel(resolver, SecureHolderCollection);
            searchViewModel.ChangeVisibility += (o, e) =>
            {
                topGrid.Visibility = searchViewModel.IsOpen ? Visibility.Collapsed : Visibility.Visible;
                var component = components.FirstOrDefault(x => x.ID == selectedUIComponentID);
                if (component != null)
                {
                    component.Selected = !searchViewModel.IsOpen;
                }
            };

            folderTreeViewModel = new FoldersTreeViewModel(resolver);
            folderTreeViewModel.SelectedFolder_Changed += (o, e) =>
            {
                if (selectedUIComponentID != null)
                {
                    var component = components.FirstOrDefault(x => x.ID == selectedUIComponentID);
                    if (component != null && component.ViewModel is ISecureHolder)
                    {
                        ((ISecureHolder)component.ViewModel).UpdateTreeView();
                    }
                }
            };
            folderTreeViewModel.FolderList_Changed += (o, e) =>
            {
                Reload();
            };
            folderTreeViewModel.ItemsToFolder_Moved += (o, e) =>
            {
                if (selectedUIComponentID != null)
                {
                    foreach (var item in e.Items.GroupBy(x => (x as ISecureItemVM).Type))
                    {
                        var holder = SecureHolderCollection.FirstOrDefault(x => x.SecureItemType == item.Key);
                        if (holder != null)
                        {
                            holder.MoveSecureItemToFolder(item, e.FolderId);
                        }
                    }
                }
            };

            foreach (var holder in SecureHolderCollection)
            {
                holder.FolderListUpdated += (o, e) => { folderTreeViewModel.UpdateFolderTree(); };
                holder.DataUpdated       += (o, e) => { searchViewModel.Update(); };
                holder.AddSecureItem     += (o, e) => { addBtn_Click(null, null); };
            }


            syncImagesHelper = new SyncImagesHelper(pbData, webApi);
            //this.pbData.OnLoginToProfile(pbData_LoginToProfile);
            this.pbData.OnProfileLock  += ProfileLock;
            this.pbData.OnUserLoggedIn += pbData_OnUserLoggedIn;

            Title = this.pbData.ActiveUser;

            resizer = new WindowResizer(this);
            InitializeComponent();

            LoadMenu();
            //LoadDialog(dialogOrder);
            Closing += OnMainClosing;
            sync     = resolver.GetInstanceOf <IPBSync>();
            if (sync != null)
            {
                sync.OnSyncFinished      += sync_OnSyncFinished;
                sync.OnSyncDeviceDeleted += sync_OnSyncDeviceDeleted;
                //sync.OnSyncSuccess += sync_OnSyncSuccess;
            }

            var advertControl = new MainWindowAdvertising(resolver);

            inAppAdvertisingGrid.Children.Add(advertControl);
            Grid.SetColumn(advertControl, 1);

            ucMainSearchBox.DataContext       = searchViewModel;
            mainSearchResultPanel.DataContext = searchViewModel;
            selectFolderControl.DataContext   = folderTreeViewModel;

            this.ResizeMode    = System.Windows.ResizeMode.CanMinimize;
            this.ShowInTaskbar = true;
            LoadForShowOnStartup();
            if (_pbExtSecureBrowserBridge == null)
            {
                _pbExtSecureBrowserBridge = resolver.GetInstanceOf <IPBExtSecureBrowserBridge>();
            }
            this.Activated += MainWindow_Activated;
            SyncAsync();
            var test = this.FindName("menuUserControl") as MenuUserControl;

            this.DataContext = new MainWindowViewModel();
        }
        /// <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);
            }
        }