protected internal override void CommitWorkBatch(WorkflowCommitWorkBatchService.CommitWorkBatchCallback commitWorkBatchCallback)
 {
     DbRetry retry = new DbRetry(this._enableRetries);
     short retryCount = 0;
 Label_000E:
     if (null != Transaction.Current)
     {
         retryCount = retry.MaxRetries;
     }
     try
     {
         base.CommitWorkBatch(commitWorkBatchCallback);
     }
     catch (Exception exception)
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "DefaultWorkflowCommitWorkBatchService caught exception from commitWorkBatchCallback: " + exception.ToString());
         if (!retry.TryDoRetry(ref retryCount))
         {
             throw;
         }
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "DefaultWorkflowCommitWorkBatchService retrying commitWorkBatchCallback (retry attempt " + retryCount.ToString(CultureInfo.InvariantCulture) + ")");
         goto Label_000E;
     }
 }
        /// <summary>
        /// DB access done without a transaction in a newly opened connection 
        /// </summary>
        /// <param name="dbResourceAllocator">Helper to get database connection/command/store procedure parameters/etc</param>
        internal PersistenceDBAccessor(DbResourceAllocator dbResourceAllocator, bool enableRetries)
        {
            this.dbResourceAllocator = dbResourceAllocator;
            this.dbRetry = new DbRetry(enableRetries);
            DbConnection conn = null;
            short count = 0;
            while (true)
            {
                try
                {
                    WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService OpenConnection start: " + DateTime.UtcNow.ToString("G", System.Globalization.CultureInfo.InvariantCulture));
                    conn = this.dbResourceAllocator.OpenNewConnection();
                    WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService. OpenConnection end: " + DateTime.UtcNow.ToString("G", System.Globalization.CultureInfo.InvariantCulture));

                    if ((null == conn) || (ConnectionState.Open != conn.State))
                        throw new InvalidOperationException(ExecutionStringManager.InvalidConnection);
                    break;
                }
                catch (Exception e)
                {
                    WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService caught exception from OpenConnection: " + e.ToString());

                    if (dbRetry.TryDoRetry(ref count))
                    {
                        WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService retrying.");
                        continue;
                    }
                    throw;
                }
            }
            connection = conn;
            needToCloseConnection = true;
        }
 protected internal override void CommitWorkBatch(WorkflowCommitWorkBatchService.CommitWorkBatchCallback commitWorkBatchCallback)
 {
     ManualResetEvent event2;
     DbRetry retry = new DbRetry(this._enableRetries);
     short maxRetries = retry.MaxRetries;
 Label_0013:
     event2 = new ManualResetEvent(false);
     Transaction transaction = null;
     SharedConnectionInfo connectionInfo = null;
     try
     {
         if (null == Transaction.Current)
         {
             maxRetries = 0;
             transaction = new CommittableTransaction();
             connectionInfo = new SharedConnectionInfo(this.dbResourceAllocator, transaction, false, event2);
         }
         else
         {
             transaction = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
             connectionInfo = new SharedConnectionInfo(this.dbResourceAllocator, transaction, true, event2);
         }
         this.AddToConnectionInfoTable(transaction, connectionInfo);
         using (TransactionScope scope = new TransactionScope(transaction))
         {
             try
             {
                 commitWorkBatchCallback();
                 scope.Complete();
             }
             finally
             {
                 this.RemoveConnectionFromInfoTable(transaction);
                 event2.Set();
             }
         }
         CommittableTransaction transaction2 = transaction as CommittableTransaction;
         if (transaction2 != null)
         {
             transaction2.Commit();
         }
         DependentTransaction transaction3 = transaction as DependentTransaction;
         if (transaction3 != null)
         {
             transaction3.Complete();
         }
     }
     catch (Exception exception)
     {
         transaction.Rollback();
         WorkflowTrace.Host.TraceEvent(TraceEventType.Error, 0, "SharedConnectionWorkflowCommitWorkBatchService caught exception from commitWorkBatchCallback: " + exception.ToString());
         if (!retry.TryDoRetry(ref maxRetries))
         {
             throw;
         }
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SharedConnectionWorkflowCommitWorkBatchService retrying commitWorkBatchCallback (retry attempt " + maxRetries.ToString(CultureInfo.InvariantCulture) + ")");
         goto Label_0013;
     }
     finally
     {
         event2.Close();
         if (transaction != null)
         {
             transaction.Dispose();
         }
     }
 }