ListenerConfig.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 / SMSvcHost / System / ServiceModel / Activation / ListenerConfig.cs / 1 / ListenerConfig.cs

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

namespace System.ServiceModel.Activation 
{
    using System.Collections.Generic; 
    using System.Security.Principal; 
    using System.Configuration;
    using System.Diagnostics; 
    using System.ServiceModel.Diagnostics;
    using System.ServiceModel.Activation.Configuration;

    static class ListenerConfig 
    {
        static object syncRoot = new object(); 
        static NetTcpSectionData tcpData = null; 
        static NetPipeSectionData pipeData = null;
        static bool diagnosticsSectionInited = false; 
        static bool perfCountersEnabled = false;

        static object SyncRoot
        { 
            get
            { 
                return syncRoot; 
            }
        } 

        static void EnsureInitializedForDiagnostics()
        {
            if (!diagnosticsSectionInited) 
            {
                lock (SyncRoot) 
                { 
                    if (!diagnosticsSectionInited)
                    { 
                        DiagnosticSection diag = DiagnosticSection.GetSection();
                        perfCountersEnabled = diag.PerformanceCountersEnabled;
                        diagnosticsSectionInited = true;
                    } 
                }
            } 
        } 

        public static void EnsureInitializedForNetTcp() 
        {
            EnsureInitializedForDiagnostics();

            if (tcpData == null) 
            {
                lock (SyncRoot) 
                { 
                    if (tcpData == null)
                    { 
                        tcpData = new NetTcpSectionData();
                    }
                }
            } 

            if (DiagnosticUtility.ShouldTraceInformation) 
            { 
                DiagnosticUtility.DiagnosticTrace.TraceEvent(TraceEventType.Information, TraceCode.ReadNetTcpConfig,
                    SR.GetString(SR.TraceCodeReadNetTcpConfig, tcpData.ListenBacklog, tcpData.MaxPendingConnections, 
                    tcpData.MaxPendingAccepts, tcpData.ReceiveTimeout, tcpData.TeredoEnabled));
            }
        }
 
        public static void EnsureInitializedForNetPipe()
        { 
            EnsureInitializedForDiagnostics(); 

            if (pipeData == null) 
            {
                lock (SyncRoot)
                {
                    if (pipeData == null) 
                    {
                        pipeData = new NetPipeSectionData(); 
                    } 
                }
            } 

            if (DiagnosticUtility.ShouldTraceInformation)
            {
                DiagnosticUtility.DiagnosticTrace.TraceEvent(TraceEventType.Information, TraceCode.ReadNetPipeConfig, 
                    SR.GetString(SR.TraceCodeReadNetPipeConfig, pipeData.MaxPendingConnections, pipeData.MaxPendingAccepts, pipeData.ReceiveTimeout));
            } 
        } 

        public static NetTcpSectionData NetTcp 
        {
            get
            {
                EnsureInitializedForNetTcp(); 
                return tcpData;
            } 
        } 

        public static NetPipeSectionData NetPipe 
        {
            get
            {
                EnsureInitializedForNetPipe(); 
                return pipeData;
            } 
        } 

        public static bool PerformanceCountersEnabled 
        {
            get
            {
                EnsureInitializedForDiagnostics(); 
                return perfCountersEnabled;
            } 
        } 

        public static List GetAllowAccounts(TransportType transportType) 
        {
            if (transportType == TransportType.Tcp)
            {
                if (NetTcp.AllowAccounts.Count == 0) 
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( 
                        SR.GetString(SR.ConfigSectionHasZeroAllowAccounts, "NetTcpSection"))); 
                }
 
                return NetTcp.AllowAccounts;
            }
            else if (transportType == TransportType.NamedPipe)
            { 
                if (NetPipe.AllowAccounts.Count == 0)
                { 
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( 
                        SR.GetString(SR.ConfigSectionHasZeroAllowAccounts, "NetPipeSection")));
                } 

                return NetPipe.AllowAccounts;
            }
 
            return null;
        } 
    } 
}

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