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)); } }
private void EditAccount(AccountNodeViewModel accountVm) { if (!_accountDirectory.TryGetById(accountVm.Id, out var account)) { return; } var oldAccount = account.Clone(); var dialog = _viewModelFactory.Value.CreateAccountEditor(account); if (_dialogService.ShowDialog(dialog) is true) { account.Name = dialog.Name; account.Endpoint = dialog.Endpoint; account.Key = dialog.Key; account.IsServerless = dialog.IsServerless; account.Folder = dialog.Folder.Trim('/'); _accountDirectory.Update(account); _accountDirectory.Save(); accountVm.Name = account.Name; _messenger.Publish(new AccountEditedMessage(account, oldAccount)); } }
private void Remove(AccountNodeViewModel accountVm) { if (!_dialogService.Confirm($"Are you sure you want to remove account '{accountVm.Name}'?")) { return; } if (!_accountDirectory.TryGetById(accountVm.Id, out var account)) { return; } _accountDirectory.Remove(accountVm.Id); _accountDirectory.Save(); _messenger.Publish(new AccountRemovedMessage(account)); }
private async Task CreateAsync(AccountNodeViewModel accountVm) { var dialog = _viewModelFactory.Value.CreateDatabaseEditor(null, null, accountVm.Context.IsServerless); if (_dialogService.ShowDialog(dialog) is true) { var(database, throughput) = dialog.GetDatabase(); try { await accountVm.Context.Databases.CreateDatabaseAsync(database, throughput, default); _messenger.Publish(new DatabaseCreatedMessage(accountVm.Context, database)); } catch (CosmosException ex) when(throughput.HasValue && ex.StatusCode == HttpStatusCode.BadRequest && ex.Message.Contains("serverless", StringComparison.OrdinalIgnoreCase)) { _dialogService.ShowError("Failed to create database with provisioned throughput, because the account seems to be serverless. If this is a serverless account, please specify it in the account configuration."); } } }