* ProxyAttribute.cs: Implemented.
authorLluis Sanchez <lluis@novell.com>
Mon, 3 Mar 2003 16:42:50 +0000 (16:42 -0000)
committerLluis Sanchez <lluis@novell.com>
Mon, 3 Mar 2003 16:42:50 +0000 (16:42 -0000)
* RealProxy.cs: Added stubs for some missing methods.
* RemotingProxy.cs: The activation constructor now creates the ConstructionCall
  message and collects the context properties.
  Activation of objects now use IActivator instances.

svn path=/trunk/mcs/; revision=12140

mcs/class/corlib/System.Runtime.Remoting.Proxies/ChangeLog
mcs/class/corlib/System.Runtime.Remoting.Proxies/ProxyAttribute.cs
mcs/class/corlib/System.Runtime.Remoting.Proxies/RealProxy.cs
mcs/class/corlib/System.Runtime.Remoting.Proxies/RemotingProxy.cs

index e43233858d88808cafa4eb4926c527407435add9..0d92f270dfc947045bf328c15a5e1b62e2cb1744 100644 (file)
@@ -1,3 +1,11 @@
+2003-03-03  Lluis Sanchez Gual <lluis@ideary.com>
+
+       * ProxyAttribute.cs: Implemented.
+       * RealProxy.cs: Added stubs for some missing methods.
+       * RemotingProxy.cs: The activation constructor now creates the ConstructionCall
+         message and collects the context properties.
+         Activation of objects now use IActivator instances.
+
 2003-02-18  Lluis Sanchez Gual <lluis@ideary.com>
 
        * RealProxy.cs: Changed constructor to allow only ClientIdentity instances. 
index 34314255574809a9cd319346caa640644058fb98..ef12b8f1a69dcabde4f05212095fbdd3722447d5 100644 (file)
@@ -10,6 +10,7 @@ using System;
 using System.Runtime.Remoting;
 using System.Runtime.Remoting.Activation;
 using System.Runtime.Remoting.Contexts;
+using System.Runtime.Remoting.Channels;
 
 namespace System.Runtime.Remoting.Proxies {
 
@@ -20,28 +21,25 @@ namespace System.Runtime.Remoting.Proxies {
                {
                }
 
-               [MonoTODO]
                public virtual MarshalByRefObject CreateInstance (Type serverType)
                {
-                       throw new NotImplementedException ();
+                       RemotingProxy proxy = new RemotingProxy (serverType, ChannelServices.CrossContextUrl, null);
+                       return (MarshalByRefObject) proxy.GetTransparentProxy();
                }
 
-               [MonoTODO]
                public virtual RealProxy CreateProxy (ObjRef objref, Type serverType, object serverObject, Context serverContext)
                {
-                       throw new NotImplementedException ();
+                       return RemotingServices.GetRealProxy (RemotingServices.GetProxyForRemoteObject (objref, false));
                }
 
-               [MonoTODO]
                public void GetPropertiesForNewContext (IConstructionCallMessage msg)
                {
-                       throw new NotImplementedException ();
+                       // Nothing to add
                }
 
-               [MonoTODO]
                public bool IsContextOK (Context ctx, IConstructionCallMessage msg)
                {
-                       throw new NotImplementedException ();
+                       return true;
                }
        }
 }
index 31ac3798a62044459aa8d73a5aaa28abf0e3f954..0abc19d6742b710fff83d663e5e55fcc64266358 100644 (file)
@@ -12,6 +12,7 @@
 using System;
 using System.Runtime.Remoting;
 using System.Runtime.Remoting.Messaging;
+using System.Runtime.Remoting.Activation;
 using System.Runtime.CompilerServices;
 using System.Runtime.Serialization;
 
@@ -61,7 +62,7 @@ namespace System.Runtime.Remoting.Proxies
 
                public virtual ObjRef CreateObjRef (Type requestedType)
                {
-                       return _objectIdentity.CreateObjRef (requestedType);
+                       return RemotingServices.Marshal ((MarshalByRefObject) GetTransparentProxy(), null, requestedType);
                }
 
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
@@ -100,5 +101,29 @@ namespace System.Runtime.Remoting.Proxies
                {
                        return _objTP;
                }
+
+               [MonoTODO]
+               public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
+               {
+                       throw new NotImplementedException();
+               }
+
+               [MonoTODO]
+               protected void AttachServer(MarshalByRefObject s)
+               {
+                       throw new NotImplementedException();
+               }
+
+               [MonoTODO]
+               protected MarshalByRefObject DetachServer()
+               {
+                       throw new NotImplementedException();
+               }
+
+               [MonoTODO]
+               protected MarshalByRefObject GetUnwrappedServer()
+               {
+                       throw new NotImplementedException();
+               }
        }
 }
index 4a54ca86a8bde079ed802b603b405528bd000744..d14f76068d1f1ceeaa67cf155610c2a0bfd22ded 100644 (file)
@@ -13,7 +13,9 @@ using System.Reflection;
 using System.Runtime.Remoting.Messaging;
 using System.Runtime.Remoting.Activation;
 using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Contexts;
 using System.Runtime.CompilerServices;
+using System.Threading;
 
 
 namespace System.Runtime.Remoting.Proxies
@@ -26,16 +28,21 @@ namespace System.Runtime.Remoting.Proxies
 \r
                IMessageSink _sink;
                string _activationUrl;
+               bool _hasEnvoySink;
+               ConstructionCall _ctorCall;
 
                internal RemotingProxy (Type type, ClientIdentity identity) : base (type, identity)
                {
                        _sink = identity.ChannelSink;
+                       _hasEnvoySink = false;
                }
 
-               internal RemotingProxy (Type type, string activationUrl, IMessageSink activationSink) : base (type)
+               internal RemotingProxy (Type type, string activationUrl, object[] activationAttributes) : base (type)
                {
-                       _sink = activationSink;
                        _activationUrl = activationUrl;
+                       _hasEnvoySink = false;
+
+                       _ctorCall = ActivationServices.CreateConstructionCall (type, activationUrl, activationAttributes);
                }
 
                public override IMessage Invoke (IMessage request)
@@ -43,7 +50,7 @@ namespace System.Runtime.Remoting.Proxies
                        MonoMethodMessage mMsg = (MonoMethodMessage) request;
 
                        if (mMsg.MethodBase.IsConstructor)
-                               return ActivateRemoteObject (request);
+                               return ActivateRemoteObject (mMsg);
 
                        if (mMsg.MethodBase == _cache_GetHashCodeMethod)
                                return new MethodResponse(ObjectIdentity.GetHashCode(), null, null, request as IMethodCallMessage);\r
@@ -53,46 +60,62 @@ namespace System.Runtime.Remoting.Proxies
 
                        mMsg.Uri = _objectIdentity.ObjectUri;
                        ((IInternalMessage)mMsg).TargetIdentity = _objectIdentity;
-                       return _sink.SyncProcessMessage (request);
+
+                       // Exiting from the context?
+                       if (!Thread.CurrentContext.IsDefaultContext && !_hasEnvoySink)
+                               return Thread.CurrentContext.GetClientContextSinkChain ().SyncProcessMessage (request);
+                       else
+                               return _sink.SyncProcessMessage (request);
                }
 
-               IMessage ActivateRemoteObject (IMessage request)
+               IMessage ActivateRemoteObject (IMethodMessage request)
                {
                        if (_activationUrl == null)
                                return new ReturnMessage (this, new object[0], 0, null, (IMethodCallMessage) request);  // Ignore constructor call for WKOs
 
                        IMethodReturnMessage response;
 
-                       ConstructionCall ctorCall = new ConstructionCall (request);
+                       _ctorCall.CopyFrom (request);
 
                        if (_activationUrl == ChannelServices.CrossContextUrl)
                        {
                                // Cross context activation
 
-                               _objectIdentity = RemotingServices.CreateContextBoundObjectIdentity (ctorCall.ActivationType);
-                               RemotingServices.SetMessageTargetIdentity (ctorCall, _objectIdentity);
-                               response = (IConstructionReturnMessage) _sink.SyncProcessMessage (ctorCall);
+                               _objectIdentity = RemotingServices.CreateContextBoundObjectIdentity (_ctorCall.ActivationType);
+                               RemotingServices.SetMessageTargetIdentity (_ctorCall, _objectIdentity);
+                               response = _ctorCall.Activator.Activate (_ctorCall);
                        }
                        else
                        {
                                // Remote activation
 
-                               MethodCall call = new MethodCall (_activationUrl, typeof(RemoteActivator).AssemblyQualifiedName, "Activate", new object[] {ctorCall} );
-                               response = (IMethodReturnMessage) _sink.SyncProcessMessage (call);
-                       
-                               if (response.Exception != null) return response;
+                               RemoteActivator remoteActivator = (RemoteActivator) RemotingServices.Connect (typeof (RemoteActivator), _activationUrl);
+
+                               try {
+                                       response = remoteActivator.Activate (_ctorCall) as IMethodReturnMessage;
+                               }
+                               catch (Exception ex) {
+                                       return new ReturnMessage (ex, (IMethodCallMessage)request);
+                               }
 
-                               response = response.ReturnValue as IMethodReturnMessage;
                                ObjRef objRef = (ObjRef) response.ReturnValue;
+                               if (RemotingServices.GetIdentityForUri (objRef.URI) != null)
+                                       throw new RemotingException("Inconsistent state during activation; there may be two proxies for the same object");
+
                                _objectIdentity = RemotingServices.GetOrCreateClientIdentity (objRef, this);
                        }
 
-                       if (_objectIdentity.EnvoySink != null) _sink = _objectIdentity.EnvoySink;
-                       else _sink = _objectIdentity.ChannelSink;
+                       if (_objectIdentity.EnvoySink != null) 
+                       {
+                               _sink = _objectIdentity.EnvoySink;
+                               _hasEnvoySink = true;
+                       }
+                       else 
+                               _sink = _objectIdentity.ChannelSink;
 
                        _activationUrl = null;
+                       _ctorCall = null;
                        return response;
                }
-
        }
 }