Exemplo n.º 1
0
        internal static ExecutionContext Capture(ref StackCrawlMark stackMark, ExecutionContext.CaptureOptions options)
        {
            ExecutionContext.Reader executionContextReader = Thread.CurrentThread.GetExecutionContextReader();
            if (executionContextReader.IsFlowSuppressed)
            {
                return((ExecutionContext)null);
            }
            SecurityContext        securityContext        = SecurityContext.Capture(executionContextReader, ref stackMark);
            HostExecutionContext   executionContext1      = HostExecutionContextManager.CaptureHostExecutionContext();
            SynchronizationContext synchronizationContext = (SynchronizationContext)null;
            LogicalCallContext     logicalCallContext     = (LogicalCallContext)null;

            if (!executionContextReader.IsNull)
            {
                if ((options & ExecutionContext.CaptureOptions.IgnoreSyncCtx) == ExecutionContext.CaptureOptions.None)
                {
                    synchronizationContext = executionContextReader.SynchronizationContext == null ? (SynchronizationContext)null : executionContextReader.SynchronizationContext.CreateCopy();
                }
                if (executionContextReader.LogicalCallContext.HasInfo)
                {
                    logicalCallContext = executionContextReader.LogicalCallContext.Clone();
                }
            }
            Dictionary <IAsyncLocal, object> dictionary = (Dictionary <IAsyncLocal, object>)null;
            List <IAsyncLocal> asyncLocalList           = (List <IAsyncLocal>)null;

            if (!executionContextReader.IsNull)
            {
                dictionary     = executionContextReader.DangerousGetRawExecutionContext()._localValues;
                asyncLocalList = executionContextReader.DangerousGetRawExecutionContext()._localChangeNotifications;
            }
            if ((options & ExecutionContext.CaptureOptions.OptimizeDefaultCase) != ExecutionContext.CaptureOptions.None && securityContext == null && (executionContext1 == null && synchronizationContext == null) && ((logicalCallContext == null || !logicalCallContext.HasInfo) && (dictionary == null && asyncLocalList == null)))
            {
                return(ExecutionContext.s_dummyDefaultEC);
            }
            ExecutionContext executionContext2 = new ExecutionContext();

            executionContext2.SecurityContext = securityContext;
            if (executionContext2.SecurityContext != null)
            {
                executionContext2.SecurityContext.ExecutionContext = executionContext2;
            }
            executionContext2._hostExecutionContext     = executionContext1;
            executionContext2._syncContext              = synchronizationContext;
            executionContext2.LogicalCallContext        = logicalCallContext;
            executionContext2._localValues              = dictionary;
            executionContext2._localChangeNotifications = asyncLocalList;
            executionContext2.isNewCapture              = true;
            return(executionContext2);
        }
Exemplo n.º 2
0
        internal static ExecutionContext Capture(ref StackCrawlMark stackMark, ExecutionContext.CaptureOptions options)
        {
            ExecutionContext.Reader executionContextReader = Thread.CurrentThread.GetExecutionContextReader();
            if (executionContextReader.IsFlowSuppressed)
            {
                return(null);
            }
            SecurityContext        securityContext        = SecurityContext.Capture(executionContextReader, ref stackMark);
            HostExecutionContext   hostExecutionContext   = HostExecutionContextManager.CaptureHostExecutionContext();
            SynchronizationContext synchronizationContext = null;
            LogicalCallContext     logicalCallContext     = null;

            if (!executionContextReader.IsNull)
            {
                if ((options & ExecutionContext.CaptureOptions.IgnoreSyncCtx) == ExecutionContext.CaptureOptions.None)
                {
                    synchronizationContext = ((executionContextReader.SynchronizationContext == null) ? null : executionContextReader.SynchronizationContext.CreateCopy());
                }
                if (executionContextReader.LogicalCallContext.HasInfo)
                {
                    logicalCallContext = executionContextReader.LogicalCallContext.Clone();
                }
            }
            IAsyncLocalValueMap asyncLocalValueMap = null;

            IAsyncLocal[] array = null;
            if (!executionContextReader.IsNull)
            {
                asyncLocalValueMap = executionContextReader.DangerousGetRawExecutionContext()._localValues;
                array = executionContextReader.DangerousGetRawExecutionContext()._localChangeNotifications;
            }
            if ((options & ExecutionContext.CaptureOptions.OptimizeDefaultCase) != ExecutionContext.CaptureOptions.None && securityContext == null && hostExecutionContext == null && synchronizationContext == null && (logicalCallContext == null || !logicalCallContext.HasInfo) && asyncLocalValueMap == null && array == null)
            {
                return(ExecutionContext.s_dummyDefaultEC);
            }
            ExecutionContext executionContext = new ExecutionContext();

            executionContext.SecurityContext = securityContext;
            if (executionContext.SecurityContext != null)
            {
                executionContext.SecurityContext.ExecutionContext = executionContext;
            }
            executionContext._hostExecutionContext     = hostExecutionContext;
            executionContext._syncContext              = synchronizationContext;
            executionContext.LogicalCallContext        = logicalCallContext;
            executionContext._localValues              = asyncLocalValueMap;
            executionContext._localChangeNotifications = array;
            executionContext.isNewCapture              = true;
            return(executionContext);
        }