예제 #1
0
        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.");
            }
        }
예제 #2
0
        /// <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;
                }
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        /// <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;
            }
        }
예제 #5
0
        /// <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;
            }
        }
예제 #6
0
        /// <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;
            }
        }
예제 #7
0
        /// <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;
            }
        }
예제 #8
0
파일: Split.cs 프로젝트: otac0n/SharpBooks
        public void SetTransactionAmount(long transactionAmount, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.TransactionAmount = transactionAmount;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }
예제 #9
0
파일: Split.cs 프로젝트: otac0n/SharpBooks
        public void SetSecurity(Security security, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.Security = security;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }
예제 #10
0
파일: Split.cs 프로젝트: otac0n/SharpBooks
        public void SetIsReconciled(bool isReconciled, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.IsReconciled = isReconciled;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }
예제 #11
0
파일: Split.cs 프로젝트: otac0n/SharpBooks
        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();
            }
        }
예제 #12
0
파일: Split.cs 프로젝트: otac0n/SharpBooks
        public void SetAccount(Account account, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.Account = account;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }