/// <summary> /// See <see cref="IAccountOperationFactory.CreateEditAccountOperation"/>. /// </summary> /// <param name="account">The account to edit.</param> /// <returns></returns> public AccountManagementEditOperation CreateEditAccountOperation(Account account) { DefaultAccountDialogViewModel accountEditor = new DefaultAccountDialogViewModel(account); DefaultAccountManagementControl control = new DefaultAccountManagementControl(accountEditor); AccountManagementEditOperation operation = new AccountManagementEditOperation(accountEditor, control); return operation; }
/// <summary> /// Use this constructor when creating a dialog that will be used on an edited account /// </summary> /// <param name="account">the existing account to be edited</param> /// <param name="factory"></param> public AccountDialogViewModel(Account account, IAccountOperationFactory factory) { if (account != null) { this.accountOperation = factory.CreateEditAccountOperation(account); Confirm = new CommandBase(ConfirmEdit); Cancel = new CommandBase(CancelEdit); } else { this.accountOperation = factory.CreateAddAccountOperation(); Confirm = new CommandBase(ConfirmNew); Cancel = new CommandBase(CancelNew); } }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { try { string alias = txtAlias.Text; string taskTenantUrl = txtUrl.Text; string accountName = txtAccount.Text; string key = txtKey.Text; Account account = new Account(alias, accountName, taskTenantUrl, key); window.accounts.AddAccount(account); window.accounts.Serialize(); window.AccountsComboBox.Items.Add(new ComboBoxItem(){Content = alias }); this.Close(); } catch (Exception ex) { MessageBox.Show(string.Format("Add Account:\n{0}", ex)); } }
/// <summary> /// See <see cref="IAccountManager.DeleteAccountAsync"/>. /// </summary> /// <param name="account">The account to be removed.</param> /// <returns>The asynchronous operation.</returns> public async Task DeleteAccountAsync(Account account) { if (!this.Accounts.Contains(account)) { throw new Exception("Attept to remove unrecognized account"); } Account tempAccount = null; //We are waiting on an account being edited, so we need to make sure our editing index is still accurate after the move if (this.editingIndex >= 0) { tempAccount = this.Accounts[this.editingIndex]; } this.Accounts.Remove(account); //We were tracking an account before the remove, so update the edit index if (tempAccount != null) { this.editingIndex = this.Accounts.IndexOf(tempAccount); } this.FirePropertyChangedEvent("HasAccounts"); await this.SaveAccountsAsync().ConfigureAwait(false); }
public BasicDataProvider(Account currentAccount) { this.CurrentAccount = currentAccount; this.Service = new BatchService(new BatchSharedKeyCredentials(this.CurrentAccount.BatchServiceUrl, this.CurrentAccount.AccountName, this.CurrentAccount.Key)); }
protected bool Equals(Account other) { return string.Equals(this.Alias, other.Alias, StringComparison.CurrentCultureIgnoreCase); }
/// <summary> /// Use this constructor when creating a dialog that will be used on an edited account /// </summary> /// <param name="account">the existing account to be edited</param> public DefaultAccountDialogViewModel(Account account) { this.account = account; }
/// <summary> /// See <see cref="IAccountManager.CommitEditAsync"/>. /// </summary> /// <param name="account">The edited clone.</param> /// <returns>The asynchronous operation.</returns> public async Task CommitEditAsync(Account account) { if (this.editingIndex < 0) { throw new Exception("Commit was called but no account was selected for edit"); } bool accountAlreadyExists = this.Accounts.Any(acct => acct.Equals(account) && acct.UniqueIdentifier != account.UniqueIdentifier); if (accountAlreadyExists) { throw new Exception(string.Format(CultureInfo.CurrentCulture, "Account with alias {0} has already been added", account.Alias)); } //Replace the selected account with the cloned account this.Accounts[this.editingIndex] = account; this.Accounts.RemoveAt(this.editingIndex); this.Accounts.Insert(this.editingIndex, account); this.editingIndex = -1; await this.SaveAccountsAsync().ConfigureAwait(false); }
/// <summary> /// See <see cref="IAccountManager.CloneAccountForEditAsync"/>. /// </summary> /// <param name="account">The account to clone.</param> /// <returns>A deep clone of the account.</returns> public async Task<Account> CloneAccountForEditAsync(Account account) { this.editingIndex = this.Accounts.IndexOf(account); if (this.editingIndex < 0) { throw new Exception("Attempt was made to edit unrecognized account"); } var clone = new DefaultAccount(this) { AccountName = account.AccountName, Alias = account.Alias, Key = account.Key, BatchServiceUrl = account.BatchServiceUrl, UniqueIdentifier = account.UniqueIdentifier, ParentAccountManager = this }; return clone; }
/// <summary> /// See <see cref="IAccountManager.AddAccountAsync"/>. /// </summary> /// <param name="account">The account to be added.</param> /// <returns>The asynchronous operation.</returns> public async Task AddAccountAsync(Account account) { if (this.Accounts.Contains(account)) { //TODO: Should this be a custom exception type? throw new Exception(string.Format(CultureInfo.CurrentCulture, "Account with alias {0} has already been added", account.Alias)); } if (!(account is DefaultAccount)) { throw new Exception(string.Format("Account type: {0}, expected Type: {1}", account.GetType().Name, typeof(DefaultAccount).Name)); } this.Accounts.Add(account); this.FirePropertyChangedEvent("HasAccounts"); await this.SaveAccountsAsync().ConfigureAwait(false); }