Example #1
0
        internal static Guid ExtractActivityId(Message message)
        {
            Guid guid = Guid.Empty;

            try
            {
                if (message != null && message.State != MessageState.Closed && message.Headers != null)
                {
                    int index = message.Headers.FindHeader(DiagnosticStrings.ActivityId, DiagnosticStrings.DiagnosticsNamespace);

                    // Check the state again, in case the message was closed after we found the header
                    if (index >= 0)
                    {
                        using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index))
                        {
                            guid = reader.ReadElementContentAsGuid();
                        }
                    }
                }
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
            }

            return(guid);
        }
        internal static Guid ExtractActivityId(Message message)
        {
            Guid empty = Guid.Empty;

            try
            {
                if (((message == null) || (message.State == MessageState.Closed)) || (message.Headers == null))
                {
                    return(empty);
                }
                int headerIndex = message.Headers.FindHeader("ActivityId", "http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics");
                if (headerIndex < 0)
                {
                    return(empty);
                }
                using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(headerIndex))
                {
                    empty = reader.ReadElementContentAsGuid();
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (DiagnosticUtility.ShouldTraceError)
                {
                    TraceUtility.TraceEvent(TraceEventType.Error, 0x20007, System.ServiceModel.SR.GetString("TraceCodeFailedToReadAnActivityIdHeader"), null, exception);
                }
            }
            return(empty);
        }
Example #3
0
 private void ReadFrom(XmlDictionaryReader reader)
 {
     try
     {
         reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.Register, this.coordinationXmlDictionaryStrings.Namespace);
         reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.Protocol, this.coordinationXmlDictionaryStrings.Namespace);
         this.Protocol = WSAtomicTransactionStrings.WellKnownNameToProtocol(reader.ReadElementContentAsString().Trim(), this.protocolVersion);
         if (this.Protocol == ControlProtocol.None)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody")));
         }
         this.ParticipantProtocolService = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(this.protocolVersion), reader, this.coordinationXmlDictionaryStrings.ParticipantProtocolService, this.coordinationXmlDictionaryStrings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Loopback, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             this.Loopback = reader.ReadElementContentAsGuid();
         }
         while (reader.IsStartElement())
         {
             reader.Skip();
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception));
     }
 }
Example #4
0
        private static WsatRegistrationHeader ReadFrom(XmlDictionaryReader reader)
        {
            string str;
            string str2;

            reader.ReadFullStartElement(XD.DotNetAtomicTransactionExternalDictionary.RegisterInfo, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
            reader.MoveToStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
            Guid transactionId = reader.ReadElementContentAsGuid();

            if (transactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderTransactionId")));
            }
            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.ContextId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                Uri uri;
                str = reader.ReadElementContentAsString().Trim();
                if (((str.Length == 0) || (str.Length > 0x100)) || !Uri.TryCreate(str, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderIdentifier")));
                }
            }
            else
            {
                str = null;
            }
            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.TokenId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                str2 = reader.ReadElementContentAsString().Trim();
                if (str2.Length == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidRegistrationHeaderTokenId")));
                }
            }
            else
            {
                str2 = null;
            }
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();
            return(new WsatRegistrationHeader(transactionId, str, str2));
        }
Example #5
0
        internal static bool ExtractActivityAndCorrelationId(Message message, out Guid activityId, out Guid correlationId)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
            }
            activityId    = Guid.Empty;
            correlationId = Guid.Empty;

            try
            {
                if (message.State != MessageState.Closed && message.Headers != null)
                {
                    int index = message.Headers.FindHeader(DiagnosticStrings.ActivityId, DiagnosticStrings.DiagnosticsNamespace);

                    // Check the state again, in case the message was closed after we found the header
                    if (index >= 0)
                    {
                        using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index))
                        {
                            correlationId = Fx.CreateGuid(reader.GetAttribute("CorrelationId", null));
                            activityId    = reader.ReadElementContentAsGuid();
                            return(activityId != Guid.Empty);
                        }
                    }
                }
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (DiagnosticUtility.ShouldTraceError)
                {
                    TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.FailedToReadAnActivityIdHeader,
                                            SR.GetString(SR.TraceCodeFailedToReadAnActivityIdHeader), null, e);
                }
            }
            return(false);
        }
 public static void ReadFrom(XmlDictionaryReader reader, out Guid enlistment, out ControlProtocol protocol)
 {
     try
     {
         if (reader.IsEmptyElement || !reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Enlistment, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnlistmentHeaderException(Microsoft.Transactions.SR.GetString("InvalidEnlistmentHeader")));
         }
         string attribute = reader.GetAttribute(XD.DotNetAtomicTransactionExternalDictionary.Protocol, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
         if (attribute == null)
         {
             protocol = ControlProtocol.None;
         }
         else
         {
             protocol = (ControlProtocol)XmlConvert.ToInt32(attribute.Trim());
             if ((protocol != ControlProtocol.Durable2PC) && (protocol != ControlProtocol.Volatile2PC))
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnlistmentHeaderException(Microsoft.Transactions.SR.GetString("InvalidEnlistmentHeader")));
             }
         }
         enlistment = reader.ReadElementContentAsGuid();
     }
     catch (FormatException exception)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnlistmentHeaderException(Microsoft.Transactions.SR.GetString("InvalidEnlistmentHeader"), exception));
     }
     catch (OverflowException exception2)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Warning);
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnlistmentHeaderException(Microsoft.Transactions.SR.GetString("InvalidEnlistmentHeader"), exception2));
     }
     catch (XmlException exception3)
     {
         Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Warning);
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnlistmentHeaderException(Microsoft.Transactions.SR.GetString("InvalidEnlistmentHeader"), exception3));
     }
 }
 internal static bool ExtractActivityAndCorrelationId(Message message, out Guid activityId, out Guid correlationId)
 {
     if (message == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
     }
     activityId    = Guid.Empty;
     correlationId = Guid.Empty;
     try
     {
         if ((message.State != MessageState.Closed) && (message.Headers != null))
         {
             int headerIndex = message.Headers.FindHeader("ActivityId", "http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics");
             if (headerIndex >= 0)
             {
                 using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(headerIndex))
                 {
                     correlationId = Fx.CreateGuid(reader.GetAttribute("CorrelationId", null));
                     activityId    = reader.ReadElementContentAsGuid();
                     return(activityId != Guid.Empty);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         if (DiagnosticUtility.ShouldTraceError)
         {
             TraceUtility.TraceEvent(TraceEventType.Error, 0x20007, System.ServiceModel.SR.GetString("TraceCodeFailedToReadAnActivityIdHeader"), null, exception);
         }
     }
     return(false);
 }
        internal static bool ExtractActivityAndCorrelationId(Message message, out Guid activityId, out Guid correlationId)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
            }
            activityId    = Guid.Empty;
            correlationId = Guid.Empty;

            try
            {
                if (message.State != MessageState.Closed && message.Headers != null)
                {
                    int index = message.Headers.FindHeader(DiagnosticStrings.ActivityId, DiagnosticStrings.DiagnosticsNamespace);

                    // Check the state again, in case the message was closed after we found the header
                    if (index >= 0)
                    {
                        using (XmlDictionaryReader reader = message.Headers.GetReaderAtHeader(index))
                        {
                            correlationId = Fx.CreateGuid(reader.GetAttribute("CorrelationId", null));
                            activityId    = reader.ReadElementContentAsGuid();
                            return(activityId != Guid.Empty);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
            }
            return(false);
        }
 private static void ReadFrom(CoordinationContext that, XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion)
 {
     try
     {
         Uri uri;
         CoordinationXmlDictionaryStrings strings  = CoordinationXmlDictionaryStrings.Version(protocolVersion);
         AtomicTransactionStrings         strings2 = AtomicTransactionStrings.Version(protocolVersion);
         reader.ReadFullStartElement(localName, strings.Namespace);
         reader.MoveToStartElement(strings.Identifier, strings.Namespace);
         that.unknownIdentifierAttributes = ReadOtherAttributes(reader, strings.Namespace);
         that.contextId = reader.ReadElementContentAsString().Trim();
         if ((that.contextId.Length == 0) || (that.contextId.Length > 0x100))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (!Uri.TryCreate(that.contextId, UriKind.Absolute, out uri))
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         if (reader.IsStartElement(strings.Expires, strings.Namespace))
         {
             that.unknownExpiresAttributes = ReadOtherAttributes(reader, strings.Namespace);
             int num = reader.ReadElementContentAsInt();
             if (num < 0)
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
             that.expiration     = (uint)num;
             that.expiresPresent = true;
         }
         reader.MoveToStartElement(strings.CoordinationType, strings.Namespace);
         if (reader.ReadElementContentAsString().Trim() != strings2.Namespace)
         {
             throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
         }
         that.registrationRef = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(protocolVersion), reader, strings.RegistrationService, strings.Namespace);
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoLevel = (System.Transactions.IsolationLevel)reader.ReadElementContentAsInt();
             if (((that.IsolationLevel < System.Transactions.IsolationLevel.Serializable) || (that.IsolationLevel > System.Transactions.IsolationLevel.Unspecified)) || (that.IsolationLevel == System.Transactions.IsolationLevel.Snapshot))
             {
                 throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext")));
             }
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationFlags, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.isoFlags = (System.ServiceModel.Transactions.IsolationFlags)reader.ReadElementContentAsInt();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Description, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.description = reader.ReadElementContentAsString().Trim();
         }
         if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace))
         {
             that.localTxId = reader.ReadElementContentAsGuid();
         }
         if (OleTxTransactionHeader.IsStartPropagationTokenElement(reader))
         {
             that.propToken = OleTxTransactionHeader.ReadPropagationTokenElement(reader);
         }
         if (reader.IsStartElement())
         {
             XmlDocument document = new XmlDocument();
             that.unknownData = new List <System.Xml.XmlNode>(5);
             while (reader.IsStartElement())
             {
                 System.Xml.XmlNode item = document.ReadNode(reader);
                 that.unknownData.Add(item);
             }
         }
         reader.ReadEndElement();
     }
     catch (XmlException exception)
     {
         throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"), exception));
     }
 }
Example #10
0
        static WsatRegistrationHeader ReadFrom(XmlDictionaryReader reader)
        {
            reader.ReadFullStartElement(XD.DotNetAtomicTransactionExternalDictionary.RegisterInfo,
                                        XD.DotNetAtomicTransactionExternalDictionary.Namespace);

            reader.MoveToStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId,
                                      XD.DotNetAtomicTransactionExternalDictionary.Namespace);

            // TransactionId
            Guid transactionId = reader.ReadElementContentAsGuid();

            if (transactionId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new XmlException(SR.GetString(SR.InvalidRegistrationHeaderTransactionId)));
            }

            // ContextId
            string contextId;

            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.ContextId,
                                      XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                Uri uri;
                contextId = reader.ReadElementContentAsString().Trim();
                if (contextId.Length == 0 ||
                    contextId.Length > CoordinationContext.MaxIdentifierLength ||
                    !Uri.TryCreate(contextId, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new XmlException(SR.GetString(SR.InvalidRegistrationHeaderIdentifier)));
                }
            }
            else
            {
                contextId = null;
            }

            // TokenId
            string tokenId;

            if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.TokenId,
                                      XD.DotNetAtomicTransactionExternalDictionary.Namespace))
            {
                tokenId = reader.ReadElementContentAsString().Trim();
                if (tokenId.Length == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                              new XmlException(SR.GetString(SR.InvalidRegistrationHeaderTokenId)));
                }
            }
            else
            {
                tokenId = null;
            }

            // Skip unknown elements
            while (reader.IsStartElement())
            {
                reader.Skip();
            }
            reader.ReadEndElement();

            return(new WsatRegistrationHeader(transactionId, contextId, tokenId));
        }