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; }
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; }
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); }