Ejemplo n.º 1
0
        public ExecutionContext CreateCopy()
        {
            if (!isNewCapture)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotCopyUsedContext"));
            }
            ExecutionContext ec = new ExecutionContext();

            ec.isNewCapture = true;
            ec._syncContext = _syncContext == null ? null : _syncContext.CreateCopy();
            // capture the host execution context
            ec._hostExecutionContext = _hostExecutionContext == null ? null : _hostExecutionContext.CreateCopy();
            if (_securityContext != null)
            {
                ec._securityContext = _securityContext.CreateCopy();
                ec._securityContext.ExecutionContext = ec;
            }
            if (this._logicalCallContext != null)
            {
                LogicalCallContext lc = (LogicalCallContext)this.LogicalCallContext;
                ec.LogicalCallContext = (LogicalCallContext)lc.Clone();
            }
            if (this._illogicalCallContext != null)
            {
                IllogicalCallContext ilcc = (IllogicalCallContext)this.IllogicalCallContext;
                ec.IllogicalCallContext = (IllogicalCallContext)ilcc.Clone();
            }

            return(ec);
        }
Ejemplo n.º 2
0
        public ExecutionContext CreateCopy()
        {
            if (!isNewCapture)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotCopyUsedContext"));
            }
            ExecutionContext ec = new ExecutionContext();

            ec.isNewCapture = true;
#if FEATURE_SYNCHRONIZATIONCONTEXT
            ec._syncContext = _syncContext == null ? null : _syncContext.CreateCopy();
#endif // #if FEATURE_SYNCHRONIZATIONCONTEXT
#if FEATURE_CAS_POLICY
            // capture the host execution context
            ec._hostExecutionContext = _hostExecutionContext == null ? null : _hostExecutionContext.CreateCopy();
#endif // FEATURE_CAS_POLICY
#if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK
            if (_securityContext != null)
            {
                ec._securityContext = _securityContext.CreateCopy();
                ec._securityContext.ExecutionContext = ec;
            }
#endif // #if FEATURE_IMPERSONATION || FEATURE_COMPRESSEDSTACK

            if (this._logicalCallContext != null)
            {
                ec.LogicalCallContext = (LogicalCallContext)this.LogicalCallContext.Clone();
            }

            Contract.Assert(this._illogicalCallContext == null);

            return(ec);
        }
Ejemplo n.º 3
0
 internal static void PartialTrustInvoke(ContextCallback callback, object state)
 {
     if (NeedPartialTrustInvoke)
     {
         SecurityContext.Run(aspNetSecurityContext.CreateCopy(), callback, state);
     }
     else
     {
         callback(state);
     }
 }
Ejemplo n.º 4
0
 protected void ScheduleWithContext(SecurityContext contextToSchedule)
 {
     if (contextToSchedule == null)
     {
         throw Fx.Exception.ArgumentNull("context");
     }
     if (this.isScheduled)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.ActionItemIsAlreadyScheduled), null);
     }
     this.isScheduled = true;
     this.context     = contextToSchedule.CreateCopy();
     this.ScheduleCallback(ActionItem.CallbackHelper.InvokeWithContextCallback);
 }
Ejemplo n.º 5
0
        protected void ScheduleWithContext(SecurityContext contextToSchedule)
        {
            if (contextToSchedule == null)
            {
                throw Fx.Exception.ArgumentNull("context");
            }
            if (_isScheduled)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.ActionItemIsAlreadyScheduled));
            }

            _isScheduled = true;
            _context     = contextToSchedule.CreateCopy();
            ScheduleCallback(CallbackHelper.InvokeWithContextCallback);
        }
Ejemplo n.º 6
0
        protected void ScheduleWithContext(SecurityContext context)
        {
            if (context == null)
            {
                throw Fx.Exception.ArgumentNull("context");
            }
            if (isScheduled)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.ActionItemIsAlreadyScheduled));
            }

            this.isScheduled = true;
            this.context     = context.CreateCopy();
            ScheduleCallback(CallbackHelper.InvokeWithContextCallback);
        }
Ejemplo n.º 7
0
        public void Copy()
        {
            SecurityContext sc = SecurityContext.Capture();

            Assert.IsNotNull(sc, "Capture");

            SecurityContext copy = sc.CreateCopy();

            Assert.IsNotNull(copy, "Copy of Capture");

            Assert.IsFalse(sc.Equals(copy));
            Assert.IsFalse(copy.Equals(sc));
            Assert.IsFalse(Object.ReferenceEquals(sc, copy));

            SecurityContext copy2nd = copy.CreateCopy();

            Assert.IsNotNull(copy2nd, "2nd level copy of Capture");
        }