private IMessage HandleDispose(IMessage msg)
        {
            IMethodCallMessage message = msg as IMethodCallMessage;

            if (message != null)
            {
                MethodBase methodBase = message.MethodBase;
                if ((methodBase == _getServicedComponentDispose) || (methodBase == _getIDisposableDispose))
                {
                    ServicedComponent.DisposeObject((ServicedComponent)this.GetTransparentProxy());
                    IMethodCallMessage mcm = (IMethodCallMessage)msg;
                    return(new ReturnMessage(null, null, 0, mcm.LogicalCallContext, mcm));
                }
            }
            return(null);
        }
Exemple #2
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);
 }
 private void DispatchDeactivate()
 {
     if (this._fDeliverADC)
     {
         ServicedComponent transparentProxy = (ServicedComponent)this.GetTransparentProxy();
         this._fIsServerActivated = false;
         try
         {
             if (!this._fFinalized)
             {
                 transparentProxy.Deactivate();
             }
         }
         catch (Exception exception)
         {
             if ((exception is NullReferenceException) || (exception is SEHException))
             {
                 throw;
             }
         }
         if (this.IsObjectPooled)
         {
             bool fCanBePooled = false;
             try
             {
                 if (!this._fFinalized)
                 {
                     fCanBePooled = transparentProxy.CanBePooled();
                 }
                 this._proxyTearoff.SetCanBePooled(fCanBePooled);
             }
             catch (Exception exception2)
             {
                 if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                 {
                     throw;
                 }
                 this._proxyTearoff.SetCanBePooled(false);
             }
         }
     }
 }
 internal void Dispose(bool disposing)
 {
     if (Util.ExtendedLifetime && (disposing || !_asyncFinalizeEnabled))
     {
         this.SendDestructionEvents(disposing);
     }
     if (this._fIsActive)
     {
         ServicedComponent transparentProxy = (ServicedComponent)this.GetTransparentProxy();
         try
         {
             transparentProxy._internalDeactivate(disposing);
         }
         catch (ObjectDisposedException)
         {
         }
     }
     if ((!disposing && this.IsObjectPooled) && (base.GetUnwrappedServer() != null))
     {
         this.FinalizeHere();
     }
     this.ReleasePoolUnk();
     if ((Util.ExtendedLifetime && !disposing) && _asyncFinalizeEnabled)
     {
         this.SendDestructionEventsAsync();
     }
     this.ReleaseGitCookie();
     if ((disposing || !_asyncFinalizeEnabled) || AppDomain.CurrentDomain.IsFinalizingForUnload())
     {
         this.ReleaseContext();
     }
     else if (!Util.ExtendedLifetime)
     {
         this.ReleaseContextAsync();
     }
     this._fIsActive = false;
     if (disposing)
     {
         GC.SuppressFinalize(this);
     }
 }
        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();
        }
Exemple #7
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();
            }
        }
 private void DispatchActivate()
 {
     if (this._fDeliverADC)
     {
         this._fIsServerActivated = true;
         ServicedComponent transparentProxy = (ServicedComponent)this.GetTransparentProxy();
         try
         {
             transparentProxy.Activate();
         }
         catch (Exception exception)
         {
             if ((exception is NullReferenceException) || (exception is SEHException))
             {
                 throw;
             }
             this.SendDestructionEvents(false);
             this.ReleasePoolUnk();
             this.ReleaseContext();
             this.ReleaseGitCookie();
             this._fIsServerActivated = false;
             try
             {
                 EventLog log = new EventLog {
                     Source = "System.EnterpriseServices"
                 };
                 string message = Resource.FormatString("Err_ActivationFailed", exception.ToString());
                 log.WriteEntry(message, EventLogEntryType.Error);
             }
             catch (Exception exception2)
             {
                 if ((exception2 is NullReferenceException) || (exception2 is SEHException))
                 {
                     throw;
                 }
             }
             throw new COMException(Resource.FormatString("ServicedComponentException_ActivationFailed"), -2147164123);
         }
     }
 }
 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();
     }
 }
        ///<summary>
        /// Called by a <see cref="ServicedComponent"/> exported by <see cref="EnterpriseServicesExporter"/> 
        /// to obtain a reference to the service it proxies.
        ///</summary>
        public static object GetObject(ServicedComponent sender, string targetName)
        {
            EnsureComponentContextRegistryInitialized(sender.GetType());
            try
            {
                return _appContext.GetObject(targetName);

            }
            catch (Exception e)
            {
                Trace.WriteLine("Error configuring application context for COM component of type " + sender.GetType() + ": " + e);
                throw;
            }
        }
 public static void DisposeObject(ServicedComponent sc)
 {
     throw new NotImplementedException();
 }
Exemple #12
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);
        }
 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);
 }
Exemple #14
0
		public static void DisposeObject (ServicedComponent sc)
		{
			throw new NotImplementedException ();
		}