public virtual IConstructionReturnMessage Activate(IConstructionCallMessage ctorMsg) { if (ctorMsg == null) { throw new ArgumentNullException("ctorMsg"); } if (ctorMsg.Properties.Contains("Remote")) { return(LocalActivator.DoRemoteActivation(ctorMsg)); } if (ctorMsg.Properties.Contains("Permission")) { Type activationType = ctorMsg.ActivationType; object[] activationAttributes = null; if (activationType.IsContextful) { IList contextProperties = ctorMsg.ContextProperties; if (contextProperties != null && contextProperties.Count > 0) { RemotePropertyHolderAttribute remotePropertyHolderAttribute = new RemotePropertyHolderAttribute(contextProperties); activationAttributes = new object[] { remotePropertyHolderAttribute }; } } MethodBase methodBase = LocalActivator.GetMethodBase(ctorMsg); RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs(ctorMsg, reflectionCachedData.Parameters); object obj = Activator.CreateInstance(activationType, args, activationAttributes); if (RemotingServices.IsClientProxy(obj)) { RedirectionProxy redirectionProxy = new RedirectionProxy((MarshalByRefObject)obj, activationType); RemotingServices.MarshalInternal(redirectionProxy, null, activationType); obj = redirectionProxy; } return(ActivationServices.SetupConstructionReply(obj, ctorMsg, null)); } return(ctorMsg.Activator.Activate(ctorMsg)); }
public virtual IConstructionReturnMessage Activate(IConstructionCallMessage ctorMsg) { if (ctorMsg == null) { throw new ArgumentNullException("ctorMsg"); } if (ctorMsg.Properties.Contains("Remote")) { return DoRemoteActivation(ctorMsg); } if (!ctorMsg.Properties.Contains("Permission")) { return ctorMsg.Activator.Activate(ctorMsg); } Type activationType = ctorMsg.ActivationType; object[] activationAttributes = null; if (activationType.IsContextful) { IList contextProperties = ctorMsg.ContextProperties; if ((contextProperties != null) && (contextProperties.Count > 0)) { RemotePropertyHolderAttribute attribute = new RemotePropertyHolderAttribute(contextProperties); activationAttributes = new object[] { attribute }; } } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(GetMethodBase(ctorMsg)); object[] args = Message.CoerceArgs(ctorMsg, reflectionCachedData.Parameters); object obj2 = Activator.CreateInstance(activationType, args, activationAttributes); if (RemotingServices.IsClientProxy(obj2)) { RedirectionProxy proxy = new RedirectionProxy((MarshalByRefObject) obj2, activationType); RemotingServices.MarshalInternal(proxy, null, activationType); obj2 = proxy; } return ActivationServices.SetupConstructionReply(obj2, ctorMsg, null); }
public virtual IConstructionReturnMessage Activate( IConstructionCallMessage ctorMsg) { // This is where the activation service hooks in to activation // requests. We get called as the activation message is recognized // by the ClientContextTerminatorSink & routed to us. // // NOTE: This gets called for both purely within appDomain activation // and 'real' remote activation scenarios as the request goes out of // the client context. // It also gets called as an incoming remote call is routed to the // local activator by the remote activator object. // BCLDebug.Log("Activation Services:: new Activate()"); if (ctorMsg == null) { throw new ArgumentNullException("ctorMsg"); } Contract.EndContractBlock(); // Check if we have marked this activation to go remote if (ctorMsg.Properties.Contains(ActivationServices.RemoteActivateKey)) { //DBG Console.WriteLine("Attempting remote activation!"); return DoRemoteActivation(ctorMsg); } else { // We must be in either a pure cross context activation or // a remote incoming activation request (in which case we // already checked the permission to create an instance of // this type). if (ctorMsg.Properties.Contains(ActivationServices.PermissionKey)) { Type activationType = ctorMsg.ActivationType; // We are on the server end of a real remote activation // Create a local attribute that contributes the context // properties requested by the remote request Object[] attr = null; if (activationType.IsContextful) { IList cp = ctorMsg.ContextProperties; if (cp != null && cp.Count > 0) { RemotePropertyHolderAttribute rph = new RemotePropertyHolderAttribute(cp); attr = new Object[1]; attr[0] = rph; } } MethodBase mb = GetMethodBase(ctorMsg); RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(mb); Object[] args = Message.CoerceArgs(ctorMsg, methodCache.Parameters); Object server = Activator.CreateInstance( activationType, args, attr); // check to see if we need to do redirection if (RemotingServices.IsClientProxy(server)) { // The wellknown type is remoted so we must wrap the proxy // with a local object. // The redirection proxy masquerades as an object of the appropriate // type, and forwards incoming messages to the actual proxy. RedirectionProxy redirectedProxy = new RedirectionProxy((MarshalByRefObject)server, activationType); RemotingServices.MarshalInternal(redirectedProxy, null, activationType); server = redirectedProxy; } return ActivationServices.SetupConstructionReply( server, ctorMsg, null); } else { BCLDebug.Log("Attempting X-Context activation!"); // delegate to the Activator in the message return ctorMsg.Activator.Activate(ctorMsg); } } }