Inheritance: System.Runtime.InteropServices.SafeHandle
        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;
        }
 internal object Clone()
 {
     IUnknownSafeHandle clonedContext = new IUnknownSafeHandle();
     if (!this.IsInvalid)
     {
         HostExecutionContextManager.CloneHostSecurityContext(this, clonedContext);
     }
     return clonedContext;
 }
        // 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);
        }
 public virtual HostExecutionContext Capture()
 {
     HostExecutionContext context = null;
     if (CheckIfHosted())
     {
         IUnknownSafeHandle state = new IUnknownSafeHandle();
         context = new HostExecutionContext(state);
         CaptureHostSecurityContext(state);
     }
     return context;
 }
        public virtual HostExecutionContext Capture()
        {
            HostExecutionContext result = null;

            if (HostExecutionContextManager.CheckIfHosted())
            {
                IUnknownSafeHandle unknownSafeHandle = new IUnknownSafeHandle();
                result = new HostExecutionContext(unknownSafeHandle);
                HostExecutionContextManager.CaptureHostSecurityContext(unknownSafeHandle);
            }
            return(result);
        }
        public virtual HostExecutionContext Capture()
        {
            HostExecutionContext context = null;

            if (CheckIfHosted())
            {
                IUnknownSafeHandle state = new IUnknownSafeHandle();
                context = new HostExecutionContext(state);
                CaptureHostSecurityContext(state);
            }
            return(context);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
Exemple #9
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public virtual HostExecutionContext Capture()
        {
            HostExecutionContext context = null;

            // check if we are hosted
            if (CheckIfHosted())
            {
                IUnknownSafeHandle unkSafeHandle = new IUnknownSafeHandle();
                context = new HostExecutionContext(unkSafeHandle);

                // call into the Hosting API to capture the host context
                // stores the output IUnknown in the safehandle,
                CaptureHostSecurityContext(unkSafeHandle);
            }

            // otherwise
            return(context);
        }
Exemple #10
0
        public virtual void Revert(Object previousState)
        {
            HostExecutionContextSwitcher hostContextSwitcher = previousState as HostExecutionContextSwitcher;

            if (hostContextSwitcher == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotOverrideSetWithoutRevert"));
            }

            // check Undo is happening on the correct thread
            ExecutionContext executionContext = Thread.CurrentThread.GetMutableExecutionContext();

            if (executionContext != hostContextSwitcher.executionContext)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotUseSwitcherOtherThread"));
            }
            hostContextSwitcher.executionContext = null; // Make sure switcher cannot be re-used.

            HostExecutionContext revertFromHostContext = executionContext.HostExecutionContext;

            // if the current host context is not the same as the one in the switcher, then revert is being called out of order
            if (revertFromHostContext != hostContextSwitcher.currentHostContext)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotUseSwitcherOtherThread"));
            }

            // get the previous host context
            HostExecutionContext revertToHostContext = hostContextSwitcher.previousHostContext;

            // now check if we are hosted and revert the context in the host
            if (CheckIfHosted())
            {
                // try restore the previous context as the current context
                if (revertToHostContext != null && revertToHostContext.State is IUnknownSafeHandle)
                {
                    IUnknownSafeHandle unkprevSafeHandle = (IUnknownSafeHandle)revertToHostContext.State;
                    // call into the Hosting API to set the host context
                    SetHostSecurityContext(unkprevSafeHandle, false, null);
                }
            }

            //restore the previous host context in the executioncontext
            executionContext.HostExecutionContext = revertToHostContext;
        }
Exemple #11
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);
        }
        public virtual object SetHostExecutionContext(HostExecutionContext hostExecutionContext)
        {
            if (hostExecutionContext == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
            }
            HostExecutionContextSwitcher switcher         = new HostExecutionContextSwitcher();
            ExecutionContext             executionContext = Thread.CurrentThread.ExecutionContext;

            switcher.executionContext    = executionContext;
            switcher.currentHostContext  = hostExecutionContext;
            switcher.previousHostContext = null;
            if (CheckIfHosted() && (hostExecutionContext.State is IUnknownSafeHandle))
            {
                IUnknownSafeHandle state = new IUnknownSafeHandle();
                switcher.previousHostContext = new HostExecutionContext(state);
                IUnknownSafeHandle context = (IUnknownSafeHandle)hostExecutionContext.State;
                SetHostSecurityContext(context, true, state);
            }
            executionContext.HostExecutionContext = hostExecutionContext;
            return(switcher);
        }
Exemple #13
0
        [System.Security.SecurityCritical]  // auto-generated_required
        public virtual Object SetHostExecutionContext(HostExecutionContext hostExecutionContext)
        {
            if (hostExecutionContext == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
            }
            Contract.EndContractBlock();

            HostExecutionContextSwitcher switcher = new HostExecutionContextSwitcher();
            ExecutionContext             currentExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();

            switcher.executionContext    = currentExecutionContext;
            switcher.currentHostContext  = hostExecutionContext;
            switcher.previousHostContext = null;

            if (CheckIfHosted())
            {
                if (hostExecutionContext.State is IUnknownSafeHandle)
                {
                    // setup the previous unknown handle
                    IUnknownSafeHandle unkPrevSafeHandle = new IUnknownSafeHandle();
                    switcher.previousHostContext = new HostExecutionContext(unkPrevSafeHandle);

                    // get the current handle
                    IUnknownSafeHandle unkSafeHandle = (IUnknownSafeHandle)hostExecutionContext.State;

                    // call into the Hosting API to set the host context
                    // second arg indicates whether we want to retrieve the previous context
                    SetHostSecurityContext(unkSafeHandle, true, unkPrevSafeHandle);
                }
            }

            // store the current HostExecutionContext in the ExecutionContext.
            currentExecutionContext.HostExecutionContext = hostExecutionContext;

            return(switcher);
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public virtual  HostExecutionContext Capture()
        {
            HostExecutionContext context =  null;
            // check if we are hosted
            if (CheckIfHosted())
            {
                IUnknownSafeHandle unkSafeHandle = new IUnknownSafeHandle();    
                            context = new HostExecutionContext(unkSafeHandle);
                            
                // call into the Hosting API to capture the host context                            
                // stores the output IUnknown in the safehandle,
                CaptureHostSecurityContext(unkSafeHandle);    
            }

            // otherwise
            return context;
            
        }
 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;
 }
 public virtual object SetHostExecutionContext(HostExecutionContext hostExecutionContext)
 {
     if (hostExecutionContext == null)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
     }
     HostExecutionContextSwitcher switcher = new HostExecutionContextSwitcher();
     ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext;
     switcher.executionContext = executionContext;
     switcher.currentHostContext = hostExecutionContext;
     switcher.previousHostContext = null;
     if (CheckIfHosted() && (hostExecutionContext.State is IUnknownSafeHandle))
     {
         IUnknownSafeHandle state = new IUnknownSafeHandle();
         switcher.previousHostContext = new HostExecutionContext(state);
         IUnknownSafeHandle context = (IUnknownSafeHandle) hostExecutionContext.State;
         SetHostSecurityContext(context, true, state);
     }
     executionContext.HostExecutionContext = hostExecutionContext;
     return switcher;
 }
        [System.Security.SecurityCritical]  // auto-generated_required
        public virtual Object SetHostExecutionContext(HostExecutionContext hostExecutionContext)
        {            
            if (hostExecutionContext == null) 
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
            }
            Contract.EndContractBlock();
            
            HostExecutionContextSwitcher switcher = new HostExecutionContextSwitcher();    
            ExecutionContext currentExecutionContext = Thread.CurrentThread.GetMutableExecutionContext();
                     
            switcher.executionContext = currentExecutionContext;    
            switcher.currentHostContext = hostExecutionContext;     
                     switcher.previousHostContext = null;
            
            if (CheckIfHosted())
            {                        
                if (hostExecutionContext.State is IUnknownSafeHandle)
                {    
                                    // setup the previous unknown handle
                                   IUnknownSafeHandle unkPrevSafeHandle = new IUnknownSafeHandle();
                            switcher.previousHostContext = new HostExecutionContext(unkPrevSafeHandle);    

                                    // get the current handle
                    IUnknownSafeHandle unkSafeHandle  = (IUnknownSafeHandle)hostExecutionContext.State;
                    
                                   // call into the Hosting API to set the host context
                                   // second arg indicates whether we want to retrieve the previous context
                      SetHostSecurityContext(unkSafeHandle,true,unkPrevSafeHandle);                                   
                }                                                                                
            }

                    // store the current HostExecutionContext in the ExecutionContext.
            currentExecutionContext.HostExecutionContext = hostExecutionContext;                
            
            return switcher;            
        }