internal void AttachIdentity(Identity identity) { _objectIdentity = identity; if (identity is ClientActivatedIdentity) // It is a CBO { ClientActivatedIdentity cai = (ClientActivatedIdentity)identity; _targetContext = cai.Context; AttachServer(cai.GetServerObject()); cai.SetClientProxy((MarshalByRefObject)GetTransparentProxy()); } if (identity is ClientIdentity) { ((ClientIdentity)identity).ClientProxy = (MarshalByRefObject)GetTransparentProxy(); _targetUri = ((ClientIdentity)identity).TargetUri; } else { _targetUri = identity.ObjectUri; } if (_objectIdentity.EnvoySink != null) { _sink = _objectIdentity.EnvoySink; _hasEnvoySink = true; } else { _sink = _objectIdentity.ChannelSink; } _ctorCall = null; // Object already constructed }
public static ConstructionCall CreateConstructionCall(Type type, string activationUrl, object[] activationAttributes) { ConstructionCall constructionCall = new ConstructionCall(type); if (!type.IsContextful) { constructionCall.Activator = new AppDomainLevelActivator(activationUrl, ActivationServices.ConstructionActivator); constructionCall.IsContextOk = false; return(constructionCall); } IActivator activator = ActivationServices.ConstructionActivator; activator = new ContextLevelActivator(activator); ArrayList arrayList = new ArrayList(); if (activationAttributes != null) { arrayList.AddRange(activationAttributes); } bool flag = activationUrl == ChannelServices.CrossContextUrl; Context currentContext = Thread.CurrentContext; if (flag) { foreach (object obj in arrayList) { IContextAttribute contextAttribute = (IContextAttribute)obj; if (!contextAttribute.IsContextOK(currentContext, constructionCall)) { flag = false; break; } } } object[] customAttributes = type.GetCustomAttributes(true); foreach (object obj2 in customAttributes) { if (obj2 is IContextAttribute) { flag = (flag && ((IContextAttribute)obj2).IsContextOK(currentContext, constructionCall)); arrayList.Add(obj2); } } if (!flag) { constructionCall.SetActivationAttributes(arrayList.ToArray()); foreach (object obj3 in arrayList) { IContextAttribute contextAttribute2 = (IContextAttribute)obj3; contextAttribute2.GetPropertiesForNewContext(constructionCall); } } if (activationUrl != ChannelServices.CrossContextUrl) { activator = new AppDomainLevelActivator(activationUrl, activator); } constructionCall.Activator = activator; constructionCall.IsContextOk = flag; return(constructionCall); }
public IConstructionReturnMessage Activate(IConstructionCallMessage ctorCall) { ServerIdentity identity = RemotingServices.CreateContextBoundObjectIdentity(ctorCall.ActivationType); RemotingServices.SetMessageTargetIdentity(ctorCall, identity); ConstructionCall call = ctorCall as ConstructionCall; if (call == null || !call.IsContextOk) { identity.Context = Context.CreateNewContext(ctorCall); Context oldContext = Context.SwitchToContext(identity.Context); try { return(m_NextActivator.Activate(ctorCall)); } finally { Context.SwitchToContext(oldContext); } } else { return(m_NextActivator.Activate(ctorCall)); } }
internal void AttachIdentity(Identity identity) { this._objectIdentity = identity; if (identity is ClientActivatedIdentity) { ClientActivatedIdentity clientActivatedIdentity = (ClientActivatedIdentity)identity; this._targetContext = clientActivatedIdentity.Context; base.AttachServer(clientActivatedIdentity.GetServerObject()); clientActivatedIdentity.SetClientProxy((MarshalByRefObject)this.GetTransparentProxy()); } if (identity is ClientIdentity) { ((ClientIdentity)identity).ClientProxy = (MarshalByRefObject)this.GetTransparentProxy(); this._targetUri = ((ClientIdentity)identity).TargetUri; } else { this._targetUri = identity.ObjectUri; } if (this._objectIdentity.EnvoySink != null) { this._sink = this._objectIdentity.EnvoySink; this._hasEnvoySink = true; } else { this._sink = this._objectIdentity.ChannelSink; } this._ctorCall = null; }
public static IMessage Activate(RemotingProxy proxy, ConstructionCall ctorCall) { IMessage response; ctorCall.SourceProxy = proxy; if (Thread.CurrentContext.HasExitSinks && !ctorCall.IsContextOk) { response = Thread.CurrentContext.GetClientContextSinkChain().SyncProcessMessage(ctorCall); } else { response = RemoteActivate(ctorCall); } if (response is IConstructionReturnMessage && ((IConstructionReturnMessage)response).Exception == null && proxy.ObjectIdentity == null) { #if !DISABLE_REMOTING Identity identity = RemotingServices.GetMessageTargetIdentity(ctorCall); proxy.AttachIdentity(identity); #endif } return(response); }
public static IMessage Activate(RemotingProxy proxy, ConstructionCall ctorCall) { ctorCall.SourceProxy = proxy; IMessage message; if (Thread.CurrentContext.HasExitSinks && !ctorCall.IsContextOk) { message = Thread.CurrentContext.GetClientContextSinkChain().SyncProcessMessage(ctorCall); } else { message = ActivationServices.RemoteActivate(ctorCall); } if (message is IConstructionReturnMessage && ((IConstructionReturnMessage)message).Exception == null && proxy.ObjectIdentity == null) { Identity messageTargetIdentity = RemotingServices.GetMessageTargetIdentity(ctorCall); proxy.AttachIdentity(messageTargetIdentity); } return(message); }
public static IMessage CreateInstanceFromMessage(IConstructionCallMessage ctorCall) { object obj = ActivationServices.AllocateUninitializedClassInstance(ctorCall.ActivationType); ServerIdentity serverIdentity = (ServerIdentity)RemotingServices.GetMessageTargetIdentity(ctorCall); serverIdentity.AttachServerObject((MarshalByRefObject)obj, Thread.CurrentContext); ConstructionCall constructionCall = ctorCall as ConstructionCall; if (ctorCall.ActivationType.IsContextful && constructionCall != null && constructionCall.SourceProxy != null) { constructionCall.SourceProxy.AttachIdentity(serverIdentity); MarshalByRefObject target = (MarshalByRefObject)constructionCall.SourceProxy.GetTransparentProxy(); RemotingServices.InternalExecuteMessage(target, ctorCall); } else { ctorCall.MethodBase.Invoke(obj, ctorCall.Args); } return(new ConstructionResponse(obj, null, ctorCall)); }
public static ConstructionCall CreateConstructionCall(Type type, string activationUrl, object[] activationAttributes) { ConstructionCall ctorCall = new ConstructionCall(type); if (!type.IsContextful) { // Must be a remote activated object ctorCall.Activator = new AppDomainLevelActivator(activationUrl, ConstructionActivator); ctorCall.IsContextOk = false; // It'll be activated in a remote context return(ctorCall); } // It is a CBO. Need collect context properties and // check if a new context is needed. IActivator activatorChain = ConstructionActivator; activatorChain = new ContextLevelActivator(activatorChain); ArrayList attributes = new ArrayList(); if (activationAttributes != null) { attributes.AddRange(activationAttributes); } bool isContextOk = (activationUrl == ChannelServices.CrossContextUrl); // Remote CBOs are always created in a new context Context currentContext = Threading.Thread.CurrentContext; if (isContextOk) { foreach (IContextAttribute attr in attributes) { if (!attr.IsContextOK(currentContext, ctorCall)) { isContextOk = false; break; } } } object[] typeAttributes = type.GetCustomAttributes(true); foreach (object attr in typeAttributes) { if (attr is IContextAttribute) { isContextOk = isContextOk && ((IContextAttribute)attr).IsContextOK(currentContext, ctorCall); attributes.Add(attr); } } if (!isContextOk) { // A new context is needed. Collect the context properties and chain // the context level activator. ctorCall.SetActivationAttributes(attributes.ToArray()); foreach (IContextAttribute attr in attributes) { attr.GetPropertiesForNewContext(ctorCall); } } if (activationUrl != ChannelServices.CrossContextUrl) { activatorChain = new AppDomainLevelActivator(activationUrl, activatorChain); } ctorCall.Activator = activatorChain; ctorCall.IsContextOk = isContextOk; return(ctorCall); }
/* this is called from unmanaged code */ internal static object PrivateInvoke(RealProxy rp, IMessage msg, out Exception exc, out object [] out_args) { MonoMethodMessage mMsg = (MonoMethodMessage)msg; mMsg.LogicalCallContext = CallContext.CreateLogicalCallContext(true); CallType call_type = mMsg.CallType; bool is_remproxy = (rp is RemotingProxy); out_args = null; IMethodReturnMessage res_msg = null; if (call_type == CallType.BeginInvoke) { // todo: set CallMessage in runtime instead mMsg.AsyncResult.CallMessage = mMsg; } if (call_type == CallType.EndInvoke) { res_msg = (IMethodReturnMessage)mMsg.AsyncResult.EndInvoke(); } // Check for constructor msg if (mMsg.MethodBase.IsConstructor) { if (is_remproxy) { res_msg = (IMethodReturnMessage)(rp as RemotingProxy).ActivateRemoteObject((IMethodMessage)msg); } else { msg = new ConstructionCall(rp.GetProxiedType()); } } if (null == res_msg) { bool failed = false; try { res_msg = (IMethodReturnMessage)rp.Invoke(msg); } catch (Exception ex) { failed = true; if (call_type == CallType.BeginInvoke) { // If async dispatch crashes, don't propagate the exception. // The exception will be raised when calling EndInvoke. mMsg.AsyncResult.SyncProcessMessage(new ReturnMessage(ex, msg as IMethodCallMessage)); res_msg = new ReturnMessage(null, null, 0, null, msg as IMethodCallMessage); } else { throw; } } // Note, from begining this code used AsyncResult.IsCompleted for // checking if it was a remoting or custom proxy, but in some // cases the remoting proxy finish before the call returns // causing this method to be called, therefore causing all kind of bugs. if ((!is_remproxy) && call_type == CallType.BeginInvoke && !failed) { IMessage asyncMsg = null; // allow calltype EndInvoke to finish asyncMsg = mMsg.AsyncResult.SyncProcessMessage(res_msg as IMessage); out_args = res_msg.OutArgs; res_msg = new ReturnMessage(asyncMsg, null, 0, null, res_msg as IMethodCallMessage); } } if (res_msg.LogicalCallContext != null && res_msg.LogicalCallContext.HasInfo) { CallContext.UpdateCurrentCallContext(res_msg.LogicalCallContext); } exc = res_msg.Exception; // todo: remove throw exception from the runtime invoke if (null != exc) { out_args = null; throw exc.FixRemotingException(); } else if (res_msg is IConstructionReturnMessage) { if (out_args == null) { out_args = res_msg.OutArgs; } } else if (mMsg.CallType == CallType.BeginInvoke) { // We don't have OutArgs in this case. } else if (mMsg.CallType == CallType.Sync) { out_args = ProcessResponse(res_msg, mMsg); } else if (mMsg.CallType == CallType.EndInvoke) { out_args = ProcessResponse(res_msg, mMsg.AsyncResult.CallMessage); } else { if (out_args == null) { out_args = res_msg.OutArgs; } } return(res_msg.ReturnValue); }
internal RemotingProxy(Type type, string activationUrl, object[] activationAttributes) : base(type) { _hasEnvoySink = false; _ctorCall = ActivationServices.CreateConstructionCall(type, activationUrl, activationAttributes); }
internal static object PrivateInvoke(RealProxy rp, IMessage msg, out Exception exc, out object[] out_args) { MonoMethodMessage monoMethodMessage = (MonoMethodMessage)msg; monoMethodMessage.LogicalCallContext = CallContext.CreateLogicalCallContext(true); CallType callType = monoMethodMessage.CallType; bool flag = rp is RemotingProxy; out_args = null; IMethodReturnMessage methodReturnMessage = null; if (callType == CallType.BeginInvoke) { monoMethodMessage.AsyncResult.CallMessage = monoMethodMessage; } if (callType == CallType.EndInvoke) { methodReturnMessage = (IMethodReturnMessage)monoMethodMessage.AsyncResult.EndInvoke(); } if (monoMethodMessage.MethodBase.IsConstructor) { if (flag) { methodReturnMessage = (IMethodReturnMessage)(rp as RemotingProxy).ActivateRemoteObject((IMethodMessage)msg); } else { msg = new ConstructionCall(rp.GetProxiedType()); } } if (methodReturnMessage == null) { bool flag2 = false; try { methodReturnMessage = (IMethodReturnMessage)rp.Invoke(msg); } catch (Exception e) { flag2 = true; if (callType != CallType.BeginInvoke) { throw; } monoMethodMessage.AsyncResult.SyncProcessMessage(new ReturnMessage(e, msg as IMethodCallMessage)); methodReturnMessage = new ReturnMessage(null, null, 0, null, msg as IMethodCallMessage); } if (!flag && callType == CallType.BeginInvoke && !flag2) { IMessage ret = monoMethodMessage.AsyncResult.SyncProcessMessage(methodReturnMessage); out_args = methodReturnMessage.OutArgs; methodReturnMessage = new ReturnMessage(ret, null, 0, null, methodReturnMessage as IMethodCallMessage); } } if (methodReturnMessage.LogicalCallContext != null && methodReturnMessage.LogicalCallContext.HasInfo) { CallContext.UpdateCurrentCallContext(methodReturnMessage.LogicalCallContext); } exc = methodReturnMessage.Exception; if (exc != null) { out_args = null; throw exc.FixRemotingException(); } if (methodReturnMessage is IConstructionReturnMessage) { if (out_args == null) { out_args = methodReturnMessage.OutArgs; } } else if (monoMethodMessage.CallType != CallType.BeginInvoke) { if (monoMethodMessage.CallType == CallType.Sync) { out_args = RealProxy.ProcessResponse(methodReturnMessage, monoMethodMessage); } else if (monoMethodMessage.CallType == CallType.EndInvoke) { out_args = RealProxy.ProcessResponse(methodReturnMessage, monoMethodMessage.AsyncResult.CallMessage); } else if (out_args == null) { out_args = methodReturnMessage.OutArgs; } } return(methodReturnMessage.ReturnValue); }