当前位置: 首页>>代码示例>>C#>>正文


C# ITransaction.Dispose方法代码示例

本文整理汇总了C#中ITransaction.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ITransaction.Dispose方法的具体用法?C# ITransaction.Dispose怎么用?C# ITransaction.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITransaction的用法示例。


在下文中一共展示了ITransaction.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Intercept

        public void Intercept(IInvocation invocation)
        {
            var sessionFactories = NHibernateSessionManager.SessionFactories;
            var method = invocation.Method;
            var isTransactionScoped = method.IsDecoratedBy(typeof(TransactionAttribute));

            if (isTransactionScoped) {
                foreach (var sessionFactory in sessionFactories)
                {
                    var session = sessionFactory.GetSession();

                    _transaction = sessionFactory.GetSession().Transaction.IsActive
                                ? _session.Transaction
                                : _session.BeginTransaction();
                }
                _transaction = _session.Transaction;

                try {
                    invocation.Proceed();

                    _transaction.Commit();
                } catch (Exception) {
                    _transaction.Rollback();

                    throw;
                } finally {
                    _transaction.Dispose();
                }
            }
        }
开发者ID:gofixiao,项目名称:Macsauto-Backup,代码行数:30,代码来源:TransactionInterceptor.cs

示例2: SynchronizedCase

		// TODO: implement WaitAll-semantics with returned task
		private void SynchronizedCase(IInvocation invocation, ITransaction transaction)
		{
			Contract.Requires(transaction.State == TransactionState.Active);

			if (_Logger.IsDebugEnabled)
				_Logger.DebugFormat("synchronized case");

			using (new TxScope(transaction.Inner, _Logger.CreateChildLogger("TxScope")))
			{
				var localIdentifier = transaction.LocalIdentifier;

				try
				{
					invocation.Proceed();

					if (transaction.State == TransactionState.Active)
						transaction.Complete();
					else if (_Logger.IsWarnEnabled)
						_Logger.WarnFormat(
							"transaction was in state {0}, so it cannot be completed. the 'consumer' method, so to speak, might have rolled it back.",
							transaction.State);
				}
				catch (TransactionAbortedException)
				{
					// if we have aborted the transaction, we both warn and re-throw the exception
					if (_Logger.IsWarnEnabled)
						_Logger.WarnFormat("transaction aborted - synchronized case, tx#{0}", localIdentifier);

					throw;
				}
				catch (TransactionException ex)
				{
					if (_Logger.IsFatalEnabled)
						_Logger.Fatal("internal error in transaction system - synchronized case", ex);

					throw;
				}
				catch (AggregateException ex)
				{
					if (_Logger.IsWarnEnabled)
						_Logger.Warn("one or more dependent transactions failed, re-throwing exceptions!", ex);
					throw;
				}
				catch (Exception)
				{
					if (_Logger.IsErrorEnabled)
						_Logger.ErrorFormat("caught exception, rolling back transaction - synchronized case - tx#{0}",
						                    localIdentifier);

					// the transaction rolls back itself on exceptions
					//transaction.Rollback();
					throw;
				}
				finally
				{
					if (_Logger.IsDebugEnabled)
						_Logger.DebugFormat("dispoing transaction - synchronized case - tx#{0}", localIdentifier);

					transaction.Dispose();
				}
			}
		}
开发者ID:andreabalducci,项目名称:Castle.Transactions,代码行数:63,代码来源:TransactionInterceptor.cs

示例3: SynchronizedCase

		private static void SynchronizedCase(IInvocation invocation, ITransaction transaction)
		{
			Contract.Requires(transaction.State == TransactionState.Active);
			_Logger.DebugFormat("synchronized case");

			using (new TransactionScope(transaction.Inner))
			{
				try
				{
					invocation.Proceed();

					if (transaction.State == TransactionState.Active)
						transaction.Complete();

					else
						_Logger.WarnFormat(
							"transaction was in state {0}, so it cannot be completed. the 'consumer' method, so to speak, might have rolled it back.",
							transaction.State);
				}
				catch (TransactionAbortedException)
				{
					// if we have aborted the transaction, we both warn and re-throw the exception
					_Logger.Warn("transaction aborted - synchronized case");
					throw;
				}
				catch (TransactionException ex)
				{
					if (_Logger.IsFatalEnabled)
						_Logger.Fatal("internal error in transaction system - synchronized case", ex);

					throw;
				}
				catch (Exception)
				{
					if (_Logger.IsErrorEnabled)
						_Logger.ErrorFormat("caught exception, rolling back transaction - synchronized case - tx#{0}",
						                    transaction.LocalIdentifier);

					transaction.Rollback();
					throw;
				}
				finally
				{
					if (_Logger.IsDebugEnabled)
						_Logger.DebugFormat("dispoing transaction - synchronized case - tx#{0}", transaction.LocalIdentifier);

					transaction.Dispose();
				}
			}
		}
开发者ID:bittercoder,项目名称:Castle.Transactions,代码行数:50,代码来源:TransactionInterceptor.cs

示例4: DisposeTransaction

 private ITransaction DisposeTransaction(ITransaction transaction)
 {
     if (transaction != null)
     {
         transaction.Commit();
         transaction.Dispose();
         transaction = null;
     }
     return transaction;
 }
开发者ID:rolfwessels,项目名称:databaseversioncontrol,代码行数:10,代码来源:DvcController.cs

示例5: AsyncCase

		private void AsyncCase(IInvocation invocation, ITransaction transaction)
		{
			Contract.Requires(transaction.State == TransactionState.Active);

			var txScope = new TxScope(transaction.Inner, _Logger.CreateChildLogger("TxScope"));

			// using (new TxScope(transaction.Inner, _Logger.CreateChildLogger("TxScope")))
			// var localIdentifier = transaction.LocalIdentifier;

			invocation.Proceed();

			var ret = (Task) invocation.ReturnValue;
					
			if (!ret.IsCompleted)
			{
				ret.ContinueWith((t, aTransaction) =>
				{
					var tran = (ITransaction) aTransaction;

					if (!t.IsFaulted && !t.IsCanceled)
					{
						if (tran.State == TransactionState.Active)
						{
							try
							{
								tran.Complete();
							}
							catch (Exception) { }
						}
					}

					tran.Dispose();

				}, transaction, TaskContinuationOptions.AttachedToParent);
			}
			else
			{
				if (transaction.State == TransactionState.Active)
					transaction.Complete();
				else if (_Logger.IsWarnEnabled)
					_Logger.WarnFormat(
						"transaction was in state {0}, so it cannot be completed. the 'consumer' method, so to speak, might have rolled it back.",
						transaction.State);

				transaction.Dispose();
			}
		}
开发者ID:hammett,项目名称:Castle.Transactions,代码行数:47,代码来源:TransactionInterceptor.cs


注:本文中的ITransaction.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。