private void ReleaseContextAsync()
 {
     if (this._token != NegativeOne)
     {
         if (AppDomain.CurrentDomain.IsFinalizingForUnload())
         {
             this.ReleaseContext();
         }
         else
         {
             object transparentProxy = this.GetTransparentProxy();
             if (this.IsJitActivated && this._tabled)
             {
                 IdentityTable.RemoveObject(this._token, transparentProxy);
                 this._tabled = false;
             }
             lock (_ctxQueue)
             {
                 _ctxQueue.Enqueue(this._context);
             }
             this._context = NegativeOne;
             this._token   = NegativeOne;
         }
     }
 }
        MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
        {
            RealProxy realProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            int  num               = ServicedComponentInfo.SCICachedLookup(serverType);
            bool fIsJitActivated   = (num & 8) != 0;
            bool fIsPooled         = (num & 0x10) != 0;
            bool fAreMethodsSecure = (num & 0x20) != 0;

            if (fIsJitActivated)
            {
                object obj2 = IdentityTable.FindObject(Proxy.GetCurrentContextToken());
                if (obj2 != null)
                {
                    realProxy = RemotingServices.GetRealProxy(obj2);
                }
            }
            if (realProxy == null)
            {
                realProxy = new ServicedComponentProxy(serverType, fIsJitActivated, fIsPooled, fAreMethodsSecure, true);
            }
            else if (realProxy is ServicedComponentProxy)
            {
                ((ServicedComponentProxy)realProxy).ConstructServer();
            }
            return((MarshalByRefObject)realProxy.GetTransparentProxy());
        }
 private void ReleaseContext()
 {
     if (this._token != NegativeOne)
     {
         object transparentProxy = this.GetTransparentProxy();
         if (this.IsJitActivated && this._tabled)
         {
             IdentityTable.RemoveObject(this._token, transparentProxy);
             this._tabled = false;
         }
         if (this._tracker != null)
         {
             this._tracker.Release();
         }
         Marshal.Release(this._context);
         this._context = NegativeOne;
         this._token   = NegativeOne;
     }
 }
        internal void ActivateObject()
        {
            IntPtr currentContextToken = Proxy.GetCurrentContextToken();

            if ((this.IsObjectPooled && this.IsJitActivated) && (this.HomeToken != currentContextToken))
            {
                object obj2 = IdentityTable.FindObject(currentContextToken);
                if (obj2 != null)
                {
                    ServicedComponentProxy realProxy    = (ServicedComponentProxy)RemotingServices.GetRealProxy(obj2);
                    ProxyTearoff           proxyTearoff = null;
                    ServicedComponent      server       = this.DisconnectForPooling(ref proxyTearoff);
                    proxyTearoff.SetCanBePooled(false);
                    realProxy.ConnectForPooling(this, server, proxyTearoff, true);
                    EnterpriseServicesHelper.SwitchWrappers(this, realProxy);
                    realProxy.ActivateProxy();
                    return;
                }
            }
            this.ActivateProxy();
        }
        private void SetupContext(bool construction)
        {
            IntPtr currentContextToken = Proxy.GetCurrentContextToken();

            if (this._token != currentContextToken)
            {
                if (this._token != NegativeOne)
                {
                    this.ReleaseContext();
                }
                this._token   = currentContextToken;
                this._context = Proxy.GetCurrentContext();
                this._tracker = Proxy.FindTracker(this._context);
            }
            if (!this._filterConstructors)
            {
                RealProxy.SetStubData(this, this._token);
            }
            if ((this.IsJitActivated && !this._tabled) && !construction)
            {
                IdentityTable.AddObject(this._token, this.GetTransparentProxy());
                this._tabled = true;
            }
        }
Esempio n. 6
0
        MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
        {
            // Platform.Assert(Platform.W2K, "ServicedComponent");

            DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for unmanaged request");

            DBG.Assert(ServicedComponentInfo.IsTypeServicedComponent(serverType),
                       "unconfigured type passed to ICustomFactory.CreateInstance");

            RealProxy rp = null;

            // The reason we don't want to cleanup GIT cookies from inside here (passing false) is
            // because we will already be in a new context, and RevokeInterfaceFromGlobal will be very expensive
            // (like 5x), as it needs to switch context.  A more appropriate place to do this is in the managed CreateInstance
            // before we even call CoCreateInstance

            ServicedComponentProxy.CleanupQueues(false);



            int iSCInfo = ServicedComponentInfo.SCICachedLookup(serverType);

            bool fIsTypeJITActivated = (iSCInfo & ServicedComponentInfo.SCI_JIT) != 0;
            bool fIsTypePooled       = (iSCInfo & ServicedComponentInfo.SCI_OBJECTPOOLED) != 0;
            bool fAreMethodsSecure   = (iSCInfo & ServicedComponentInfo.SCI_METHODSSECURE) != 0;

            if (fIsTypeJITActivated)
            {
                // NOTE: If the component is JIT activated, we may be trying
                // to connect a new backing object to an existing TP held
                // by a managed client.  So we look in our handy table
                // to see if there is a component registered for this context.
                // Because it is JIT activated, COM+ ensures that it will
                // have been the distinguished object in this context.

                IntPtr token = Thunk.Proxy.GetCurrentContextToken();

                DBG.Info(DBG.SC, "SCPA.CreateInstance looking for JIT object in IdentityTable. token=" + token);

                Object otp = IdentityTable.FindObject(token);

                if (otp != null)
                {
                    DBG.Info(DBG.SC, "SCPA.CreateInstance found JIT object in IdentityTable.");
                    rp = RemotingServices.GetRealProxy(otp);

                    DBG.Assert(rp is ServicedComponentProxy, "Cached something that wasn't a serviced component proxy in the ID table!");
                    DBG.Assert(rp != null, " GetTransparentProxy.. real proxy is null");
                    DBG.Assert(serverType == rp.GetProxiedType(), "Invalid type found in Deactivated list");
                }
            }

            if (rp == null)
            {
                DBG.Info(DBG.SC, "SCPA.CreateInstance creating new SCP fJIT=" + fIsTypeJITActivated + " fPooled=" + fIsTypePooled + " fMethodsSecure=" + fAreMethodsSecure);
                rp = new ServicedComponentProxy(serverType, fIsTypeJITActivated, fIsTypePooled, fAreMethodsSecure, true);
            }
            else if (rp is ServicedComponentProxy)
            {
                ServicedComponentProxy scp = (ServicedComponentProxy)rp;
                scp.ConstructServer();
            }

            MarshalByRefObject mo = (MarshalByRefObject)rp.GetTransparentProxy();

            DBG.Assert(mo != null, " GetTransparentProxy returned NULL");

            DBG.Info(DBG.SC, "SCPA.ICustomFactory.CreateInstance done.");

            return(mo);
        }