Esempio n. 1
0
        // TODO:  Move to ServicedComponent static method
        public static void DeactivateObject(Object otp, bool disposing)
        {
            RealProxy rp = RemotingServices.GetRealProxy(otp);
            ServicedComponentProxy scp = rp as ServicedComponentProxy;

            DBG.Assert(scp != null, "CS.DeactivateObject called on a non-ServicedComponentProxy");

            if (!scp.IsProxyDeactivated)
            {
                DBG.Assert(scp.HomeToken == Thunk.Proxy.GetCurrentContextToken(), "Deactivate called from wrong context");

                if (scp.IsObjectPooled)
                {
                    DBG.Info(DBG.SC, "CS.DeactivateObject calling ReconnectForPooling");
                    ReconnectForPooling(scp);
                }

                // this would wack the real server also so do this last

                DBG.Info(DBG.SC, "CS.DeactivateObject calling scp.DeactivateProxy");
                scp.DeactivateProxy(disposing);
            }

            DBG.Assert(scp.IsProxyDeactivated, "scp not deactive");
        }
Esempio n. 2
0
        // TODO: @cleanup: Move to ServicedComponentProxy
        private static void ReconnectForPooling(ServicedComponentProxy scp)
        {
            Type         serverType        = scp.GetProxiedType();
            bool         fIsJitActivated   = scp.IsJitActivated;
            bool         fIsTypePooled     = scp.IsObjectPooled;
            bool         fAreMethodsSecure = scp.AreMethodsSecure;
            ProxyTearoff tearoff           = null;

            DBG.Assert(fIsTypePooled == true, "CS.ReconnectForPooling called on a non-pooled proxy!");

            DBG.Info(DBG.SC, "CS.ReconnectForPooling (type is pooled) " + serverType);
            ServicedComponent server = scp.DisconnectForPooling(ref tearoff);

            // now setup a new SCP that we can add to the pool
            // with the current server object and the CCW
            ServicedComponentProxy newscp = new ServicedComponentProxy(serverType, fIsJitActivated, fIsTypePooled, fAreMethodsSecure, false);

            DBG.Info(DBG.SC, "CS.ReconnectForPooling (calling newscp.ConnectForPooling)");
            newscp.ConnectForPooling(scp, server, tearoff, false);
            // switch the CCW from oldtp to new tp

            DBG.Info(DBG.SC, "CS.ReconnectForPooling (SwitchingWrappers)");
            EnterpriseServicesHelper.SwitchWrappers(scp, newscp);

            // Strengthen the CCW:  The only reference now held is
            // the reference from the pool.
            if (tearoff != null)
            {
                Marshal.ChangeWrapperHandleStrength(tearoff, false);
            }
            Marshal.ChangeWrapperHandleStrength(newscp.GetTransparentProxy(), false);
        }
        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());
        }
Esempio n. 4
0
        /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.DisposeObject"]/*' />
        public static void DisposeObject(ServicedComponent sc)
        {
            RealProxy rp = RemotingServices.GetRealProxy(sc);

            if (rp is ServicedComponentProxy)
            {
                DBG.Info(DBG.SC, "DisposeObject(): Disposing ServicedComponentProxy");

                ServicedComponentProxy scp = (ServicedComponentProxy)rp;

                RemotingServices.Disconnect(sc);

                // dispose the actual proxy
                scp.Dispose(true);
            }
            else if (rp is RemoteServicedComponentProxy)
            {
                DBG.Info(DBG.SC, "DisposeObject(): Disposing RemoteServicedComponentProxy");

                RemoteServicedComponentProxy rscp = (RemoteServicedComponentProxy)rp;

                // dispose the remote instance first

                sc.Dispose();

                // then dispose the local proxy

                rscp.Dispose(true);
            }
            else     // We're off in magic land, with no proxy of our own.
            {
                sc.Dispose();
            }
        }
Esempio n. 5
0
        /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.ServicedComponent"]/*' />
        public ServicedComponent()
        {
            ServicedComponentProxy pxy = RemotingServices.GetRealProxy(this) as ServicedComponentProxy;

            DBG.Assert(pxy != null, "RealProxy() is null during constructor!");
            pxy.SuppressFinalizeServer();

            Type thisType = this.GetType();

            _denyRemoteDispatch = ServicedComponentInfo.AreMethodsSecure(thisType);

            // Get the methodinfo for finalize...
            // REVIEW:  Do we have to do anything special to make sure we
            // get the one furthest down the chain?

            bool bFoundInCache = false;

            _finalize = _finalizeCache.Get(thisType, out bFoundInCache) as MethodInfo;

            if (bFoundInCache == false)
            {
                _finalize = GetDeclaredFinalizer(thisType);
                _finalizeCache.Put(thisType, _finalize);
            }

            _calledDispose = false;
        }
Esempio n. 6
0
        void IObjectControl.Deactivate()
        {
            ServicedComponentProxy target = (ServicedComponentProxy)this._scp.Target;

            if (target != null)
            {
                ComponentServices.DeactivateObject(target.GetTransparentProxy(), true);
            }
        }
Esempio n. 7
0
        public static void DeactivateObject(object otp, bool disposing)
        {
            ServicedComponentProxy realProxy = RemotingServices.GetRealProxy(otp) as ServicedComponentProxy;

            if (!realProxy.IsProxyDeactivated)
            {
                if (realProxy.IsObjectPooled)
                {
                    ReconnectForPooling(realProxy);
                }
                realProxy.DeactivateProxy(disposing);
            }
        }
Esempio n. 8
0
        private static void ReconnectForPooling(ServicedComponentProxy scp)
        {
            Type                   proxiedType      = scp.GetProxiedType();
            bool                   isJitActivated   = scp.IsJitActivated;
            bool                   isObjectPooled   = scp.IsObjectPooled;
            bool                   areMethodsSecure = scp.AreMethodsSecure;
            ProxyTearoff           proxyTearoff     = null;
            ServicedComponent      server           = scp.DisconnectForPooling(ref proxyTearoff);
            ServicedComponentProxy newcp            = new ServicedComponentProxy(proxiedType, isJitActivated, isObjectPooled, areMethodsSecure, false);

            newcp.ConnectForPooling(scp, server, proxyTearoff, false);
            EnterpriseServicesHelper.SwitchWrappers(scp, newcp);
            if (proxyTearoff != null)
            {
                Marshal.ChangeWrapperHandleStrength(proxyTearoff, false);
            }
            Marshal.ChangeWrapperHandleStrength(newcp.GetTransparentProxy(), false);
        }
 internal void ConnectForPooling(ServicedComponentProxy oldscp, ServicedComponent server, ProxyTearoff proxyTearoff, bool fForJit)
 {
     if (oldscp != null)
     {
         this._fReturnedByFinalizer = oldscp._fFinalized;
         if (fForJit)
         {
             this._pPoolUnk   = oldscp._pPoolUnk;
             oldscp._pPoolUnk = IntPtr.Zero;
         }
     }
     if (server != null)
     {
         base.AttachServer(server);
     }
     this._proxyTearoff = proxyTearoff;
     this._proxyTearoff.Init(this);
 }
Esempio n. 10
0
        public static void DisposeObject(ServicedComponent sc)
        {
            RealProxy realProxy = RemotingServices.GetRealProxy(sc);

            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                RemotingServices.Disconnect(sc);
                proxy2.Dispose(true);
            }
            else if (realProxy is RemoteServicedComponentProxy)
            {
                RemoteServicedComponentProxy proxy3 = (RemoteServicedComponentProxy)realProxy;
                sc.Dispose();
                proxy3.Dispose(true);
            }
            else
            {
                sc.Dispose();
            }
        }
        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();
        }
 internal override void Init(ServicedComponentProxy scp)
 {
     this._scp = scp;
 }
Esempio n. 13
0
 internal override void Init(ServicedComponentProxy scp)
 {
     this._scp = new WeakReference(scp, true);
 }
 internal override void Init(ServicedComponentProxy scp)
 {
     this._scp = new WeakReference(scp, true);
 }
Esempio n. 15
0
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            // Platform.Assert(Platform.W2K, "ServicedComponent");

            RealProxy          rp = null;
            MarshalByRefObject mo = null;

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


            ServicedComponentProxy.CleanupQueues(true);

            // First check if the type is configured to be activated remotely or is a well
            // known remote type.
            if ((null != RemotingConfiguration.IsWellKnownClientType(serverType)) ||
                (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType)))
            {
                // It is configured for remote activation. Ask remoting services to do the
                // job of creating a remoting proxy and returning it.
                mo = base.CreateInstance(serverType);
                rp = RemotingServices.GetRealProxy(mo);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri         = "";
                bool   bEventClass = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk        = Thunk.Proxy.CoCreateObject(serverType, !bEventClass, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try {
                        // TODO:  Get rid of this useless foreknowledge requirement
                        // Is there a way we can tell by QI'ing this guy if he's
                        // an event class (or something else we need to artificially
                        // wrap?
                        if (bEventClass)
                        {
                            // events and queued components use RemoteServicedComponentProxy
                            // set up a TP & Remote ServicedComponentProxy pair
                            rp = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            mo = (MarshalByRefObject)rp.GetTransparentProxy();
                        }
                        else
                        {
                            if (bIsAnotherProcess)              // a-ha, we know it should be a RSCP now !!!!
                            {
                                FastRSCPObjRef oref = new FastRSCPObjRef(pUnk, serverType, uri);
                                mo = (MarshalByRefObject)RemotingServices.Unmarshal(oref);

                                DBG.Assert(mo != null, "RemotingServices.Unmarshal returned null!");
                                DBG.Assert(RemotingServices.GetRealProxy(mo) is RemoteServicedComponentProxy, "RemotingServices.Unmarshal did not return an RSCP!");
                            }
                            else        // bummer, this will give us back a SCP
                            {
                                mo = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);

                                DBG.Info(DBG.SC, "ret = " + mo.GetType());
                                DBG.Info(DBG.SC, "st = " + serverType);
                                DBG.Info(DBG.SC, "rt == sc = " + (mo.GetType() == serverType));
                                DBG.Info(DBG.SC, "instanceof = " + serverType.IsInstanceOfType(mo));

                                if (!(serverType.IsInstanceOfType(mo)))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, mo.GetType()));
                                }

                                rp = RemotingServices.GetRealProxy(mo);
                                if (!(rp is ServicedComponentProxy) && !(rp is RemoteServicedComponentProxy))
                                {
                                    // in cross-appdomain scenario, we get back a RemotingProxy, SetCOMIUnknown has not been made on our server!
                                    ServicedComponent sc = (ServicedComponent)mo;
                                    sc.DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }

            if (rp is ServicedComponentProxy)
            {
                // Here, we tell the server proxy that it needs to filter out
                // constructor calls:  We only need to do this if
                // the proxy lives in the same context as the caller,
                // otherwise we'll get an Invoke call and can do the
                // filtering automagically:
                ServicedComponentProxy scp = (ServicedComponentProxy)rp;
                if (scp.HomeToken == Thunk.Proxy.GetCurrentContextToken())
                {
                    scp.FilterConstructors();
                }
            }

            DBG.Assert(mo is ServicedComponent, " CoCI returned an invalid object type");
            DBG.Info(DBG.SC, "SCPA.CreateInstance done.");
            return(mo);
        }
Esempio n. 16
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);
        }
 internal void ConnectForPooling(ServicedComponentProxy oldscp, ServicedComponent server, ProxyTearoff proxyTearoff, bool fForJit)
 {
     if (oldscp != null)
     {
         this._fReturnedByFinalizer = oldscp._fFinalized;
         if (fForJit)
         {
             this._pPoolUnk = oldscp._pPoolUnk;
             oldscp._pPoolUnk = IntPtr.Zero;
         }
     }
     if (server != null)
     {
         base.AttachServer(server);
     }
     this._proxyTearoff = proxyTearoff;
     this._proxyTearoff.Init(this);
 }
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            RealProxy          realProxy        = null;
            MarshalByRefObject transparentProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            if ((RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (RemotingConfiguration.IsRemotelyActivatedClientType(serverType) != null))
            {
                transparentProxy = base.CreateInstance(serverType);
                realProxy        = RemotingServices.GetRealProxy(transparentProxy);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri   = "";
                bool   flag2 = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk  = Proxy.CoCreateObject(serverType, !flag2, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try
                    {
                        if (flag2)
                        {
                            realProxy        = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            transparentProxy = (MarshalByRefObject)realProxy.GetTransparentProxy();
                        }
                        else
                        {
                            bool flag3 = (RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType));
                            if (bIsAnotherProcess && !flag3)
                            {
                                FastRSCPObjRef objectRef = new FastRSCPObjRef(pUnk, serverType, uri);
                                transparentProxy = (MarshalByRefObject)RemotingServices.Unmarshal(objectRef);
                            }
                            else
                            {
                                transparentProxy = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);
                                if (!serverType.IsInstanceOfType(transparentProxy))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, transparentProxy.GetType()));
                                }
                                realProxy = RemotingServices.GetRealProxy(transparentProxy);
                                if ((!bIsAnotherProcess && !(realProxy is ServicedComponentProxy)) && !(realProxy is RemoteServicedComponentProxy))
                                {
                                    ((ServicedComponent)transparentProxy).DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }
            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                if (proxy2.HomeToken == Proxy.GetCurrentContextToken())
                {
                    proxy2.FilterConstructors();
                }
            }
            return(transparentProxy);
        }
 internal ServicedComponentStub(ServicedComponentProxy scp)
 {
     this.Refresh(scp);
 }
 internal void Refresh(ServicedComponentProxy scp)
 {
     this._scp = new WeakReference(scp, true);
 }
        internal static bool CleanupQueues(bool bGit)
        {
            bool flag  = true;
            bool flag2 = true;

            if (!_asyncFinalizeEnabled)
            {
                return(true);
            }
            if (bGit)
            {
                if (_gitQueue.Count > 0)
                {
                    bool flag3  = false;
                    int  cookie = 0;
                    lock (_gitQueue)
                    {
                        if (_gitQueue.Count > 0)
                        {
                            cookie = (int)_gitQueue.Dequeue();
                            flag3  = true;
                            flag   = _gitQueue.Count <= 0;
                        }
                    }
                    if (flag3)
                    {
                        Proxy.RevokeObject(cookie);
                    }
                }
            }
            else if (_gitQueue.Count > 0)
            {
                lock (_gitQueue)
                {
                    if ((_gitQueue.Count > 0) && (_QueuedItemsCount < 0x19))
                    {
                        try
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback(ServicedComponentProxy.RevokeAsync), _gitQueue.Count);
                            Interlocked.Increment(ref _QueuedItemsCount);
                        }
                        catch (Exception exception)
                        {
                            if ((exception is NullReferenceException) || (exception is SEHException))
                            {
                                throw;
                            }
                        }
                    }
                }
            }
            object obj2 = null;

            if (_ctxQueue.Count > 0)
            {
                lock (_ctxQueue)
                {
                    if (_ctxQueue.Count > 0)
                    {
                        obj2  = _ctxQueue.Dequeue();
                        flag2 = _ctxQueue.Count <= 0;
                    }
                }
                if (obj2 != null)
                {
                    if (!Util.ExtendedLifetime)
                    {
                        Marshal.Release((IntPtr)obj2);
                    }
                    else
                    {
                        ServicedComponentProxy proxy = (ServicedComponentProxy)obj2;
                        try
                        {
                            proxy.SendDestructionEvents(false);
                        }
                        catch (Exception exception2)
                        {
                            if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                            {
                                throw;
                            }
                        }
                        try
                        {
                            proxy.ReleaseContext();
                        }
                        catch (Exception exception3)
                        {
                            if ((exception3 is NullReferenceException) || (exception3 is SEHException))
                            {
                                throw;
                            }
                        }
                    }
                }
            }
            return(flag2 & flag);
        }
 internal abstract void Init(ServicedComponentProxy scp);
 internal void Refresh(ServicedComponentProxy scp)
 {
     this._scp = new WeakReference(scp, true);
 }
        void IManagedObjectInfo.GetIObjectControl(out IObjectControl pCtrl)
        {
            ServicedComponentProxy target = (ServicedComponentProxy)this._scp.Target;

            pCtrl = target.GetProxyTearoff() as IObjectControl;
        }
 internal ServicedComponentStub(ServicedComponentProxy scp)
 {
     this.Refresh(scp);
 }
 internal override void Init(ServicedComponentProxy scp)
 {
     this._scp = scp;
 }
 private static void ReconnectForPooling(ServicedComponentProxy scp)
 {
     Type proxiedType = scp.GetProxiedType();
     bool isJitActivated = scp.IsJitActivated;
     bool isObjectPooled = scp.IsObjectPooled;
     bool areMethodsSecure = scp.AreMethodsSecure;
     ProxyTearoff proxyTearoff = null;
     ServicedComponent server = scp.DisconnectForPooling(ref proxyTearoff);
     ServicedComponentProxy newcp = new ServicedComponentProxy(proxiedType, isJitActivated, isObjectPooled, areMethodsSecure, false);
     newcp.ConnectForPooling(scp, server, proxyTearoff, false);
     EnterpriseServicesHelper.SwitchWrappers(scp, newcp);
     if (proxyTearoff != null)
     {
         Marshal.ChangeWrapperHandleStrength(proxyTearoff, false);
     }
     Marshal.ChangeWrapperHandleStrength(newcp.GetTransparentProxy(), false);
 }