Exemple #1
0
        internal CADMethodReturnMessage(IMethodReturnMessage retMsg) : base(retMsg)
        {
            ArrayList serializeList = null;

            _propertyCount = MarshalProperties(retMsg.Properties, ref serializeList);

            _returnValue = MarshalArgument(retMsg.ReturnValue, ref serializeList);
            _args        = MarshalArguments(retMsg.Args, ref serializeList);

            _sig = GetSignature(method, true);

            if (null != retMsg.Exception)
            {
                if (null == serializeList)
                {
                    serializeList = new ArrayList();
                }

                _exception = new CADArgHolder(serializeList.Count);
                serializeList.Add(retMsg.Exception);
            }

            // Save callcontext
            SaveLogicalCallContext(retMsg, ref serializeList);

            if (null != serializeList)
            {
                MemoryStream stm = CADSerializer.SerializeObject(serializeList.ToArray());
                _serializedArgs = stm.GetBuffer();
            }
        }
Exemple #2
0
        internal void ProcessMessageInDomain(byte[] arrRequest, CADMethodCallMessage cadMsg,
                                             out byte[] arrResponse, out CADMethodReturnMessage cadMrm)
        {
            IMessage reqDomMsg;

            if (null != arrRequest)
            {
                reqDomMsg = CADSerializer.DeserializeMessage(new MemoryStream(arrRequest), null);
            }
            else
            {
                reqDomMsg = new MethodCall(cadMsg);
            }

            IMessage retDomMsg = ChannelServices.SyncDispatchMessage(reqDomMsg);

            cadMrm = CADMethodReturnMessage.Create(retDomMsg);
            if (null == cadMrm)
            {
                arrResponse = CADSerializer.SerializeMessage(retDomMsg).GetBuffer();
            }
            else
            {
                arrResponse = null;
            }
        }
Exemple #3
0
        internal ObjRef DeserializeInTheCurrentDomain(int domainId, byte[] tInfo)
        {
            string            local_uri = string.Copy(this.uri);
            ChannelInfo       cinfo     = new ChannelInfo(new CrossAppDomainData(domainId));
            ObjRef            res       = new ObjRef(local_uri, cinfo);
            IRemotingTypeInfo typeInfo  = (IRemotingTypeInfo)CADSerializer.DeserializeObjectSafe(tInfo);

            res.typeInfo = typeInfo;
            return(res);
        }
        internal ArrayList GetArguments()
        {
            ArrayList result = null;

            if (this._serializedArgs != null)
            {
                object[] c = (object[])CADSerializer.DeserializeObject(new MemoryStream(this._serializedArgs));
                result = new ArrayList(c);
                this._serializedArgs = null;
            }
            return(result);
        }
Exemple #5
0
        internal byte[] SerializeType()
        {
            // FIXME: Assert self and typeinfo in same domain
            if (typeInfo == null)
            {
                throw new Exception("Attempt to serialize a null TypeInfo.");
            }

            MemoryStream stm = CADSerializer.SerializeObject(typeInfo);

            return(stm.GetBuffer());
        }
Exemple #6
0
        internal ArrayList GetArguments()
        {
            ArrayList ret = null;

            if (null != _serializedArgs)
            {
                object[] oret = (object[])CADSerializer.DeserializeObject(new MemoryStream(_serializedArgs));
                ret             = new ArrayList(oret);
                _serializedArgs = null;
            }

            return(ret);
        }
Exemple #7
0
        internal CADMethodCallMessage(IMethodCallMessage callMsg)
        {
            this._uri         = callMsg.Uri;
            this.MethodHandle = callMsg.MethodBase.MethodHandle;
            this.FullTypeName = callMsg.MethodBase.DeclaringType.AssemblyQualifiedName;
            ArrayList arrayList = null;

            this._propertyCount = CADMessageBase.MarshalProperties(callMsg.Properties, ref arrayList);
            this._args          = base.MarshalArguments(callMsg.Args, ref arrayList);
            base.SaveLogicalCallContext(callMsg, ref arrayList);
            if (arrayList != null)
            {
                MemoryStream memoryStream = CADSerializer.SerializeObject(arrayList.ToArray());
                this._serializedArgs = memoryStream.GetBuffer();
            }
        }
Exemple #8
0
        internal ArrayList GetArguments()
        {
            ArrayList ret = null;

            if (null != _serializedArgs)
            {
                // Avoid cross domain refs between MemoryStream and _serializedArgs byte array
                byte[] copyArray = new byte [_serializedArgs.Length];
                Array.Copy(_serializedArgs, copyArray, _serializedArgs.Length);

                object[] oret = (object[])CADSerializer.DeserializeObject(new MemoryStream(copyArray));
                ret             = new ArrayList(oret);
                _serializedArgs = null;
            }

            return(ret);
        }
Exemple #9
0
        internal static object GetDomainProxy(AppDomain domain)
        {
            byte[] data = null;

            Context currentContext = Thread.CurrentContext;

            try
            {
                data = (byte[])AppDomain.InvokeInDomain(domain, typeof(AppDomain).GetMethod("GetMarshalledDomainObjRef", BindingFlags.Instance | BindingFlags.NonPublic), domain, null);
            }
            finally
            {
                AppDomain.InternalSetContext(currentContext);
            }

            MemoryStream stream = new MemoryStream(data);
            ObjRef       appref = (ObjRef)CADSerializer.DeserializeObject(stream);

            return((AppDomain)RemotingServices.Unmarshal(appref));
        }
Exemple #10
0
        internal CADMethodCallMessage(IMethodCallMessage callMsg) : base(callMsg)
        {
            _uri = callMsg.Uri;

            ArrayList serializeList = null;

            _propertyCount = MarshalProperties(callMsg.Properties, ref serializeList);

            _args = MarshalArguments(callMsg.Args, ref serializeList);

            // Save callcontext
            SaveLogicalCallContext(callMsg, ref serializeList);

            // Serialize message data if needed

            if (null != serializeList)
            {
                MemoryStream stm = CADSerializer.SerializeObject(serializeList.ToArray());
                _serializedArgs = stm.GetBuffer();
            }
        }
        internal CADMethodReturnMessage(IMethodReturnMessage retMsg)
        {
            ArrayList arrayList = null;

            this._propertyCount = CADMessageBase.MarshalProperties(retMsg.Properties, ref arrayList);
            this._returnValue   = base.MarshalArgument(retMsg.ReturnValue, ref arrayList);
            this._args          = base.MarshalArguments(retMsg.Args, ref arrayList);
            if (retMsg.Exception != null)
            {
                if (arrayList == null)
                {
                    arrayList = new ArrayList();
                }
                this._exception = new CADArgHolder(arrayList.Count);
                arrayList.Add(retMsg.Exception);
            }
            base.SaveLogicalCallContext(retMsg, ref arrayList);
            if (arrayList != null)
            {
                MemoryStream memoryStream = CADSerializer.SerializeObject(arrayList.ToArray());
                this._serializedArgs = memoryStream.GetBuffer();
            }
        }
        internal CADMethodCallMessage(IMethodCallMessage callMsg)
        {
            _uri         = callMsg.Uri;
            MethodHandle = callMsg.MethodBase.MethodHandle;
            FullTypeName = callMsg.MethodBase.DeclaringType.AssemblyQualifiedName;

            ArrayList serializeList = null;

            _propertyCount = MarshalProperties(callMsg.Properties, ref serializeList);

            _args = MarshalArguments(callMsg.Args, ref serializeList);

            // Save callcontext
            SaveLogicalCallContext(callMsg, ref serializeList);

            // Serialize message data if needed

            if (null != serializeList)
            {
                MemoryStream stm = CADSerializer.SerializeObject(serializeList.ToArray());
                _serializedArgs = stm.GetBuffer();
            }
        }
Exemple #13
0
        public CADMessageBase(IMethodMessage msg)
        {
            CADMethodRef methodRef = new CADMethodRef(msg);

            serializedMethod = CADSerializer.SerializeObject(methodRef).GetBuffer();
        }
Exemple #14
0
        internal MethodBase GetMethod()
        {
            CADMethodRef methRef = (CADMethodRef)CADSerializer.DeserializeObjectSafe(serializedMethod);

            MethodBase _method;

            Type tt = Type.GetType(methRef.FullTypeName, true);

            if (tt.IsGenericType || tt.IsGenericTypeDefinition)
            {
                _method = MethodBase.GetMethodFromHandleNoGenericCheck(methRef.MethodHandle);
            }
            else
            {
                _method = MethodBase.GetMethodFromHandle(methRef.MethodHandle);
            }

            if (tt != _method.DeclaringType)
            {
                // The target domain has loaded the type from a different assembly.
                // We need to locate the correct type and get the method from it
                Type [] signature = GetSignature(_method, true);
                if (_method.IsGenericMethod)
                {
                    MethodBase [] methods   = tt.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                    Type []       base_args = _method.GetGenericArguments();
                    foreach (MethodBase method in methods)
                    {
                        if (!method.IsGenericMethod || method.Name != _method.Name)
                        {
                            continue;
                        }
                        Type [] method_args = method.GetGenericArguments();
                        if (base_args.Length != method_args.Length)
                        {
                            continue;
                        }

                        MethodInfo method_instance = ((MethodInfo)method).MakeGenericMethod(base_args);
                        Type []    base_sig        = GetSignature(method_instance, false);
                        if (base_sig.Length != signature.Length)
                        {
                            continue;
                        }
                        bool dont = false;
                        for (int i = base_sig.Length - 1; i >= 0; i--)
                        {
                            if (base_sig [i] != signature [i])
                            {
                                dont = true;
                                break;
                            }
                        }
                        if (dont)
                        {
                            continue;
                        }
                        return(method_instance);
                    }
                    return(_method);
                }

                MethodBase mb = tt.GetMethod(_method.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, signature, null);
                if (mb == null)
                {
                    throw new RemotingException("Method '" + _method.Name + "' not found in type '" + tt + "'");
                }
                return(mb);
            }
            return(_method);
        }
        internal MethodBase GetMethod()
        {
            CADMethodRef methRef = (CADMethodRef)CADSerializer.DeserializeObjectSafe(serializedMethod);

            return(methRef.Resolve());
        }
Exemple #16
0
        internal byte[] GetMarshalledDomainObjRef()
        {
            ObjRef oref = RemotingServices.Marshal(AppDomain.CurrentDomain, null, typeof(AppDomain));

            return(CADSerializer.SerializeObject(oref).GetBuffer());
        }