Ejemplo n.º 1
0
        /// <summary>
        ///     Commit transaction.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     - transaction is not active;
        ///     - transaction is owned by a managed transaction
        /// </exception>
        /// <exception cref="TransactionNotificationException">
        ///		Transaction notification failed. If failure occurred while sending preparation notifications the commit will not proceed (can try later).
        ///		Otherwise, when exception is thrown from <see cref="ITransactionNotification.TransactionCompleted(IFileSystemTransaction, bool)"/>, the transaction is already
        ///		committed and durable.
        ///		<seealso cref="TransactionNotificationException.NotificationType"/>
        /// </exception>
        /// <exception cref="StorageTransactionException">
        ///		Call to KTM API failed.
        /// </exception>
        public void Commit()
        {
            Check.DoCheckOperationValid(IsHandleValid, "Transaction is not active");
            Check.DoCheckOperationValid(!IsSlave, "Use owning managed transaction");

            try
            {
                NotifyPrepare();
            }
            catch (TransactionNotificationException e)
            {
                _log.ErrorFormat("Transaction Prepare notification failed, commit aborted: {0}", e);
                throw;
            }

            _log.Debug("Committing KTM transaction");
            try
            {
                _ktmHandle.Commit();
            }
            catch (Win32Exception e)
            {
                _log.ErrorFormat("KtmTransaction Commit failed: {0}", e);
                throw new StorageTransactionException(
                          message: string.Format("Failed committing KTM transaction - {0}", e.Message)
                          , technicalInfo: string.Empty
                          , innerException: e);
            }
            _status = TransactionStatus.Committed;
            // exceptions ok to flow through if any
            NotifyCompletion(true);
        }