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


C# CommittableTransaction.DependentClone方法代码示例

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


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

示例1: CommittableTransaction

        /// <summary>
        /// 
        /// </summary>
        /// <returns>Retrieved work item or null if not found, didn't pass pre-check, etc.</returns>
        private WorkItem GetWorkItemFromQueue
            ()
        {
            //TODO: Pay great attention here, now workItemCandidate is an instance field!!! (SD)
            workItemCandidate = null;

            #region Get message from queue

            var transaction = new CommittableTransaction();

            try
            {

                Job job;


                using (DependentTransaction dependentTransaction =
                    transaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete))
                {
                    using (var scope = new TransactionScope(dependentTransaction))
                    {
                        job = ItemProvider.GetNextItem();
                        scope.Complete();
                    }

                    dependentTransaction.Complete();
                }

                if (job != null)
                {
                    PerformanceHandler.HandleEvent("Reads From Queue/sec", 1);

                    workItemCandidate = new RequestWorkItem(job.ContextIdentifier.InternalId,
                                                            0, WorkItemState.AvailableForProcessing,
                                                            SubmissionPriority.Normal, null, false, false, "test",
                                                            new ContextIdentifier());
                    // Set transaction on the work item
                    workItemCandidate.Transaction = transaction;
                    workItemCandidate.RetrievedAt = DateTime.Now;
                    workItemCandidate.MessageBody = SerializationUtility.Serialize2ByteArray(job);
                }
                else
                {
                    workItemCandidate = null;
                }

                FailureExceptionHandler.ResetState();
            }
            catch (Exception ex)
            {
                try
                {
                    // Rollback the commitable transaction
                    transaction.Rollback(ex);
                }
                finally
                {
                    transaction.Dispose();
                }

                Log.Source.TraceData(TraceEventType.Error,
                                     ProducerMessage.ErrorDuringObtainingTheWorkItem,
                                     new ContextualLogEntry
                                         {
                                             Message =
                                                 "Exception happened when trying to get item from the message queue (" +
                                                 "queue.QueuePath" + "). " + Environment.NewLine + ex
                                             ,
                                             ContextIdentifier =
                                                 ((workItemCandidate != null)
                                                      ? workItemCandidate.ContextIdentifier
                                                      :
                                                          new ContextIdentifier())
                                         });
                // To review what is the required handling here for us (SD)
                if (ExecutionState == ProcessExecutionState.Running)
                {
                    FailureExceptionType type = FailureExceptionHandler.HandleFailure(ex);
                    if (type == FailureExceptionType.NonRecoverable)
                        Stop();
                }
                else
                {
                    if (workItemCandidate != null)
                    {
                        Log.Source.TraceData(TraceEventType.Information,
                                             ProducerMessage.RetrievedMessageReturnedToTheRetrievalQueue,
                                             new ContextualLogEntry
                                                 {
                                                     Message =
                                                         string.Format
                                                         (
                                                         "'{0}': Retrieved Recurrence(Id = {1}) Successfully Saved to the {2} queue",
                                                         Name,
                                                         workItemCandidate.Id,
                                                         ""
//.........这里部分代码省略.........
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:101,代码来源:SampleWorkItemsProducer.cs

示例2: ExplicitTransactionWithDependentTransaction

		public void ExplicitTransactionWithDependentTransaction()
		{
			using (var t = new CommittableTransaction())
			using (new TxScope(t, NullLogger.Instance))
			{
				Console.WriteLine("T1 STATUS: {0}", t.TransactionInformation.Status);

				using (var c = GetConnection())
				using (var cmd = c.CreateCommand())
				{
					cmd.CommandText = "SELECT TOP 1 Val FROM Thing";
					var scalar = (double)cmd.ExecuteScalar();
					Console.WriteLine("T1 STATUS: {0}", t.TransactionInformation.Status);
					Console.WriteLine("got val {0}, disposing command and connection", scalar);
				}

				using (var t2 = t.DependentClone(DependentCloneOption.RollbackIfNotComplete))
				using (new TxScope(t2, NullLogger.Instance))
				using (var c = GetConnection())
				using (var cmd = c.CreateCommand())
				{
					t2.TransactionCompleted +=
						(s, ea) =>
						Console.WriteLine("::: T2 TransactionCompleted: {0}", ea.Transaction.TransactionInformation.LocalIdentifier);
					cmd.CommandText = "DELETE FROM Thing";
					Console.WriteLine("T2: EXECUTING NON QUERY");
					cmd.ExecuteNonQuery();

					Console.WriteLine("T2: Enlisting volatile");
					t2.EnlistVolatile(new VolatileResource(false), EnlistmentOptions.None);

					Console.WriteLine("T2: COMPLETE-CALL");
					t2.Complete();
					Console.WriteLine("T2 STATUS: {0}", t2.TransactionInformation.Status);
				}

				Console.WriteLine("T1: COMMITTING, status: {0}", t.TransactionInformation.Status);
				try
				{
					t.Commit();
				}
				catch (TransactionAbortedException e)
				{
					Console.WriteLine("TransactionAbortedException, {0}", e);
					t.Rollback(e);
				}
				Console.WriteLine("T1 STATUS: {0}", t.TransactionInformation.Status);
				Console.WriteLine("T1: DISPOSING");
			}
		}
开发者ID:ols,项目名称:Castle.Facilities.NHibernate,代码行数:50,代码来源:ScratchBoard_LTM.cs

示例3: GetWorkItemFromQueue

        /// <summary>
        /// 
        /// </summary>
        /// <param name="priority"></param>
        /// <returns>Retrieved work item or null if not found, didn't pass pre-check, etc.</returns>
        private WorkItem GetWorkItemFromQueue(SubmissionPriority priority)
        {
            //TODO: Pay great attention here, now workItemCandidate is an instance field!!! (SD)
            workItemCandidate = null;
            WorkItem workItem = null;
            Tools.Commands.Implementation.IF1.req item = null;

            Trace.CorrelationManager.ActivityId = Guid.NewGuid();


            #region Get message from queue

            var transaction = new CommittableTransaction();

            try
            {
                #region Get next job from the queue

                //var 

                using (DependentTransaction dependentTransaction =
                    transaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete))
                {
                    using (var scope = new TransactionScope(dependentTransaction))
                    {
                        //TODO: (SD) Provide timeout option
                        item = new Tools.Commands.Implementation.IF1.req
                        {
                            reqId = (++IdSequence).ToString(),
                            processingStatus = "P",
                            errorDesc = "ok",
                            returnValue = "ok",
                            updateMechanism = "JMS"
                        }; 
                        
                        scope.Complete();
                    }

                    dependentTransaction.Complete();

                    if (item == null)
                    {
                        // if token is equal to null then commit here, as 
                        // consumer will not get to the item anyway.
                        if (transaction.TransactionInformation.Status == TransactionStatus.Active)
                            transaction.Commit();
                    }
                }

                #endregion

                #region If job is not null create a work item for it

                if (item != null)
                {
                    workItemCandidate = new RequestWorkItem(0, 0, WorkItemState.AvailableForProcessing,
                        SubmissionPriority.Normal, Encoding.UTF8.GetBytes(SerializationUtility.Serialize2String(item)), false, false, this.Name,
                        new ContextIdentifier { InternalId = 0, ExternalReference = IdSequence.ToString(), ExternalId = IdSequence.ToString() })
                        {
                            Transaction = transaction,
                            RetrievedAt = DateTime.Now
                        };

                    //**Trace.CorrelationManager.ActivityId = .ContextUid;
                    Log.Source.TraceEvent(TraceEventType.Start, 0, "Received the item " + item);

                    // Set transaction on the work item
                }

                #endregion

                this.FailureExceptionHandler.ResetState();
            }
            catch (Exception ex)
            {

                try
                {

                    // Rollback the commitable transaction
                    transaction.Rollback(ex);
                }
                finally
                {
                    transaction.Dispose();
                }

                Log.TraceData(Log.Source,
                    TraceEventType.Error,
                    ProducerMessage.ErrorDuringObtainingTheWorkItem,
                    new ContextualLogEntry
                    {
                        Message =
                            "Exception happened when trying to get item " + Environment.NewLine + ex,
                        ContextIdentifier = ((workItemCandidate != null) ? workItemCandidate.ContextIdentifier : new ContextIdentifier())
//.........这里部分代码省略.........
开发者ID:alienwaredream,项目名称:toolsdotnet,代码行数:101,代码来源:ReqProducerStub.cs


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