Пример #1
0
 internal static TransactionException Create(string traceSource, string message, Exception innerException)
 {
     if (DiagnosticTrace.Error)
     {
         TransactionExceptionTraceRecord.Trace(traceSource, message);
     }
     return(new TransactionException(message, innerException));
 }
        public static Enlistment Reenlist(Guid resourceManagerIdentifier, byte[] recoveryInformation, IEnlistmentNotification enlistmentNotification)
        {
            if (resourceManagerIdentifier == Guid.Empty)
            {
                throw new ArgumentException(System.Transactions.SR.GetString("BadResourceManagerId"), "resourceManagerIdentifier");
            }
            if (recoveryInformation == null)
            {
                throw new ArgumentNullException("recoveryInformation");
            }
            if (enlistmentNotification == null)
            {
                throw new ArgumentNullException("enlistmentNotification");
            }
            if (!_platformValidated)
            {
                ValidatePlatform();
            }
            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), "TransactionManager.Reenlist");
            }
            if (DiagnosticTrace.Information)
            {
                ReenlistTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), resourceManagerIdentifier);
            }
            MemoryStream input    = new MemoryStream(recoveryInformation);
            string       nodeName = null;

            byte[] buffer = null;
            try
            {
                BinaryReader reader = new BinaryReader(input);
                if (reader.ReadInt32() != 1)
                {
                    if (DiagnosticTrace.Error)
                    {
                        TransactionExceptionTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), System.Transactions.SR.GetString("UnrecognizedRecoveryInformation"));
                    }
                    throw new ArgumentException(System.Transactions.SR.GetString("UnrecognizedRecoveryInformation"), "recoveryInformation");
                }
                nodeName = reader.ReadString();
                buffer   = reader.ReadBytes(recoveryInformation.Length - ((int)input.Position));
            }
            catch (EndOfStreamException exception2)
            {
                if (DiagnosticTrace.Error)
                {
                    TransactionExceptionTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), System.Transactions.SR.GetString("UnrecognizedRecoveryInformation"));
                }
                throw new ArgumentException(System.Transactions.SR.GetString("UnrecognizedRecoveryInformation"), "recoveryInformation", exception2);
            }
            catch (FormatException exception)
            {
                if (DiagnosticTrace.Error)
                {
                    TransactionExceptionTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), System.Transactions.SR.GetString("UnrecognizedRecoveryInformation"));
                }
                throw new ArgumentException(System.Transactions.SR.GetString("UnrecognizedRecoveryInformation"), "recoveryInformation", exception);
            }
            finally
            {
                input.Close();
            }
            OletxTransactionManager manager = CheckTransactionManager(nodeName);
            object     syncRoot             = new object();
            Enlistment enlistment           = new Enlistment(enlistmentNotification, syncRoot);

            EnlistmentState._EnlistmentStatePromoted.EnterState(enlistment.InternalEnlistment);
            enlistment.InternalEnlistment.PromotedEnlistment = manager.ReenlistTransaction(resourceManagerIdentifier, buffer, (RecoveringInternalEnlistment)enlistment.InternalEnlistment);
            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(System.Transactions.SR.GetString("TraceSourceBase"), "TransactionManager.Reenlist");
            }
            return(enlistment);
        }
Пример #3
0
        static public Enlistment Reenlist(
            Guid resourceManagerIdentifier,
            byte[] recoveryInformation,
            IEnlistmentNotification enlistmentNotification
            )
        {
            if (resourceManagerIdentifier == Guid.Empty)
            {
                throw new ArgumentException(SR.GetString(SR.BadResourceManagerId), "resourceManagerIdentifier");
            }

            if (null == recoveryInformation)
            {
                throw new ArgumentNullException("recoveryInformation");
            }

            if (null == enlistmentNotification)
            {
                throw new ArgumentNullException("enlistmentNotification");
            }

            if (!TransactionManager._platformValidated)
            {
                TransactionManager.ValidatePlatform();
            }

            if (DiagnosticTrace.Verbose)
            {
                MethodEnteredTraceRecord.Trace(SR.GetString(SR.TraceSourceBase),
                                               "TransactionManager.Reenlist"
                                               );
            }

            if (DiagnosticTrace.Information)
            {
                ReenlistTraceRecord.Trace(SR.GetString(SR.TraceSourceBase),
                                          resourceManagerIdentifier
                                          );
            }

            // Put the recovery information into a stream.
            MemoryStream stream = new MemoryStream(recoveryInformation);
            int          recoveryInformationVersion = 0;
            string       nodeName = null;

            byte[] resourceManagerRecoveryInformation = null;

            try
            {
                BinaryReader reader = new BinaryReader(stream);
                recoveryInformationVersion = reader.ReadInt32();

                if (recoveryInformationVersion == TransactionManager.recoveryInformationVersion1)
                {
                    nodeName = reader.ReadString();

                    resourceManagerRecoveryInformation = reader.ReadBytes(recoveryInformation.Length - checked ((int)stream.Position));
                }
                else
                {
                    if (DiagnosticTrace.Error)
                    {
                        TransactionExceptionTraceRecord.Trace(SR.GetString(SR.TraceSourceBase),
                                                              SR.GetString(SR.UnrecognizedRecoveryInformation)
                                                              );
                    }
                    throw new ArgumentException(SR.GetString(SR.UnrecognizedRecoveryInformation), "recoveryInformation");
                }
            }
            catch (System.IO.EndOfStreamException e)
            {
                if (DiagnosticTrace.Error)
                {
                    TransactionExceptionTraceRecord.Trace(SR.GetString(SR.TraceSourceBase),
                                                          SR.GetString(SR.UnrecognizedRecoveryInformation)
                                                          );
                }
                throw new ArgumentException(SR.GetString(SR.UnrecognizedRecoveryInformation), "recoveryInformation", e);
            }
            catch (System.FormatException e)
            {
                if (DiagnosticTrace.Error)
                {
                    TransactionExceptionTraceRecord.Trace(SR.GetString(SR.TraceSourceBase),
                                                          SR.GetString(SR.UnrecognizedRecoveryInformation)
                                                          );
                }
                throw new ArgumentException(SR.GetString(SR.UnrecognizedRecoveryInformation), "recoveryInformation", e);
            }
            finally
            {
                stream.Close();
            }

            Oletx.OletxTransactionManager transactionManager = CheckTransactionManager(nodeName);

            // Now ask the Transaction Manager to reenlist.
            object     syncRoot    = new object();
            Enlistment returnValue = new Enlistment(enlistmentNotification, syncRoot);

            EnlistmentState._EnlistmentStatePromoted.EnterState(returnValue.InternalEnlistment);

            returnValue.InternalEnlistment.PromotedEnlistment =
                transactionManager.ReenlistTransaction(
                    resourceManagerIdentifier,
                    resourceManagerRecoveryInformation,
                    (RecoveringInternalEnlistment)returnValue.InternalEnlistment
                    );

            if (DiagnosticTrace.Verbose)
            {
                MethodExitedTraceRecord.Trace(SR.GetString(SR.TraceSourceBase),
                                              "TransactionManager.Reenlist"
                                              );
            }

            return(returnValue);
        }