Prepared() публичный Метод

public Prepared ( ) : void
Результат void
        public virtual void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Trace.WriteIf(Tracing.Is.TraceVerbose, string.Empty);
            if (null == preparingEnlistment)
            {
                return;
            }

            try
            {
                Operation.Info = Convert.ToBase64String(preparingEnlistment.RecoveryInformation());
                if (ConfigureOperation() &&
                    Operation.Do())
                {
                    Trace.WriteIf(Tracing.Is.TraceVerbose, "preparingEnlistment.Prepared()");
                    preparingEnlistment.Prepared();
                    return;
                }

                Trace.WriteIf(Tracing.Is.TraceVerbose, "preparingEnlistment.ForceRollback()");
                preparingEnlistment.ForceRollback();
            }
            catch (Exception exception)
            {
                Trace.TraceError("{0}", exception);
                preparingEnlistment.ForceRollback(exception);
            }
        }
Пример #2
0
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			try
			{

				onTxComplete();
				ctx.CreateFile(TransactionRecoveryInformationFileName, stream =>
				{
					var writer = new BinaryWriter(stream);
					writer.Write(session.ResourceManagerId.ToString());
					writer.Write(transaction.LocalIdentifier);
					writer.Write(session.DatabaseName ?? "");
					writer.Write(preparingEnlistment.RecoveryInformation());
				});

				session.PrepareTransaction(transaction.LocalIdentifier); 
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not prepare distributed transaction", e);
			    try
			    {
                    session.Rollback(transaction.LocalIdentifier);
                    DeleteFile();
			    }
			    catch (Exception e2)
			    {
			        logger.ErrorException("Could not roll back transaction after prepare failed", e2);
			    }

				preparingEnlistment.ForceRollback(e);
				return;
			}
			preparingEnlistment.Prepared();
		}
 void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
 {
     bool success = false;
     try
     {
         IAsyncResult result = new PrepareAsyncResult(this, TransactionContext.handleEndPrepare, preparingEnlistment);
         if (result.CompletedSynchronously)
         {
             PrepareAsyncResult.End(result);
             preparingEnlistment.Prepared();
         }
         success = true;
     }
     //we need to swollow the TransactionException as it could because another party aborting it
     catch (TransactionException) 
     {
     }
     finally
     {
         if (!success)
         {
             preparingEnlistment.ForceRollback();
         }
     }
 }
Пример #4
0
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			onTxComplete();
			session.StoreRecoveryInformation(session.ResourceManagerId, PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction), 
				preparingEnlistment.RecoveryInformation());
			preparingEnlistment.Prepared();
		}
Пример #5
0
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			onTxComplete();
			try
			{
				using (var machineStoreForApplication = IsolatedStorageFile.GetMachineStoreForDomain())
				{
					var name = TransactionRecoveryInformationFileName;
					using (var file = machineStoreForApplication.CreateFile(name + ".temp"))
					using(var writer = new BinaryWriter(file))
					{
						writer.Write(session.ResourceManagerId.ToString());
						writer.Write(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction).ToString());
						writer.Write(session.DatabaseName ?? "");
						writer.Write(preparingEnlistment.RecoveryInformation());
						file.Flush(true);
					}
					machineStoreForApplication.MoveFile(name + ".temp", name);
			}
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not prepare distributed transaction", e);
				preparingEnlistment.ForceRollback(e);
				return;
			}
			preparingEnlistment.Prepared();
		}
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
   if (_transaction.IsValid(false) == false)
     preparingEnlistment.ForceRollback();
   else
     preparingEnlistment.Prepared();
 }
Пример #7
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     DeveelDbException error;
     if (!transaction.IsOpen(out error)) {
         preparingEnlistment.ForceRollback(error);
     } else {
         preparingEnlistment.Prepared();
     }
 }
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				byte[] recoveryInformation = preparingEnlistment.RecoveryInformation();
				var ravenJObject = new RavenJObject
				{
					{Constants.NotForReplication, true}
				};
				database.PutStatic("transactions/recoveryInformation/" + txId, null, new MemoryStream(recoveryInformation), ravenJObject);
				preparingEnlistment.Prepared();
			}
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     _assertNotDisposed();
     _logger.Debug("Preparing enlistment with id: {0}", Id);
     var information = preparingEnlistment.RecoveryInformation();
     _queueStorage.Global(actions =>
     {
         actions.RegisterRecoveryInformation(Id, information);
     });
     preparingEnlistment.Prepared();
     _logger.Debug("Prepared enlistment with id: {0}", Id);
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     try
     {
         transaction.Commit();
         preparingEnlistment.Prepared();
     }
     catch (Exception ex)
     {
         preparingEnlistment.ForceRollback(ex);
     }
 }
Пример #11
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     try
       {
     _transaction.IsValid();
       }
       catch(Exception e)
       {
     preparingEnlistment.ForceRollback(e);
     return;
       }
       preparingEnlistment.Prepared();
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     if (commit)
     {
         preparingEnlistment.Prepared();
     }
     else
     {
         preparingEnlistment.ForceRollback();
         // Rollback is not called after 'Rollback' vote
         this.WasRollback = true;
         preparingEnlistment.Done();
     }
 }
        /// <summary>
        /// Notifies an enlisted object that a transaction is being prepared for commitment.
        /// </summary>
        /// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
        public void Prepare( PreparingEnlistment preparingEnlistment )
        {
            Status = TxfmStatus.InPrepare;

            // TODO: Write to recovery log.

            foreach( var operation in operations )
            {
                operation.Commit();
            }

            preparingEnlistment.Prepared();

            Status = TxfmStatus.InTransaction;
        }
Пример #14
0
		/// <summary>
		/// Notifies an enlisted object that a transaction is being prepared for commitment.
		/// </summary>
		/// <param name="preparingEnlistment">A <see cref="T:System.Transactions.PreparingEnlistment"/> object used to send a response to the transaction manager.</param>
		public void Prepare(PreparingEnlistment preparingEnlistment)
		{
			onTxComplete();
			try
			{
				session.StoreRecoveryInformation(session.ResourceManagerId, PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction), 
				                                 preparingEnlistment.RecoveryInformation());
			}
			catch (Exception e)
			{
				logger.ErrorException("Could not prepare distributed transaction", e);
				preparingEnlistment.ForceRollback(e);
				return;
			}
			preparingEnlistment.Prepared();
		}
Пример #15
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            try
            {
                using (var ts = new TransactionScope(_transaction))
                {
                    _unitOfWork.Commit();

                    ts.Complete();
                }

                preparingEnlistment.Prepared();
            }
            catch (Exception ex)
            {
                preparingEnlistment.ForceRollback(ex);
            }
        }
 void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
 {
     bool flag = false;
     try
     {
         IAsyncResult result = new PrepareAsyncResult(this, handleEndPrepare, preparingEnlistment);
         if (result.CompletedSynchronously)
         {
             PrepareAsyncResult.End(result);
             preparingEnlistment.Prepared();
         }
         flag = true;
     }
     catch (TransactionException)
     {
     }
     finally
     {
         if (!flag)
         {
             preparingEnlistment.ForceRollback();
         }
     }
 }
Пример #17
0
        // This *doesn't* get called when we get enlisted in a Tx, it gets
        // called when we're about to commit a transaction. We can *probably*
        // get away with calling .Done() here and skipping the commit phase,
        // but I'm not sure if we'd get InDoubt signalling if we did that.
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            log.Debug("Registry prepared to commit transaction");

            preparingEnlistment.Prepared();
        }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     PrepareCalled = true;
     preparingEnlistment.Prepared();
 }
Пример #19
0
 void OnPrepare(PreparingEnlistment preparingEnlistment)
 {
     bool prepareNeeded = false;
     lock (ThisLock)
     {
         if (TooLateToEnlist)
         {
             // Skip this if somehow we already got rolled back or committed.
             return;
         }
         TooLateToEnlist = true;
         if (OperationPending && AcquirePending == null)
         {
             Fx.Assert(CurrentExecutionContext != null, "Should either be acquiring or executing in Prepare.");
             this.pendingPreparingEnlistment = preparingEnlistment;
         }
         else
         {
             prepareNeeded = true;
         }
     }
     if (prepareNeeded)
     {
         preparingEnlistment.Prepared();
     }
 }
Пример #20
0
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				Assert.AreNotEqual(thread, Thread.CurrentThread.ManagedThreadId);
				if (shouldRollBack)
				{
					log.Debug(">>>>Force Rollback<<<<<");
					preparingEnlistment.ForceRollback();
				}
				else
				{
					preparingEnlistment.Prepared();
				}
			}
 private void OnPrepare(PreparingEnlistment preparingEnlistment)
 {
     bool flag = false;
     lock (this.ThisLock)
     {
         if (this.TooLateToEnlist)
         {
             return;
         }
         this.TooLateToEnlist = true;
         if (this.OperationPending && (this.AcquirePending == null))
         {
             this.pendingPreparingEnlistment = preparingEnlistment;
         }
         else
         {
             flag = true;
         }
     }
     if (flag)
     {
         preparingEnlistment.Prepared();
     }
 }
Пример #22
0
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				database.PutStatic("transactions/recoveryInformation/" + txId, null, preparingEnlistment.RecoveryInformation(), new JObject());
				preparingEnlistment.Prepared();
			}
Пример #23
0
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				// shouldn't be called, already 
				// prepared, otherwise we won't have this issue
				preparingEnlistment.Prepared();
			}
Пример #24
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     preparingEnlistment.Prepared(); // should not really be called, and we did the work already anyway
 }
 private void FinishOperation()
 {
     List<InstanceHandleReference> handlesPendingResolution = null;
     try
     {
         bool needFreedNotification;
         PreparingEnlistment pendingPreparingEnlistment;
         AcquireContextAsyncResult pendingRollback;
         lock (this.ThisLock)
         {
             this.OperationPending = false;
             this.AcquirePending = null;
             this.CurrentExecutionContext = null;
             if ((this.inProgressBind != null) && ((this.Version == -1L) || !this.IsValid))
             {
                 this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
             }
             else if ((this.Version != -1L) && !this.IsValid)
             {
                 this.Owner.Unbind(this);
             }
             needFreedNotification = this.needFreedNotification;
             this.needFreedNotification = false;
             pendingPreparingEnlistment = this.pendingPreparingEnlistment;
             this.pendingPreparingEnlistment = null;
             pendingRollback = this.pendingRollback;
             this.pendingRollback = null;
         }
         try
         {
             if (needFreedNotification)
             {
                 this.Store.FreeInstanceHandle(this, this.ProviderObject);
             }
         }
         finally
         {
             if (pendingRollback != null)
             {
                 pendingRollback.RollBack();
             }
             else if (pendingPreparingEnlistment != null)
             {
                 pendingPreparingEnlistment.Prepared();
             }
         }
     }
     finally
     {
         InstanceOwner.ResolveHandles(handlesPendingResolution);
     }
 }
Пример #26
0
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     Log.Info("DurableRM.Prepare");
     _dbLock.Acquire(GlobalMutexScope.MutexTimeout, GlobalMutexScope.AcquireMutexTimeout, null);
     preparingEnlistment.Prepared();
 }
 public void Prepare(PreparingEnlistment preparingEnlistment)
 {
     TestLog.WriteLine("{0}: Prepare", phase);
     preparingEnlistment.Prepared();
 }
Пример #28
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Log.Info("Prepare notification received");

            //Perform transactional work
            using (var db = Dao.Default.Create())
            {
                using (var dbTransaction = db.Connection.BeginTransaction())
                {
                    using (var cmd = db.Connection.CreateCommand())
                    {
                        try
                        {
                            DbUtil.Execute(
                                "INSERT INTO GlobalSetting (SettingGroup, SettingKey, LastModified, SettingValue, System) VALUES ({0}, {1}, {2}, {3}, {4})",
                                db, cmd,
                                new[] { DbType.String, DbType.String, DbType.DateTime, DbType.String, DbType.Boolean },
                                new object[] { GlobalMutexScope.Group, _key, DateTime.UtcNow, "", true });
                            dbTransaction.Commit();
                            Log.InfoFormat("Trans: Status={0}, LocalId={1}, DistributedId={2}.",
                                           Transaction.Current.TransactionInformation.Status,
                                           Transaction.Current.TransactionInformation.LocalIdentifier,
                                           Transaction.Current.TransactionInformation.DistributedIdentifier);
                            //If work finished correctly, reply prepared
                            preparingEnlistment.Prepared();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.Message);
                            // otherwise, do a ForceRollback
                            preparingEnlistment.ForceRollback();
                            throw;
                        }
                    }
                }
            }
        }
Пример #29
0
			public void Prepare(PreparingEnlistment preparingEnlistment)
			{
				preparingEnlistment.Prepared();
			}
Пример #30
0
        public void Prepare(PreparingEnlistment preparingEnlistment)
        {
            Log.Info("Prepare notification received");

            //Perform transactional work
            try
            {

                Log.InfoFormat("Trans: Status={0}, LocalId={1}, DistributedId={2}.",
                                Transaction.Current.TransactionInformation.Status,
                                Transaction.Current.TransactionInformation.LocalIdentifier,
                                Transaction.Current.TransactionInformation.DistributedIdentifier);
                //If work finished correctly, reply prepared
                preparingEnlistment.Prepared();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                // otherwise, do a ForceRollback
                preparingEnlistment.ForceRollback();
                throw;
            }
        }