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


C# ITransaction.Complete方法代码示例

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


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

示例1: ValidateTransaction

            //验证Transaction
            internal void ValidateTransaction(ITransaction transaction)
            {
                IList<IMessage> children = transaction.Children;
                int len = children.Count;
                for (int i = 0; i < len; i++)
                {
                    IMessage message = children[i];
                    var transaction1 = message as ITransaction;
                    if (transaction1 != null)
                    {
                        ValidateTransaction(transaction1);
                    }
                }

                if (!transaction.IsCompleted())
                {
                    // missing transaction end, log a BadInstrument event so that
                    // developer can fix the code
                    IMessage notCompleteEvent = new DefaultEvent("CAT", "BadInstrument")
                                                    {Status = "TransactionNotCompleted"};
                    notCompleteEvent.Complete();
                    transaction.AddChild(notCompleteEvent);
                    transaction.Complete();
                }
            }
开发者ID:kangzhenkang,项目名称:cat.net,代码行数:26,代码来源:DefaultMessageManager.cs

示例2: 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

示例3: 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

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