DotNetATv1WindowsLogEntryDeserializer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Recovery / DotNetATv1WindowsLogEntryDeserializer.cs / 1 / DotNetATv1WindowsLogEntryDeserializer.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

// This file contains the knowledge of how to serialize a .NET-AT v1 Windows log entry 

using System; 
using System.ServiceModel; 
using System.Diagnostics;
using System.IO; 
using Microsoft.Transactions.Bridge;
using Microsoft.Transactions.Wsat.Messaging;
using Microsoft.Transactions.Wsat.Protocol;
 
using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility;
 
namespace Microsoft.Transactions.Wsat.Recovery 
{
    class WsATv1LogEntryDeserializer : LogEntryDeserializer 
    {
        //
        ProtocolVersion protocolVersion;
 
        public WsATv1LogEntryDeserializer(MemoryStream mem, LogEntry entry, ProtocolVersion protocolVersion)
            : 
            base(mem, entry) 
        {
            this.protocolVersion = protocolVersion; 
        }

        protected override void DeserializeExtended()
        { 
            DebugTrace.TraceEnter(this, "DeserializeExtended");
 
            // Version 
            WsATv1LogEntryVersion version = (WsATv1LogEntryVersion) SerializationUtils.ReadByte(mem);
            if (!Enum.IsDefined(typeof(WsATv1LogEntryVersion), version)) 
            {
                // The deserializer only supports two versions of log entry. It
                // cannot make sense of other versions and must failfast if logging
                // was done incorrectly. The assumption is that no one else writes to the 
                // log. If someone else DOES write to the log, we can't deal with it and
                // continue on, so failure is the safest  option. 
                DiagnosticUtility.FailFast("Unsupported WsATv1LogEntryVersion"); 
            }
 
            // Flags
            WsATv1LogEntryFlags flags = (WsATv1LogEntryFlags) SerializationUtils.ReadByte(mem);
            if (DebugTrace.Verbose)
            { 
                DebugTrace.Trace(TraceLevel.Verbose, "DeserializeExtended flags: {0}", flags);
            } 
            CheckFlags(flags); 

            // Check for optimized EPR 
            if ((flags & WsATv1LogEntryFlags.OptimizedEndpointRepresentation) == 0)
            {
                this.entry.Endpoint = SerializationUtils.ReadEndpointAddress(this.mem, this.protocolVersion);
 
                if (DebugTrace.Verbose)
                { 
                    DebugTrace.Trace(TraceLevel.Verbose, "Read endpoint address: {0}", this.entry.Endpoint.Uri); 
                }
            } 
            else
            {
                // Remote enlistmentId
                Guid remoteEnlistmentId = SerializationUtils.ReadGuid(this.mem); 
                if (DebugTrace.Verbose)
                { 
                    DebugTrace.Trace(TraceLevel.Verbose, "Read remote EnlistmentId: {0}", remoteEnlistmentId); 
                }
 
                // HostName
                string hostName = SerializationUtils.ReadString(this.mem);
                if (DebugTrace.Verbose)
                { 
                    DebugTrace.Trace(TraceLevel.Verbose, "Read hostName: {0}", hostName);
                } 
 
                // Port
                int port; 
                if ((flags & WsATv1LogEntryFlags.UsesDefaultPort) != 0)
                {
                    port = Configuration.DefaultHttpsPort;
                } 
                else
                { 
                    port = SerializationUtils.ReadInt(mem); 
                    if (DebugTrace.Verbose)
                    { 
                        DebugTrace.Trace(TraceLevel.Verbose, "Read port: {0}", port);
                    }
                }
 
                // Address path
                string addressPath; 
                if ((flags & WsATv1LogEntryFlags.UsesStandardCoordinatorAddressPath) != 0) 
                {
                    addressPath = WsATv1LogEntrySerializer.StandardCoordinatorAddressPath(this.protocolVersion); 
                }
                else if ((flags & WsATv1LogEntryFlags.UsesStandardParticipantAddressPath) != 0)
                {
                    addressPath = WsATv1LogEntrySerializer.StandardParticipantAddressPath(this.protocolVersion); 
                }
                else 
                { 
                    addressPath = SerializationUtils.ReadString(this.mem);
                    if (DebugTrace.Verbose) 
                    {
                        DebugTrace.Trace(TraceLevel.Verbose, "Read address path: {0}", addressPath);
                    }
                } 

                // 
                // Create address from deserialized parts 
                //
 
                UriBuilder uriBuilder = new UriBuilder(Uri.UriSchemeHttps,
                                                       hostName,
                                                       port,
                                                       addressPath); 

                // Create EndpointAddress from deserialized parts 
                EnlistmentHeader refParam = new EnlistmentHeader(remoteEnlistmentId, 
                                                                 ControlProtocol.Durable2PC);
 
                this.entry.Endpoint = new EndpointAddress(uriBuilder.Uri, refParam);
            }

            DebugTrace.TraceLeave(this, "DeserializeExtended"); 
        }
 
        void CheckFlags(WsATv1LogEntryFlags flags) 
        {
            // Detect invalid flags 
            const WsATv1LogEntryFlags allFlags =
                WsATv1LogEntryFlags.OptimizedEndpointRepresentation |
                WsATv1LogEntryFlags.UsesDefaultPort |
                WsATv1LogEntryFlags.UsesStandardCoordinatorAddressPath | 
                WsATv1LogEntryFlags.UsesStandardParticipantAddressPath;
 
            if ((flags | allFlags) != allFlags) 
            {
                // An invalid Enum value on this internal code path indicates 
                // a product bug and violates assumptions about
                // valid values in MSDTC.
                DiagnosticUtility.FailFast("Invalid WsATv1LogEntryFlags");
            } 

            // If OptimizedEndpointRepresentation is not set, no other flag should be set 
            if ((flags & WsATv1LogEntryFlags.OptimizedEndpointRepresentation) == 0 && 
                flags != 0)
            { 
                // The deserializer only supports one version of log entry. It cannot
                // make sense of other versions and must failfast if logging was done
                // incorrectly. The assumption is that noone else writes to the log.
                // If someone else DOES write to the log, we can't deal with it and 
                // continue on, so failure is the safest  option.
                DiagnosticUtility.FailFast("If OptimizedEndpointRepresentation is not set, " + "no other flag should be set"); 
            } 

            // Both address flags cannot be set 
            const WsATv1LogEntryFlags allAddressFlags =
                WsATv1LogEntryFlags.UsesStandardCoordinatorAddressPath |
                WsATv1LogEntryFlags.UsesStandardParticipantAddressPath;
 
            if ((flags & allAddressFlags) == allAddressFlags)
            { 
                // An invalid Enum value on this internal code path indicates 
                // a product bug and violates assumptions about
                // valid values in MSDTC. 
                DiagnosticUtility.FailFast("Both address flags cannot be set at once");
            }
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK