internal void ValidateLock(TransactionLock transactionLock) { if (this.currentLock == null) { throw new InvalidOperationException("Could not modify the transaction, because it is not currently locked for editing."); } if (this.currentLock != transactionLock) { throw new InvalidOperationException("Could not modify the transaction, because the lock provided was not valid."); } }
/// <summary> /// Sets an extension on the transaction. /// </summary> /// <param name="name">The name of the extension.</param> /// <param name="value">The value of the extension.</param> /// <param name="transactionLock">A <see cref="SharpBooks.TransactionLock"/> obtained from the <see cref="SharpBooks.Transaction.Lock" /> function.</param> public void SetExtension(string name, string value, TransactionLock transactionLock) { lock (this.lockMutex) { this.ValidateLock(transactionLock); if (value == null) { this.extensions.Remove(name); } else { this.extensions[name] = value; } } }
internal void Unlock(TransactionLock transactionLock) { lock (this.lockMutex) { if (this.currentLock == null) { throw new InvalidOperationException("Could not unlock the transaction, because it is not currently locked."); } if (this.currentLock != transactionLock) { throw new InvalidOperationException("Could not unlock the transaction, because the lock provided was not valid."); } this.currentLock = null; } }
/// <summary> /// Removes a previously added split from the transaction. /// </summary> /// <param name="split">The previously added split.</param> /// <param name="transactionLock">A <see cref="SharpBooks.TransactionLock"/> obtained from the <see cref="Lock" /> function.</param> public void RemoveSplit(Split split, TransactionLock transactionLock) { if (split == null) { throw new ArgumentNullException("split"); } lock (this.lockMutex) { this.ValidateLock(transactionLock); if (!this.splits.Contains(split)) { throw new InvalidOperationException("Could not remove the split from the transaction, because the split is not a member of the transaction."); } this.splits.Remove(split); split.Transaction = null; } }
/// <summary> /// Sets the date and time at which the transaction took place. /// </summary> /// <param name="date">The date and time at which the transaction took place.</param> /// <param name="transactionLock">A <see cref="SharpBooks.TransactionLock"/> obtained from the <see cref="SharpBooks.Transaction.Lock" /> function.</param> public void SetDate(DateTime date, TransactionLock transactionLock) { if (date.Kind != DateTimeKind.Utc) { throw new ArgumentOutOfRangeException("date"); } lock (this.lockMutex) { this.ValidateLock(transactionLock); this.Date = date; } }
/// <summary> /// Creates a new split and adds it to the transaction. /// </summary> /// <param name="transactionLock">A <see cref="SharpBooks.TransactionLock"/> obtained from the <see cref="SharpBooks.Transaction.Lock" /> function.</param> /// <returns>The newly created split.</returns> public Split AddSplit(TransactionLock transactionLock) { lock (this.lockMutex) { this.ValidateLock(transactionLock); var split = new Split(this); this.splits.Add(split); return split; } }
/// <summary> /// Locks the transaction for editing. /// </summary> /// <returns>A <see cref="SharpBooks.TransactionLock"/> that must be used for all modifications to the transaction.</returns> /// <remarks> /// The transaction will be unlocked when the <see cref="SharpBooks.TransactionLock"/> is disposed. /// </remarks> public TransactionLock Lock() { lock (this.lockMutex) { if (this.currentLock != null) { throw new InvalidOperationException("Could not lock the transaction, because it is already locked."); } this.currentLock = new TransactionLock(this); return this.currentLock; } }
public void SetTransactionAmount(long transactionAmount, TransactionLock transactionLock) { this.Transaction.EnterCriticalSection(); try { this.Transaction.ValidateLock(transactionLock); this.TransactionAmount = transactionAmount; } finally { this.Transaction.ExitCriticalSection(); } }
public void SetSecurity(Security security, TransactionLock transactionLock) { this.Transaction.EnterCriticalSection(); try { this.Transaction.ValidateLock(transactionLock); this.Security = security; } finally { this.Transaction.ExitCriticalSection(); } }
public void SetIsReconciled(bool isReconciled, TransactionLock transactionLock) { this.Transaction.EnterCriticalSection(); try { this.Transaction.ValidateLock(transactionLock); this.IsReconciled = isReconciled; } finally { this.Transaction.ExitCriticalSection(); } }
public void SetDateCleared(DateTime? dateCleared, TransactionLock transactionLock) { if (dateCleared.HasValue && dateCleared.Value.Kind != DateTimeKind.Utc) { throw new ArgumentOutOfRangeException("dateCleared"); } this.Transaction.EnterCriticalSection(); try { this.Transaction.ValidateLock(transactionLock); this.DateCleared = dateCleared; } finally { this.Transaction.ExitCriticalSection(); } }
public void SetAccount(Account account, TransactionLock transactionLock) { this.Transaction.EnterCriticalSection(); try { this.Transaction.ValidateLock(transactionLock); this.Account = account; } finally { this.Transaction.ExitCriticalSection(); } }