Exemplo n.º 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.");
            }
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 8
0
        public void SetTransactionAmount(long transactionAmount, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.TransactionAmount = transactionAmount;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }
Exemplo n.º 9
0
        public void SetSecurity(Security security, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.Security = security;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }
Exemplo n.º 10
0
        public void SetIsReconciled(bool isReconciled, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

                this.IsReconciled = isReconciled;
            }
            finally
            {
                this.Transaction.ExitCriticalSection();
            }
        }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
        public void SetAccount(Account account, TransactionLock transactionLock)
        {
            this.Transaction.EnterCriticalSection();

            try
            {
                this.Transaction.ValidateLock(transactionLock);

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