コード例 #1
0
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        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
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        /// <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
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        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
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        /// <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
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        /// <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
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        /// <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
ファイル: Transaction.cs プロジェクト: otac0n/SharpBooks
        /// <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();
            }
        }