TracingConnectionListener.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 / ServiceModel / System / ServiceModel / Channels / TracingConnectionListener.cs / 1 / TracingConnectionListener.cs

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

namespace System.ServiceModel.Channels 
{
    using System.ServiceModel.Diagnostics; 
    using System.Threading; 

 
    class TracingConnectionListener : IConnectionListener
    {
        ServiceModelActivity activity;
        IConnectionListener listener; 

        internal TracingConnectionListener(IConnectionListener listener, string traceStartInfo): 
            this(listener, traceStartInfo, true) 
        {
        } 

        internal TracingConnectionListener(IConnectionListener listener, Uri uri)
            : this(listener, uri.ToString())
        { 
        }
 
        internal TracingConnectionListener(IConnectionListener listener) 
        {
            this.listener = listener; 
            this.activity = ServiceModelActivity.CreateActivity(DiagnosticTrace.ActivityId, false);
        }

        internal TracingConnectionListener(IConnectionListener listener, string traceStartInfo, bool newActivity) 
        {
            this.listener = listener; 
            if (newActivity) 
            {
                this.activity = ServiceModelActivity.CreateActivity(); 
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    DiagnosticUtility.DiagnosticTrace.TraceTransfer(this.activity.Id);
                    ServiceModelActivity.Start(this.activity, SR.GetString(SR.ActivityListenAt, traceStartInfo), ActivityType.ListenAt); 
                }
            } 
            else 
            {
                this.activity = ServiceModelActivity.CreateActivity(DiagnosticTrace.ActivityId, false); 
                if (this.activity != null)
                {
                    this.activity.Name = traceStartInfo;
                } 
            }
        } 
 
        public void Listen()
        { 
            using (ServiceModelActivity.BoundOperation(this.activity))
            {
                this.listener.Listen();
            } 
        }
 
        public IAsyncResult BeginAccept(AsyncCallback callback, object state) 
        {
            using (ServiceModelActivity.BoundOperation(this.activity)) 
            {
                return this.listener.BeginAccept(callback, state);
            }
        } 

        public IConnection EndAccept(IAsyncResult result) 
        { 
            using (ServiceModelActivity.BoundOperation(this.activity))
            { 
                ServiceModelActivity activity = ServiceModelActivity.CreateActivity();
                if (activity!= null)
                {
                    DiagnosticUtility.DiagnosticTrace.TraceTransfer(activity.Id); 
                }
                using (ServiceModelActivity.BoundOperation(activity)) 
                { 
                    ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityReceiveBytes, this.activity.Name), ActivityType.ReceiveBytes);
                    IConnection innerConnection = this.listener.EndAccept(result); 
                    if (innerConnection == null)
                    {
                        return null;
                    } 
                    TracingConnection retval = new TracingConnection(innerConnection, activity);
                    return retval; 
                } 
            }
        } 

        public void Dispose()
        {
            using (ServiceModelActivity.BoundOperation(this.activity)) 
            {
                this.listener.Dispose(); 
                this.activity.Dispose(); 
            }
        } 
    }
}

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