ProtocolInformationWriter.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 / Protocol / ProtocolInformationWriter.cs / 1 / ProtocolInformationWriter.cs

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

// Define the class that knows how to serialize WS-AT protocol information 

using System; 
using System.IO; 

using Microsoft.Transactions.Wsat.Recovery; 

namespace Microsoft.Transactions.Wsat.Protocol
{
    enum ProtocolInformationMajorVersion : byte 
    {
        v1 = 0x1 
    } 

    enum ProtocolInformationMinorVersion : byte 
    {
        v1 = 0x1,
        v2 = 0x2,
    } 

    enum ProtocolInformationFlags : byte 
    { 
        IssuedTokensEnabled   = 0x01,
        NetworkClientAccess   = 0x02, 
        NetworkInboundAccess  = 0x04,
        NetworkOutboundAccess = 0x08,
        IsClustered           = 0x10
    } 

    class ProtocolInformationWriter 
    { 
        ProtocolState state;
 
        public ProtocolInformationWriter(ProtocolState state)
        {
            this.state = state;
        } 

        public byte[] GetProtocolInformation() 
        { 
            MemoryStream mem = new MemoryStream();
            WriteProtocolInformation(mem); 

            return mem.ToArray();
        }
 
        void WriteProtocolInformation(MemoryStream mem)
        { 
            ProtocolInformationFlags flags = GetProtocolInformationFlags(); 

            // Version 
            mem.WriteByte((byte)ProtocolInformationMajorVersion.v1);
            mem.WriteByte((byte)ProtocolInformationMinorVersion.v2);

            // Flags 
            mem.WriteByte((byte)flags);
 
            // Https port 
            SerializationUtils.WriteInt(mem, state.Config.PortConfiguration.HttpsPort);
 
            // Max timeout
            SerializationUtils.WriteTimeout(mem, state.Config.MaxTimeout);

            // Hostname used in addresses 
            SerializationUtils.WriteString(mem, state.Config.PortConfiguration.HostName);
 
            // Base path used in addresses 
            SerializationUtils.WriteString(mem, state.Config.PortConfiguration.BasePath);
 
            // Local node name
            SerializationUtils.WriteString(mem, Environment.MachineName);

            // End of version 1.1 

            // version 1.2 data 
 
            // Supported protocols
            SerializationUtils.WriteUShort(mem, (ushort)(ProtocolVersion.Version10 | ProtocolVersion.Version11)); 

            // End of version 1.2 data

        } 

        ProtocolInformationFlags GetProtocolInformationFlags() 
        { 
            ProtocolInformationFlags flags = 0;
 
            // IssuedTokensEnabled
            if (state.Config.PortConfiguration.SupportingTokensEnabled)
            {
                flags |= ProtocolInformationFlags.IssuedTokensEnabled; 
            }
 
            // NetworkInboundAccess 
            if (state.TransactionManager.Settings.NetworkInboundAccess)
            { 
                flags |= ProtocolInformationFlags.NetworkInboundAccess;
            }

            // NetworkOutboundAccess 
            if (state.TransactionManager.Settings.NetworkOutboundAccess)
            { 
                flags |= ProtocolInformationFlags.NetworkOutboundAccess; 
            }
 
            // NetworkClientsAccess
            if (state.TransactionManager.Settings.NetworkClientAccess)
            {
                flags |= ProtocolInformationFlags.NetworkClientAccess; 
            }
 
            // IsClustered 
            if (state.TransactionManager.Settings.IsClustered)
            { 
                flags |= ProtocolInformationFlags.IsClustered;
            }

            return flags; 
        }
    } 
} 

// 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