CorrelationManager.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / CompMod / System / Diagnostics / CorrelationManager.cs / 1 / CorrelationManager.cs

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

using System; 
using System.Collections; 
using System.Collections.Specialized;
using System.Threading; 
using System.Runtime.Remoting.Messaging;


namespace System.Diagnostics { 
    public class CorrelationManager {
        private const string transactionSlotName = "System.Diagnostics.Trace.CorrelationManagerSlot"; 
        private const string activityIdSlotName = "E2ETrace.ActivityID"; 

        internal CorrelationManager() { } 

        public Guid ActivityId {
            get {
                Object id = CallContext.LogicalGetData(activityIdSlotName); 
                if (id != null)
                    return (Guid) id; 
                else 
                    return Guid.Empty;
            } 
            set {
                CallContext.LogicalSetData(activityIdSlotName, value);
            }
        } 

        public Stack LogicalOperationStack { 
            get { 
                return GetLogicalOperationStack();
            } 
        }

        public void StartLogicalOperation(object operationId) {
            if (operationId == null) 
                throw new ArgumentNullException("operationId");
 
            Stack idStack = GetLogicalOperationStack(); 
            idStack.Push(operationId);
        } 

        public void StartLogicalOperation() {
            StartLogicalOperation(Guid.NewGuid());
        } 

        public void StopLogicalOperation() { 
            Stack idStack = GetLogicalOperationStack(); 
            idStack.Pop();
        } 

        private Stack GetLogicalOperationStack() {
            Stack idStack = CallContext.LogicalGetData(transactionSlotName) as Stack;
            if (idStack == null) { 
                idStack = new Stack();
                CallContext.LogicalSetData(transactionSlotName, idStack); 
            } 

            return idStack; 
        }

    }
}
                        

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