public int AddAccount(IAccount account) { int id = Interlocked.Increment(ref count); var newOne = new Account(id, account); if (string.IsNullOrEmpty(newOne.DomainName)) { throw new AccountsException(AccountsErrors.DomainRequred); } if (accounts2.TryAdd(newOne.DomainName, newOne) == false) { throw new AccountsException(AccountsErrors.DomainUsed); } if (accounts1.TryAdd(id, newOne) == false) { throw new AccountsException(AccountsErrors.IdUsed); } try { files.IgnoryFileChanges(id); newOne.Serialize(files.GetFileName(id)); } catch { accounts2.Remove(newOne.DomainName); accounts1.Remove(id); throw; } return(id); }
public void UpdateAccount(IAccount account) { if (account.Id == Account.InvalidId) { throw new AccountsException(AccountsErrors.InvalidId); } var newOne = new Account(account); var oldOne = accounts1.GetValue(account.Id); if (oldOne == null) { throw new AccountsException(AccountsErrors.OldNotFound); } if (string.IsNullOrEmpty(newOne.DomainName)) { throw new AccountsException(AccountsErrors.DomainRequred); } if (newOne.DomainName != oldOne.DomainName) { if (accounts2.TryAdd(newOne.DomainName, newOne) == false) { throw new AccountsException(AccountsErrors.DomainUsed); } accounts2.Remove(oldOne.DomainName); } files.IgnoryFileChanges(account.Id); newOne.Serialize(files.GetFileName(account.Id)); }
public int AddAccount(IAccount account) { int id = Interlocked.Increment(ref count); var newOne = new Account(id, account); if (string.IsNullOrEmpty(newOne.DomainName)) throw new AccountsException(AccountsErrors.DomainRequred); if (accounts2.TryAdd(newOne.DomainName, newOne) == false) throw new AccountsException(AccountsErrors.DomainUsed); if (accounts1.TryAdd(id, newOne) == false) throw new AccountsException(AccountsErrors.IdUsed); try { files.IgnoryFileChanges(id); newOne.Serialize(files.GetFileName(id)); } catch { accounts2.Remove(newOne.DomainName); accounts1.Remove(id); throw; } return id; }
public void UpdateAccount(IAccount account) { if (account.Id == Account.InvalidId) throw new AccountsException(AccountsErrors.InvalidId); var newOne = new Account(account); var oldOne = accounts1.GetValue(account.Id); if (oldOne == null) throw new AccountsException(AccountsErrors.OldNotFound); if (string.IsNullOrEmpty(newOne.DomainName)) throw new AccountsException(AccountsErrors.DomainRequred); if (newOne.DomainName != oldOne.DomainName) { if (accounts2.TryAdd(newOne.DomainName, newOne) == false) throw new AccountsException(AccountsErrors.DomainUsed); accounts2.Remove(oldOne.DomainName); } files.IgnoryFileChanges(account.Id); newOne.Serialize(files.GetFileName(account.Id)); }