예제 #1
0
        public MainVM()
        {
            this.Explorer         = new ExplorerVM(this);
            this.CurrentWorkspace = new HomeWrkspcVM();

            foreach (var savedAccount in Config.Instance.DocDbAccounts)
            {
                this.Explorer.ConnectToSavedAccount(savedAccount);
            }

            this.AddAccountCommand = new LambdaCommand((o) =>
            {
                DocDbAccountCredentialsDlg.ShowDialog((credentials) =>
                {
                    this.Explorer.ConnectToAccount(credentials);
                });
            });
        }
예제 #2
0
 public AccountExpItemVM(AccountModel model, MainVM main) : base(main)
 {
     IsBroken = false;
     _model   = model;
     this.Children.Add(new DummyExpItemVM(main));
     this.ContextMenuItems.Add(new MenuItemVM()
     {
         Caption = "Refresh",
         Command = new LambdaCommand(async(o) =>
         {
             await this.LoadDatabases();
         })
     });
     this.ContextMenuItems.Add(new MenuItemVM()
     {
         Caption = "Create database",
         Command = new LambdaCommand(async(o) =>
         {
             if (IsBroken)
             {
                 MessageBox.Show("Can't create database on a broken connect, check error message, try to reenter credentials.");
                 return;
             }
             var dlg = new NameSelector("New database name");
             if (dlg.ShowDialog() == true && dlg.Value.IsNotEmpty())
             {
                 var created = await _model.CreateDatabase(dlg.Value);
                 this.Children.Insert(0, new DatabaseExpItemVM(this, created, this.Main));
             }
         })
     });
     this.ContextMenuItems.Add(new MenuItemVM()
     {
         Caption = "Change access data",
         Command = new LambdaCommand((o) =>
         {
             var oldEndpoint = _model.Endpoint;
             DocDbAccountCredentialsDlg.ShowDialog(_model.Credentials, async(creds) =>
             {
                 await performWithIsBrokenTest(async() =>
                 {
                     this.Children.Clear();
                     await _model.RefreshCredentials();
                     foreach (var db in this._model.Databases)
                     {
                         this.Children.Add(new DatabaseExpItemVM(this, db, this.Main));
                     }
                     Config.Instance.ChangeAccountCredentials(oldEndpoint, _model.Credentials);
                 });
             });
         })
     });
     this.ContextMenuItems.Add(new MenuItemVM()
     {
         Caption = "Remove",
         Command = new LambdaCommand((o) =>
         {
             MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Removal Confirmation", System.Windows.MessageBoxButton.YesNo);
             if (messageBoxResult == MessageBoxResult.Yes)
             {
                 main.Explorer.RootItems.Remove(this);
                 Config.Instance.RemoveAccount(_model.Endpoint);
             }
         })
     });
 }