예제 #1
0
        public virtual void Revert(object previousState)
        {
            HostExecutionContextSwitcher executionContextSwitcher = previousState as HostExecutionContextSwitcher;

            if (executionContextSwitcher == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotOverrideSetWithoutRevert"));
            }
            ExecutionContext executionContext1 = Thread.CurrentThread.GetMutableExecutionContext();
            ExecutionContext executionContext2 = executionContextSwitcher.executionContext;

            if (executionContext1 != executionContext2)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotUseSwitcherOtherThread"));
            }
            executionContextSwitcher.executionContext = (ExecutionContext)null;
            if (executionContext1.HostExecutionContext != executionContextSwitcher.currentHostContext)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotUseSwitcherOtherThread"));
            }
            HostExecutionContext executionContext3 = executionContextSwitcher.previousHostContext;

            if (HostExecutionContextManager.CheckIfHosted() && executionContext3 != null && executionContext3.State is IUnknownSafeHandle)
            {
                HostExecutionContextManager.SetHostSecurityContext((SafeHandle)executionContext3.State, false, (SafeHandle)null);
            }
            HostExecutionContext executionContext4 = executionContext3;

            executionContext1.HostExecutionContext = executionContext4;
        }
예제 #2
0
        internal static ExecutionContextSwitcher SetExecutionContext(ExecutionContext executionContext)
        {
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;

            BCLDebug.Assert(executionContext != null, "ExecutionContext cannot be null here.");


            // Set up the switcher object to return;
            ExecutionContextSwitcher ecsw = new ExecutionContextSwitcher();

            ecsw.thread = Thread.CurrentThread;
            ecsw.prevEC = Thread.CurrentThread.GetExecutionContextNoCreate(); // prev
            ecsw.currEC = executionContext;                                   //current

            // Update the EC on thread
            Thread.CurrentThread.SetExecutionContext(executionContext);

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if (executionContext != null)
                {
                    //set the security context
                    SecurityContext sc = executionContext.SecurityContext;
                    if (sc != null)
                    {
                        // non-null SC: needs to be set
                        SecurityContext prevSeC = (ecsw.prevEC != null) ? ecsw.prevEC.SecurityContext : null;
                        ecsw.scsw = SecurityContext.SetSecurityContext(sc, prevSeC, ref stackMark);
                    }
                    else if (!SecurityContext.CurrentlyInDefaultFTSecurityContext(ecsw.prevEC))
                    {
                        // null incoming SC, but we're currently not in FT: use static FTSC to set
                        SecurityContext prevSeC = (ecsw.prevEC != null) ? ecsw.prevEC.SecurityContext : null;
                        ecsw.scsw = SecurityContext.SetSecurityContext(SecurityContext.FullTrustSecurityContext, prevSeC, ref stackMark);
                    }

                    // set the sync context
                    SynchronizationContext syncContext = executionContext.SynchronizationContext;
                    if (syncContext != null)
                    {
                        SynchronizationContext prevSyC = (ecsw.prevEC != null) ? ecsw.prevEC.SynchronizationContext : null;
                        ecsw.sysw = SynchronizationContext.SetSynchronizationContext(syncContext, prevSyC);
                    }

                    // set the Host Context
                    HostExecutionContext hostContext = executionContext.HostExecutionContext;
                    if (hostContext != null)
                    {
                        ecsw.hecsw = HostExecutionContextManager.SetHostExecutionContextInternal(hostContext);
                    }
                }
            }
            catch
            {
                ecsw.UndoNoThrow();
                throw;
            }
            return(ecsw);
        }
        public virtual void Revert(object previousState)
        {
            HostExecutionContextSwitcher hostExecutionContextSwitcher = previousState as HostExecutionContextSwitcher;

            if (hostExecutionContextSwitcher == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotOverrideSetWithoutRevert"));
            }
            ExecutionContext mutableExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();

            if (mutableExecutionContext != hostExecutionContextSwitcher.executionContext)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotUseSwitcherOtherThread"));
            }
            hostExecutionContextSwitcher.executionContext = null;
            HostExecutionContext hostExecutionContext = mutableExecutionContext.HostExecutionContext;

            if (hostExecutionContext != hostExecutionContextSwitcher.currentHostContext)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotUseSwitcherOtherThread"));
            }
            HostExecutionContext previousHostContext = hostExecutionContextSwitcher.previousHostContext;

            if (HostExecutionContextManager.CheckIfHosted() && previousHostContext != null && previousHostContext.State is IUnknownSafeHandle)
            {
                IUnknownSafeHandle context = (IUnknownSafeHandle)previousHostContext.State;
                HostExecutionContextManager.SetHostSecurityContext(context, false, null);
            }
            mutableExecutionContext.HostExecutionContext = previousHostContext;
        }
예제 #4
0
        internal static ExecutionContext Capture(ref StackCrawlMark stackMark)
        {
            if (IsFlowSuppressed())
            {
                return(null);
            }
            ExecutionContext executionContextNoCreate = System.Threading.Thread.CurrentThread.GetExecutionContextNoCreate();
            ExecutionContext context2 = new ExecutionContext {
                isNewCapture    = true,
                SecurityContext = System.Security.SecurityContext.Capture(executionContextNoCreate, ref stackMark)
            };

            if (context2.SecurityContext != null)
            {
                context2.SecurityContext.ExecutionContext = context2;
            }
            context2._hostExecutionContext = HostExecutionContextManager.CaptureHostExecutionContext();
            if (executionContextNoCreate != null)
            {
                context2._syncContext = (executionContextNoCreate._syncContext == null) ? null : executionContextNoCreate._syncContext.CreateCopy();
                if (executionContextNoCreate._logicalCallContext != null)
                {
                    System.Runtime.Remoting.Messaging.LogicalCallContext logicalCallContext = executionContextNoCreate.LogicalCallContext;
                    context2.LogicalCallContext = (System.Runtime.Remoting.Messaging.LogicalCallContext)logicalCallContext.Clone();
                }
            }
            return(context2);
        }
 internal static HostExecutionContextManager GetInternalHostExecutionContextManager()
 {
     if (_hostExecutionContextManager == null)
     {
         _hostExecutionContextManager = new HostExecutionContextManager();
     }
     return _hostExecutionContextManager;
 }
 internal static HostExecutionContextManager GetInternalHostExecutionContextManager()
 {
     if (_hostExecutionContextManager == null)
     {
         _hostExecutionContextManager = new HostExecutionContextManager();
     }
     return(_hostExecutionContextManager);
 }
예제 #7
0
 internal static bool CheckIfHosted()
 {
     if (!HostExecutionContextManager._fIsHostedChecked)
     {
         HostExecutionContextManager._fIsHosted        = HostExecutionContextManager.HostSecurityManagerPresent();
         HostExecutionContextManager._fIsHostedChecked = true;
     }
     return(HostExecutionContextManager._fIsHosted);
 }
        // Token: 0x06003B28 RID: 15144 RVA: 0x000DF5EC File Offset: 0x000DD7EC
        internal object Clone()
        {
            IUnknownSafeHandle unknownSafeHandle = new IUnknownSafeHandle();

            if (!this.IsInvalid)
            {
                HostExecutionContextManager.CloneHostSecurityContext(this, unknownSafeHandle);
            }
            return(unknownSafeHandle);
        }
예제 #9
0
 // retun the HostExecutionContextManager for the current AppDomain
 internal static HostExecutionContextManager GetInternalHostExecutionContextManager()
 {
     if (_hostExecutionContextManager == null)
     {
         // setup the HostExecutionContextManager for the current AppDomain
         Contract.Assert(_hostExecutionContextManager == null, "HostExecutionContextManager should be null");
         _hostExecutionContextManager = new HostExecutionContextManager();
     }
     return(_hostExecutionContextManager);
 }
        internal static HostExecutionContext CaptureHostExecutionContext()
        {
            HostExecutionContext        result = null;
            HostExecutionContextManager currentHostExecutionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();

            if (currentHostExecutionContextManager != null)
            {
                result = currentHostExecutionContextManager.Capture();
            }
            return(result);
        }
        internal static HostExecutionContext CaptureHostExecutionContext()
        {
            HostExecutionContext        context = null;
            HostExecutionContextManager currentHostExecutionContextManager = GetCurrentHostExecutionContextManager();

            if (currentHostExecutionContextManager != null)
            {
                context = currentHostExecutionContextManager.Capture();
            }
            return(context);
        }
        internal static object SetHostExecutionContextInternal(HostExecutionContext hostContext)
        {
            HostExecutionContextManager currentHostExecutionContextManager = GetCurrentHostExecutionContextManager();
            object obj2 = null;

            if (currentHostExecutionContextManager != null)
            {
                obj2 = currentHostExecutionContextManager.SetHostExecutionContext(hostContext);
            }
            return(obj2);
        }
        internal static object SetHostExecutionContextInternal(HostExecutionContext hostContext)
        {
            HostExecutionContextManager currentHostExecutionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();
            object result = null;

            if (currentHostExecutionContextManager != null)
            {
                result = currentHostExecutionContextManager.SetHostExecutionContext(hostContext);
            }
            return(result);
        }
예제 #14
0
        internal static Object SetHostExecutionContextInternal(HostExecutionContext hostContext)
        {
            HostExecutionContextManager hostMgr = HostExecutionContextManager.GetCurrentHostExecutionContextManager();
            Object switcher = null;

            if (hostMgr != null)
            {
                switcher = hostMgr.SetHostExecutionContext(hostContext);
            }
            return(switcher);
        }
예제 #15
0
 public static void Undo(object switcherObject)
 {
     if (switcherObject != null)
     {
         HostExecutionContextManager currentHostExecutionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();
         if (currentHostExecutionContextManager != null)
         {
             currentHostExecutionContextManager.Revert(switcherObject);
         }
     }
 }
예제 #16
0
        internal static HostExecutionContext CaptureHostExecutionContext()
        {
            HostExecutionContext        executionContext        = (HostExecutionContext)null;
            HostExecutionContextManager executionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();

            if (executionContextManager != null)
            {
                executionContext = executionContextManager.Capture();
            }
            return(executionContext);
        }
예제 #17
0
        internal static object SetHostExecutionContextInternal(HostExecutionContext hostContext)
        {
            HostExecutionContextManager executionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();
            object obj = (object)null;

            if (executionContextManager != null)
            {
                obj = executionContextManager.SetHostExecutionContext(hostContext);
            }
            return(obj);
        }
        public virtual HostExecutionContext Capture()
        {
            HostExecutionContext result = null;

            if (HostExecutionContextManager.CheckIfHosted())
            {
                IUnknownSafeHandle unknownSafeHandle = new IUnknownSafeHandle();
                result = new HostExecutionContext(unknownSafeHandle);
                HostExecutionContextManager.CaptureHostSecurityContext(unknownSafeHandle);
            }
            return(result);
        }
예제 #19
0
        internal Object Clone()
        {
            IUnknownSafeHandle unkSafeHandleCloned = new IUnknownSafeHandle();

            // call into the Hosting API to CLONE the host context
            // stores the output IUnknown in the safehandle,
            if (!IsInvalid)
            {
                HostExecutionContextManager.CloneHostSecurityContext(this, unkSafeHandleCloned);
            }
            return(unkSafeHandleCloned);
        }
예제 #20
0
        internal static HostExecutionContext CaptureHostExecutionContext()
        {
            HostExecutionContext hostContext = null;
            // capture the host execution context
            HostExecutionContextManager hostMgr = HostExecutionContextManager.GetCurrentHostExecutionContextManager();

            if (hostMgr != null)
            {
                hostContext = hostMgr.Capture();
            }
            return(hostContext);
        }
예제 #21
0
        public virtual HostExecutionContext Capture()
        {
            HostExecutionContext executionContext = (HostExecutionContext)null;

            if (HostExecutionContextManager.CheckIfHosted())
            {
                IUnknownSafeHandle iunknownSafeHandle = new IUnknownSafeHandle();
                executionContext = new HostExecutionContext((object)iunknownSafeHandle);
                HostExecutionContextManager.CaptureHostSecurityContext((SafeHandle)iunknownSafeHandle);
            }
            return(executionContext);
        }
예제 #22
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);
        }
예제 #23
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);
        }
예제 #24
0
        public static void Undo(object switcherObject)
        {
            if (switcherObject == null)
            {
                return;
            }
            HostExecutionContextManager executionContextManager = HostExecutionContextManager.GetCurrentHostExecutionContextManager();

            if (executionContextManager == null)
            {
                return;
            }
            executionContextManager.Revert(switcherObject);
        }
예제 #25
0
        static public void Undo(Object switcherObject)
        {
            if (switcherObject == null)
            {
                return;
            }
            // otherwise call the host
            HostExecutionContextManager hostMgr = HostExecutionContextManager.GetCurrentHostExecutionContextManager();

            if (hostMgr != null)
            {
                hostMgr.Revert(switcherObject);
            }
        }
예제 #26
0
        internal static ExecutionContextSwitcher SetExecutionContext(ExecutionContext executionContext)
        {
            StackCrawlMark           lookForMyCaller = StackCrawlMark.LookForMyCaller;
            ExecutionContextSwitcher switcher        = new ExecutionContextSwitcher {
                thread = System.Threading.Thread.CurrentThread,
                prevEC = System.Threading.Thread.CurrentThread.GetExecutionContextNoCreate(),
                currEC = executionContext
            };

            System.Threading.Thread.CurrentThread.SetExecutionContext(executionContext);
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                if (executionContext == null)
                {
                    return(switcher);
                }
                System.Security.SecurityContext securityContext = executionContext.SecurityContext;
                if (securityContext != null)
                {
                    System.Security.SecurityContext prevSecurityContext = (switcher.prevEC != null) ? switcher.prevEC.SecurityContext : null;
                    switcher.scsw = System.Security.SecurityContext.SetSecurityContext(securityContext, prevSecurityContext, ref lookForMyCaller);
                }
                else if (!System.Security.SecurityContext.CurrentlyInDefaultFTSecurityContext(switcher.prevEC))
                {
                    System.Security.SecurityContext context3 = (switcher.prevEC != null) ? switcher.prevEC.SecurityContext : null;
                    switcher.scsw = System.Security.SecurityContext.SetSecurityContext(System.Security.SecurityContext.FullTrustSecurityContext, context3, ref lookForMyCaller);
                }
                System.Threading.SynchronizationContext synchronizationContext = executionContext.SynchronizationContext;
                if (synchronizationContext != null)
                {
                    System.Threading.SynchronizationContext prevSyncContext = (switcher.prevEC != null) ? switcher.prevEC.SynchronizationContext : null;
                    switcher.sysw = System.Threading.SynchronizationContext.SetSynchronizationContext(synchronizationContext, prevSyncContext);
                }
                System.Threading.HostExecutionContext hostExecutionContext = executionContext.HostExecutionContext;
                if (hostExecutionContext != null)
                {
                    switcher.hecsw = HostExecutionContextManager.SetHostExecutionContextInternal(hostExecutionContext);
                }
            }
            catch
            {
                switcher.UndoNoThrow();
                throw;
            }
            return(switcher);
        }
예제 #27
0
        internal static ExecutionContextSwitcher SetExecutionContext(ExecutionContext executionContext, bool preserveSyncCtx)
        {
            StackCrawlMark           stackMark = StackCrawlMark.LookForMyCaller;
            ExecutionContextSwitcher executionContextSwitcher = new ExecutionContextSwitcher();
            Thread currentThread = Thread.CurrentThread;

            ExecutionContext.Reader executionContextReader = currentThread.GetExecutionContextReader();
            executionContextSwitcher.thread  = currentThread;
            executionContextSwitcher.outerEC = executionContextReader;
            executionContextSwitcher.outerECBelongsToScope = currentThread.ExecutionContextBelongsToCurrentScope;
            if (preserveSyncCtx)
            {
                executionContext.SynchronizationContext = executionContextReader.SynchronizationContext;
            }
            executionContext.SynchronizationContextNoFlow = executionContextReader.SynchronizationContextNoFlow;
            currentThread.SetExecutionContext(executionContext, true);
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                ExecutionContext.OnAsyncLocalContextChanged(executionContextReader.DangerousGetRawExecutionContext(), executionContext);
                SecurityContext securityContext1 = executionContext.SecurityContext;
                if (securityContext1 != null)
                {
                    SecurityContext.Reader securityContext2 = executionContextReader.SecurityContext;
                    executionContextSwitcher.scsw = SecurityContext.SetSecurityContext(securityContext1, securityContext2, false, ref stackMark);
                }
                else if (!SecurityContext.CurrentlyInDefaultFTSecurityContext(executionContextSwitcher.outerEC))
                {
                    SecurityContext.Reader securityContext2 = executionContextReader.SecurityContext;
                    executionContextSwitcher.scsw = SecurityContext.SetSecurityContext(SecurityContext.FullTrustSecurityContext, securityContext2, false, ref stackMark);
                }
                HostExecutionContext executionContext1 = executionContext.HostExecutionContext;
                if (executionContext1 != null)
                {
                    executionContextSwitcher.hecsw = HostExecutionContextManager.SetHostExecutionContextInternal(executionContext1);
                }
            }
            catch
            {
                executionContextSwitcher.UndoNoThrow();
                throw;
            }
            return(executionContextSwitcher);
        }
예제 #28
0
        public virtual object SetHostExecutionContext(HostExecutionContext hostExecutionContext)
        {
            if (hostExecutionContext == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
            }
            HostExecutionContextSwitcher executionContextSwitcher = new HostExecutionContextSwitcher();
            ExecutionContext             executionContext         = Thread.CurrentThread.GetMutableExecutionContext();

            executionContextSwitcher.executionContext    = executionContext;
            executionContextSwitcher.currentHostContext  = hostExecutionContext;
            executionContextSwitcher.previousHostContext = (HostExecutionContext)null;
            if (HostExecutionContextManager.CheckIfHosted() && hostExecutionContext.State is IUnknownSafeHandle)
            {
                IUnknownSafeHandle iunknownSafeHandle = new IUnknownSafeHandle();
                executionContextSwitcher.previousHostContext = new HostExecutionContext((object)iunknownSafeHandle);
                HostExecutionContextManager.SetHostSecurityContext((SafeHandle)hostExecutionContext.State, true, (SafeHandle)iunknownSafeHandle);
            }
            executionContext.HostExecutionContext = hostExecutionContext;
            return((object)executionContextSwitcher);
        }
예제 #29
0
        internal static ExecutionContext Capture(ref StackCrawlMark stackMark, CaptureOptions options)
        {
            if (IsFlowSuppressed())
            {
                return(null);
            }
            bool             flag  = CaptureOptions.None != (options & CaptureOptions.IgnoreSyncCtx);
            bool             flag2 = CaptureOptions.None != (options & CaptureOptions.OptimizeDefaultCase);
            ExecutionContext executionContextNoCreate = System.Threading.Thread.CurrentThread.GetExecutionContextNoCreate();

            System.Security.SecurityContext         context2 = System.Security.SecurityContext.Capture(executionContextNoCreate, ref stackMark);
            System.Threading.HostExecutionContext   context3 = HostExecutionContextManager.CaptureHostExecutionContext();
            System.Threading.SynchronizationContext context4 = null;
            if ((executionContextNoCreate != null) && !flag)
            {
                context4 = (executionContextNoCreate._syncContext == null) ? null : executionContextNoCreate._syncContext.CreateCopy();
            }
            System.Runtime.Remoting.Messaging.LogicalCallContext context5 = null;
            if (((executionContextNoCreate != null) && (executionContextNoCreate._logicalCallContext != null)) && executionContextNoCreate.LogicalCallContext.HasInfo)
            {
                context5 = (System.Runtime.Remoting.Messaging.LogicalCallContext)executionContextNoCreate.LogicalCallContext.Clone();
            }
            if (((flag2 && (context2 == null)) && ((context3 == null) && (context4 == null))) && ((context5 == null) || !context5.HasInfo))
            {
                return(s_dummyDefaultEC);
            }
            ExecutionContext context6 = new ExecutionContext {
                SecurityContext = context2
            };

            if (context6.SecurityContext != null)
            {
                context6.SecurityContext.ExecutionContext = context6;
            }
            context6._hostExecutionContext = context3;
            context6._syncContext          = context4;
            context6.LogicalCallContext    = context5;
            context6.isNewCapture          = true;
            return(context6);
        }
예제 #30
0
        // internal helper to capture the current execution context using a passed in stack mark
        static internal ExecutionContext Capture(ref StackCrawlMark stackMark)
        {
            // check to see if Flow is suppressed
            if (IsFlowSuppressed())
            {
                return(null);
            }

            ExecutionContext ecCurrent = Thread.CurrentThread.GetExecutionContextNoCreate();
            ExecutionContext ecNew     = new ExecutionContext();

            ecNew.isNewCapture = true;

            // capture the security context
            ecNew.SecurityContext = SecurityContext.Capture(ecCurrent, ref stackMark);
            if (ecNew.SecurityContext != null)
            {
                ecNew.SecurityContext.ExecutionContext = ecNew;
            }

            // capture the host execution context
            ecNew._hostExecutionContext = HostExecutionContextManager.CaptureHostExecutionContext();


            if (ecCurrent != null)
            {
                // capture the sync context
                ecNew._syncContext = (ecCurrent._syncContext == null) ? null : ecCurrent._syncContext.CreateCopy();

                // copy over the Logical Call Context
                if (ecCurrent._logicalCallContext != null)
                {
                    LogicalCallContext lc = (LogicalCallContext)ecCurrent.LogicalCallContext;
                    ecNew.LogicalCallContext = (LogicalCallContext)lc.Clone();
                }
            }
            return(ecNew);
        }
		public void Fiddeling_With_HostExecutionContextManager()
		{
			// http://stackoverflow.com/questions/6939037/log4net-logicalthreadcontext-not-working
			// https://issues.apache.org/jira/browse/LOG4NET-317
			// http://logging.markmail.org/thread/q3bogptirf32g77r#query:+page:1+mid:tpgfykgizkpb2mxs+state:results
			// http://blogs.msdn.com/b/ericlippert/archive/2007/12/04/immutability-in-c-part-two-a-simple-immutable-stack.aspx
			var manager = new HostExecutionContextManager();

			_context.Set("Item", "whatever");
			var context = manager.Capture();
		}
예제 #32
0
 override protected bool ReleaseHandle()
 {
     HostExecutionContextManager.ReleaseHostSecurityContext(this.handle);
     return(true);
 }
       // retun the HostExecutionContextManager for the current AppDomain
 internal static HostExecutionContextManager GetInternalHostExecutionContextManager() 
 {
     if (_hostExecutionContextManager == null) {
         // setup the HostExecutionContextManager for the current AppDomain
         Contract.Assert(_hostExecutionContextManager == null, "HostExecutionContextManager should be null");
         _hostExecutionContextManager = new HostExecutionContextManager();
     }
     return _hostExecutionContextManager;
 }