public void Validate()
 {
     CosmosAccount.Validate();
     StorageAccount.Validate();
     SourceCollection.Validate();
     TargetCollection.Validate();
 }
        private void LoadAccounts()
        {
            var nodes = _accountDirectory.GetRootNodes();
            var root  = new List <TreeNodeViewModel>();

            foreach (var node in nodes)
            {
                var vm = node switch
                {
                    CosmosAccount account =>
                    (TreeNodeViewModel)_viewModelFactory.CreateAccountNode(
                        account,
                        _accountContextFactory.Create(account),
                        null),
                    CosmosAccountFolder folder => (TreeNodeViewModel)_viewModelFactory.CreateAccountFolderNode(folder, null),
                    _ => throw new Exception("Invalid node type")
                };
                root.Add(vm);
            }
            foreach (var c in root.OrderByDescending(n => n is AccountFolderNodeViewModel)
                     .ThenBy(c => c.Text))
            {
                RootNodes.Add(c);
            }
        }
Exemple #3
0
        private void AddAccount(TreeNodeViewModel?parent)
        {
            string folder = parent switch
            {
                AccountFolderNodeViewModel f => f.FullPath,
                AccountNodeViewModel a => (a.Parent as AccountFolderNodeViewModel)?.FullPath ?? string.Empty,
                _ => string.Empty
            };

            var dialog = _viewModelFactory.Value.CreateAccountEditor();

            dialog.Folder = folder;
            if (_dialogService.ShowDialog(dialog) is true)
            {
                var newAccount = new CosmosAccount
                {
                    Id           = Guid.NewGuid().ToString(),
                    Name         = dialog.Name,
                    Endpoint     = dialog.Endpoint,
                    Key          = dialog.Key,
                    IsServerless = dialog.IsServerless,
                    Folder       = dialog.Folder.Trim('/')
                };
                _accountDirectory.Add(newAccount);
                _accountDirectory.Save();

                _messenger.Publish(new AccountAddedMessage(newAccount));
            }
        }
        public AccountNodeViewModel(
            CosmosAccount account,
            IAccountContext context,
            AccountFolderNodeViewModel?parent,
            AccountCommands accountCommands,
            DatabaseCommands databaseCommands,
            IViewModelFactory viewModelFactory,
            IMessenger messenger,
            IClientPool clientPool)
        {
            Id                = account.Id;
            Context           = context;
            Parent            = parent;
            _viewModelFactory = viewModelFactory;
            _clientPool       = clientPool;
            _name             = account.Name;

            Commands = new[]
            {
                new CommandViewModel("Create database", databaseCommands.CreateCommand, this),
                CommandViewModel.Separator(),
                new CommandViewModel("Refresh", RefreshCommand),
                CommandViewModel.Separator(),
                new CommandViewModel("Add account", accountCommands.AddCommand, Parent),
                new CommandViewModel("Edit account", accountCommands.EditCommand, this),
                new CommandViewModel("Remove account", accountCommands.RemoveCommand, this),
            };

            messenger.Subscribe(this).To <AccountEditedMessage>((vm, message) => vm.OnAccountEdited(message));
            messenger.Subscribe(this).To <DatabaseCreatedMessage>((vm, message) => vm.OnDatabaseCreated(message));
            messenger.Subscribe(this).To <DatabaseDeletedMessage>((vm, message) => vm.OnDatabaseDeleted(message));
        }
Exemple #5
0
        public CosmosClient GetClientForAccount(CosmosAccount account)
        {
            if (account is null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            return(_clients.GetOrAdd(account.Id, _ => CreateClient(account)));
        }
        public async Task AddCosmosAccount(string accountUri, string accountKey)
        {
            var account = new CosmosAccount
            {
                Endpoint  = accountUri.TrimEnd('/'),
                MasterKey = accountKey
            };
            await _dataContext.AddAsync(account);

            await _dataContext.SaveChangesAsync();
        }
Exemple #7
0
        public void RemoveClientForAccount(CosmosAccount account)
        {
            if (account is null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            if (_clients.TryRemove(account.Id, out var client))
            {
                client.Dispose();
            }
        }
 public void Validate()
 {
     CosmosAccount.Validate();
     StorageAccount.Validate();
     GeneralPlan.Validate();
     if (Collections.Length == 0)
     {
         throw new CosbakException("No collection defined");
     }
     foreach (var collection in Collections)
     {
         collection.Validate();
     }
 }
Exemple #9
0
        private void LoadAccounts()
        {
            var nodes = _accountDirectory.GetRootNodes();

            foreach (var node in nodes)
            {
                var vm = node switch
                {
                    CosmosAccount account =>
                    (TreeNodeViewModel)_viewModelFactory.CreateAccountNode(
                        account,
                        _accountContextFactory.Create(account),
                        null),
                    CosmosAccountFolder folder => (TreeNodeViewModel)_viewModelFactory.CreateAccountFolderNode(folder, null),
                    _ => throw new Exception("Invalid node type")
                };

                RootNodes.Add(vm);
            }
        }
        protected override Task <IEnumerable <TreeNodeViewModel> > LoadChildrenAsync()
        {
            var childNodes = _accountDirectory.GetChildNodes(_folder.FullPath);
            var result     = new List <TreeNodeViewModel>();

            foreach (var node in childNodes)
            {
                var childVM = node switch
                {
                    CosmosAccount account =>
                    (TreeNodeViewModel)_viewModelFactory.CreateAccountNode(
                        account,
                        _accountContextFactory.Create(account),
                        this),
                    CosmosAccountFolder folder => (TreeNodeViewModel)_viewModelFactory.CreateAccountFolderNode(folder, this),
                    _ => throw new Exception("Invalid node type")
                };
                result.Add(childVM);
            }
            return(Task.FromResult <IEnumerable <TreeNodeViewModel> >(result));
        }
Exemple #11
0
 public AccountContext(CosmosAccount account, Func <CosmosClient> clientGetter)
 {
     _account      = account;
     _clientGetter = clientGetter;
     Databases     = new DatabaseService(clientGetter);
 }
 public AccountAddedMessage(CosmosAccount account)
 {
     Account = account;
 }
 public IAccountContext Create(CosmosAccount account)
 {
     return(new AccountContext(account, () => _clientPool.GetClientForAccount(account)));
 }
Exemple #14
0
 private CosmosClient CreateClient(CosmosAccount account)
 {
     return(new CosmosClient(account.Endpoint, account.Key));
 }
 public AccountEditedMessage(CosmosAccount account, CosmosAccount oldAccount)
 {
     Account    = account;
     OldAccount = oldAccount;
 }
 public void Add(CosmosAccount account)
 {
     _accounts.Add(account.Id, account.Clone());
 }
 public void Update(CosmosAccount account)
 {
     if (!TryGetById(account.Id, out var existing, false))
     {
         Add(account);
     }
Exemple #18
0
 public AccountRemovedMessage(CosmosAccount account)
 {
     Account = account;
 }