You've already forked linux-packaging-mono
Imported Upstream version 4.2.0.179
Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
committed by
Jo Shields
parent
aa7da660d6
commit
c042cd0c52
@ -39,7 +39,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
[System.Runtime.InteropServices.ComVisible (true)]
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
public class AsyncResult : IAsyncResult, IMessageSink {
|
||||
public class AsyncResult : IAsyncResult, IMessageSink, IThreadPoolWorkItem {
|
||||
|
||||
#pragma warning disable 169, 414, 649
|
||||
object async_state;
|
||||
@ -62,6 +62,7 @@ public class AsyncResult : IAsyncResult, IMessageSink {
|
||||
IMessageCtrl message_ctrl;
|
||||
#pragma warning restore
|
||||
IMessage reply_message;
|
||||
WaitCallback orig_cb;
|
||||
|
||||
internal AsyncResult ()
|
||||
{
|
||||
@ -69,10 +70,28 @@ public class AsyncResult : IAsyncResult, IMessageSink {
|
||||
|
||||
internal AsyncResult (WaitCallback cb, object state, bool capture_context)
|
||||
{
|
||||
orig_cb = cb;
|
||||
if (capture_context) {
|
||||
var stackMark = default (StackCrawlMark);
|
||||
current = ExecutionContext.Capture (
|
||||
ref stackMark,
|
||||
ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
|
||||
cb = delegate {
|
||||
ExecutionContext.Run(current, ccb, this, true);
|
||||
};
|
||||
}
|
||||
|
||||
async_state = state;
|
||||
async_delegate = cb;
|
||||
if (capture_context)
|
||||
current = ExecutionContext.Capture ();
|
||||
}
|
||||
|
||||
static internal ContextCallback ccb = new ContextCallback(WaitCallback_Context);
|
||||
|
||||
static private void WaitCallback_Context(Object state)
|
||||
{
|
||||
AsyncResult obj = (AsyncResult)state;
|
||||
WaitCallback wc = obj.orig_cb as WaitCallback;
|
||||
wc(obj.async_state);
|
||||
}
|
||||
|
||||
public virtual object AsyncState
|
||||
@ -185,5 +204,17 @@ public class AsyncResult : IAsyncResult, IMessageSink {
|
||||
get { return call_message; }
|
||||
set { call_message = value; }
|
||||
}
|
||||
|
||||
void IThreadPoolWorkItem.ExecuteWorkItem()
|
||||
{
|
||||
Invoke ();
|
||||
}
|
||||
|
||||
void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae)
|
||||
{
|
||||
}
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern object Invoke ();
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +51,16 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
}
|
||||
|
||||
internal class CADObjRef {
|
||||
ObjRef objref;
|
||||
public int SourceDomain;
|
||||
internal ObjRef objref;
|
||||
internal int SourceDomain;
|
||||
internal byte[] TypeInfo;
|
||||
|
||||
public CADObjRef (ObjRef o, int sourceDomain) {
|
||||
objref = o;
|
||||
TypeInfo = o.SerializeType ();
|
||||
SourceDomain = sourceDomain;
|
||||
}
|
||||
|
||||
|
||||
public string TypeName {
|
||||
get { return objref.TypeInfo.TypeName; }
|
||||
}
|
||||
@ -68,22 +70,119 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class CADMethodRef
|
||||
{
|
||||
internal string FullTypeName;
|
||||
internal IntPtr MethodHandlePtr;
|
||||
|
||||
public RuntimeMethodHandle MethodHandle {
|
||||
get {
|
||||
return new RuntimeMethodHandle (MethodHandlePtr);
|
||||
}
|
||||
}
|
||||
|
||||
public CADMethodRef (IMethodMessage msg)
|
||||
{
|
||||
MethodHandlePtr = msg.MethodBase.MethodHandle.Value;
|
||||
FullTypeName = msg.MethodBase.DeclaringType.AssemblyQualifiedName;
|
||||
}
|
||||
}
|
||||
|
||||
internal class CADMessageBase {
|
||||
|
||||
protected object [] _args;
|
||||
protected byte [] _serializedArgs = null;
|
||||
protected int _propertyCount = 0;
|
||||
protected CADArgHolder _callContext;
|
||||
|
||||
internal byte[] serializedMethod;
|
||||
|
||||
public CADMessageBase (IMethodMessage msg) {
|
||||
CADMethodRef methodRef = new CADMethodRef (msg);
|
||||
serializedMethod = CADSerializer.SerializeObject (methodRef).GetBuffer ();
|
||||
}
|
||||
|
||||
internal MethodBase method {
|
||||
get { return GetMethod (); }
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static protected Type [] GetSignature (MethodBase methodBase, bool load)
|
||||
{
|
||||
ParameterInfo[] pars = methodBase.GetParameters ();
|
||||
Type[] signature = new Type [pars.Length];
|
||||
for (int n=0; n<pars.Length; n++) {
|
||||
// The parameter types may also be loaded from a different assembly, so we need
|
||||
// to load them again
|
||||
if (load)
|
||||
signature [n] = Type.GetType (pars [n].ParameterType.AssemblyQualifiedName, true);
|
||||
else
|
||||
signature [n] = pars [n].ParameterType;
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
// Helper to marshal properties
|
||||
internal static int MarshalProperties (IDictionary dict, ref ArrayList args) {
|
||||
IDictionary serDict = dict;
|
||||
int count = 0;
|
||||
|
||||
MethodDictionary msgDict = dict as MethodDictionary;
|
||||
MessageDictionary msgDict = dict as MessageDictionary;
|
||||
if (null != msgDict) {
|
||||
if (msgDict.HasInternalProperties) {
|
||||
serDict = msgDict.InternalProperties;
|
||||
if (msgDict.HasUserData ()) {
|
||||
serDict = msgDict.InternalDictionary;
|
||||
if (null != serDict) {
|
||||
foreach (DictionaryEntry e in serDict) {
|
||||
if (null == args)
|
||||
@ -171,12 +270,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
CADObjRef objref = arg as CADObjRef;
|
||||
if (null != objref) {
|
||||
string typeName = string.Copy (objref.TypeName);
|
||||
string uri = string.Copy (objref.URI);
|
||||
int domid = objref.SourceDomain;
|
||||
|
||||
ChannelInfo cinfo = new ChannelInfo (new CrossAppDomainData (domid));
|
||||
ObjRef localRef = new ObjRef (typeName, uri, cinfo);
|
||||
ObjRef localRef = objref.objref.DeserializeInTheCurrentDomain (objref.SourceDomain, objref.TypeInfo);
|
||||
return RemotingServices.Unmarshal (localRef);
|
||||
}
|
||||
|
||||
@ -255,7 +349,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
return unmarshalledArgs;
|
||||
}
|
||||
|
||||
|
||||
protected void SaveLogicalCallContext (IMethodMessage msg, ref ArrayList serializeList)
|
||||
{
|
||||
if (msg.LogicalCallContext != null && msg.LogicalCallContext.HasInfo)
|
||||
@ -280,10 +374,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
// Used when passing a IMethodCallMessage between appdomains
|
||||
internal class CADMethodCallMessage : CADMessageBase {
|
||||
string _uri;
|
||||
|
||||
internal RuntimeMethodHandle MethodHandle;
|
||||
internal string FullTypeName;
|
||||
|
||||
|
||||
internal string Uri {
|
||||
get {
|
||||
return _uri;
|
||||
@ -298,10 +389,8 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
return new CADMethodCallMessage (msg);
|
||||
}
|
||||
|
||||
internal CADMethodCallMessage (IMethodCallMessage callMsg) {
|
||||
internal CADMethodCallMessage (IMethodCallMessage callMsg): base (callMsg) {
|
||||
_uri = callMsg.Uri;
|
||||
MethodHandle = callMsg.MethodBase.MethodHandle;
|
||||
FullTypeName = callMsg.MethodBase.DeclaringType.AssemblyQualifiedName;
|
||||
|
||||
ArrayList serializeList = null;
|
||||
|
||||
@ -342,77 +431,13 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
}
|
||||
}
|
||||
|
||||
static Type [] GetSignature (MethodBase methodBase, bool load)
|
||||
{
|
||||
ParameterInfo[] pars = methodBase.GetParameters ();
|
||||
Type[] signature = new Type [pars.Length];
|
||||
for (int n=0; n<pars.Length; n++) {
|
||||
// The parameter types may also be loaded from a different assembly, so we need
|
||||
// to load them again
|
||||
if (load)
|
||||
signature [n] = Type.GetType (pars [n].ParameterType.AssemblyQualifiedName, true);
|
||||
else
|
||||
signature [n] = pars [n].ParameterType;
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
|
||||
internal MethodBase GetMethod ()
|
||||
{
|
||||
MethodBase methodBase = null;
|
||||
Type tt = Type.GetType (FullTypeName, true);
|
||||
if (tt.IsGenericType || tt.IsGenericTypeDefinition) {
|
||||
methodBase = MethodBase.GetMethodFromHandleNoGenericCheck (MethodHandle);
|
||||
} else {
|
||||
methodBase = MethodBase.GetMethodFromHandle (MethodHandle);
|
||||
}
|
||||
|
||||
if (tt != methodBase.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 (methodBase, true);
|
||||
if (methodBase.IsGenericMethod) {
|
||||
MethodBase [] methods = tt.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);
|
||||
Type [] base_args = methodBase.GetGenericArguments ();
|
||||
foreach (MethodBase method in methods) {
|
||||
if (!method.IsGenericMethod || method.Name != methodBase.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 methodBase;
|
||||
}
|
||||
|
||||
MethodBase mb = tt.GetMethod (methodBase.Name, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, signature, null);
|
||||
if (mb == null)
|
||||
throw new RemotingException ("Method '" + methodBase.Name + "' not found in type '" + tt + "'");
|
||||
return mb;
|
||||
}
|
||||
return methodBase;
|
||||
}
|
||||
}
|
||||
|
||||
// Used when passing a IMethodReturnMessage between appdomains
|
||||
internal class CADMethodReturnMessage : CADMessageBase {
|
||||
object _returnValue;
|
||||
CADArgHolder _exception = null;
|
||||
Type [] _sig;
|
||||
|
||||
static internal CADMethodReturnMessage Create (IMessage callMsg) {
|
||||
IMethodReturnMessage msg = callMsg as IMethodReturnMessage;
|
||||
@ -422,7 +447,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
return new CADMethodReturnMessage (msg);
|
||||
}
|
||||
|
||||
internal CADMethodReturnMessage(IMethodReturnMessage retMsg) {
|
||||
internal CADMethodReturnMessage(IMethodReturnMessage retMsg): base (retMsg) {
|
||||
ArrayList serializeList = null;
|
||||
|
||||
_propertyCount = MarshalProperties (retMsg.Properties, ref serializeList);
|
||||
@ -430,6 +455,8 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
_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();
|
||||
@ -462,7 +489,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
internal object [] GetArgs (ArrayList args) {
|
||||
return UnmarshalArguments (_args, args);
|
||||
}
|
||||
|
||||
|
||||
internal object GetReturnValue (ArrayList args) {
|
||||
return UnmarshalArgument (_returnValue, args);
|
||||
}
|
||||
|
@ -1,156 +0,0 @@
|
||||
//
|
||||
// System.Runtime.Remoting.Messaging.CallContext.cs
|
||||
//
|
||||
// Authors: Jaime Anguiano Olarra (jaime@gnome.org)
|
||||
// Lluis Sanchez Gual (lluis@ximian.com)
|
||||
// Marek Safar (marek.safar@gmail.com)
|
||||
//
|
||||
// (c) 2002, Jaime Anguiano Olarra
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
[Serializable]
|
||||
[System.Runtime.InteropServices.ComVisible (true)]
|
||||
public sealed class CallContext
|
||||
{
|
||||
[ThreadStatic] static Header [] Headers;
|
||||
[ThreadStatic] static object hostContext;
|
||||
|
||||
private CallContext ()
|
||||
{
|
||||
}
|
||||
|
||||
public static object HostContext {
|
||||
get { return hostContext; }
|
||||
set { hostContext = value; }
|
||||
}
|
||||
|
||||
public static void FreeNamedDataSlot (string name)
|
||||
{
|
||||
ExecutionContext.FreeNamedDataSlot (name);
|
||||
}
|
||||
|
||||
public static object GetData (string name)
|
||||
{
|
||||
var value = LogicalGetData (name);
|
||||
if (value == null)
|
||||
Datastore.TryGetValue (name, out value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void SetData (string name, object data)
|
||||
{
|
||||
if (data is ILogicalThreadAffinative) {
|
||||
LogicalSetData (name, data);
|
||||
} else {
|
||||
var ec = ExecutionContext.GetCurrentWritable ();
|
||||
ec.LogicalCallContext.FreeNamedDataSlot (name);
|
||||
ec.DataStore [name] = data;
|
||||
}
|
||||
}
|
||||
|
||||
public static object LogicalGetData (string name)
|
||||
{
|
||||
return LogicalContext.GetData (name);
|
||||
}
|
||||
|
||||
public static void LogicalSetData (string name, object data)
|
||||
{
|
||||
var ec = ExecutionContext.GetCurrentWritable ();
|
||||
ec.DataStore.Remove (name);
|
||||
ec.LogicalCallContext.SetData (name, data);
|
||||
}
|
||||
|
||||
public static Header[] GetHeaders ()
|
||||
{
|
||||
return Headers;
|
||||
}
|
||||
|
||||
public static void SetHeaders (Header[] headers)
|
||||
{
|
||||
Headers = headers;
|
||||
}
|
||||
|
||||
internal static object SetCurrentCallContext (LogicalCallContext ctx)
|
||||
{
|
||||
object oldData = new object[] { Datastore, LogicalContext.Datastore };
|
||||
|
||||
Hashtable logicalDatastore;
|
||||
if (ctx != null && ctx.HasInfo)
|
||||
logicalDatastore = (Hashtable) ctx.Datastore.Clone ();
|
||||
else
|
||||
logicalDatastore = null;
|
||||
|
||||
LogicalContext.Datastore = logicalDatastore;
|
||||
return oldData;
|
||||
}
|
||||
|
||||
internal static void UpdateCurrentLogicalCallContext (LogicalCallContext ctx)
|
||||
{
|
||||
Hashtable data = ctx.Datastore;
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
foreach (DictionaryEntry entry in data)
|
||||
LogicalSetData ((string)entry.Key, entry.Value);
|
||||
}
|
||||
|
||||
internal static void RestoreCallContext (object oldContext)
|
||||
{
|
||||
object[] contextArray = (object[])oldContext;
|
||||
ExecutionContext.DataStore = (Dictionary<string, object>)contextArray [0];
|
||||
LogicalContext.Datastore = (Hashtable)contextArray [1];
|
||||
}
|
||||
|
||||
static Dictionary<string, object> Datastore {
|
||||
get {
|
||||
return ExecutionContext.DataStore;
|
||||
}
|
||||
}
|
||||
|
||||
static LogicalCallContext LogicalContext {
|
||||
get {
|
||||
return ExecutionContext.LogicalCallContext;
|
||||
}
|
||||
}
|
||||
|
||||
static ExecutionContext ExecutionContext {
|
||||
get {
|
||||
return ExecutionContext.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.ComVisible (true)]
|
||||
public interface ILogicalThreadAffinative
|
||||
{
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ using System.Runtime.Remoting.Activation;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
class ConstructionCallDictionary : MethodDictionary
|
||||
class ConstructionCallDictionary : MessageDictionary
|
||||
{
|
||||
public static string[] InternalKeys = new string[] {"__Uri", "__MethodName", "__TypeName", "__MethodSignature", "__Args", "__CallContext", "__CallSiteActivationAttributes", "__ActivationType", "__ContextProperties", "__Activator", "__ActivationTypeName"};
|
||||
|
||||
|
@ -21,14 +21,15 @@
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
using System;
|
||||
using System.Runtime.Remoting;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
internal interface IInternalMessage
|
||||
{
|
||||
Identity TargetIdentity { get; set; }
|
||||
string Uri { get; set; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.Remoting;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
internal interface IInternalMessage
|
||||
{
|
||||
Identity TargetIdentity { get; set; }
|
||||
string Uri { get; set; }
|
||||
bool HasProperties();
|
||||
}
|
||||
}
|
||||
|
@ -1,129 +0,0 @@
|
||||
//
|
||||
// System.Runtime.Remoting.Messaging.LogicalCallContext.cs
|
||||
//
|
||||
// Authors:
|
||||
// Dan Lewis (dihlewis@yahoo.co.uk)
|
||||
// Lluis Sanchez Gual (lluis@ximian.com)
|
||||
// Marek Safar (marek.safar@gmail.com)
|
||||
//
|
||||
// 2002 (C) Copyright. Ximian, Inc.
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
// Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
[Serializable]
|
||||
[System.Runtime.InteropServices.ComVisible (true)]
|
||||
public sealed class LogicalCallContext : ISerializable, ICloneable
|
||||
{
|
||||
Hashtable _data;
|
||||
CallContextRemotingData _remotingData = new CallContextRemotingData();
|
||||
|
||||
internal LogicalCallContext ()
|
||||
{
|
||||
}
|
||||
|
||||
internal LogicalCallContext (SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
foreach (SerializationEntry entry in info)
|
||||
{
|
||||
if (entry.Name == "__RemotingData")
|
||||
_remotingData = (CallContextRemotingData) entry.Value;
|
||||
else
|
||||
SetData (entry.Name, entry.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasInfo {
|
||||
get {
|
||||
return _data != null && _data.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void FreeNamedDataSlot (string name)
|
||||
{
|
||||
if (_data != null)
|
||||
_data.Remove (name);
|
||||
}
|
||||
|
||||
public object GetData (string name)
|
||||
{
|
||||
return _data != null ? _data [name] : null;
|
||||
}
|
||||
|
||||
public void GetObjectData (SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue ("__RemotingData", _remotingData);
|
||||
if (_data != null)
|
||||
{
|
||||
foreach (DictionaryEntry de in _data)
|
||||
info.AddValue ((string)de.Key, de.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetData (string name, object data)
|
||||
{
|
||||
if (_data == null)
|
||||
_data = new Hashtable ();
|
||||
_data [name] = data;
|
||||
}
|
||||
|
||||
public object Clone ()
|
||||
{
|
||||
LogicalCallContext nc = new LogicalCallContext ();
|
||||
nc._remotingData = (CallContextRemotingData) _remotingData.Clone ();
|
||||
if (_data != null)
|
||||
nc._data = (Hashtable) _data.Clone ();
|
||||
|
||||
return nc;
|
||||
}
|
||||
|
||||
internal Hashtable Datastore {
|
||||
get { return _data; }
|
||||
set { _data = value; }
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class CallContextRemotingData : ICloneable
|
||||
{
|
||||
string _logicalCallID;
|
||||
|
||||
public string LogicalCallID
|
||||
{
|
||||
get { return _logicalCallID; }
|
||||
set { _logicalCallID = value; }
|
||||
}
|
||||
|
||||
public object Clone ()
|
||||
{
|
||||
CallContextRemotingData data = new CallContextRemotingData ();
|
||||
data._logicalCallID = _logicalCallID;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
@ -117,7 +118,41 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
Init();
|
||||
ResolveMethod();
|
||||
}
|
||||
#if FEATURE_REMOTING
|
||||
internal MethodCall (Object handlerObject, BinaryMethodCallMessage smuggledMsg)
|
||||
{
|
||||
if (handlerObject != null)
|
||||
{
|
||||
_uri = handlerObject as String;
|
||||
if (_uri == null)
|
||||
{
|
||||
// This must be the tranparent proxy
|
||||
MarshalByRefObject mbr = handlerObject as MarshalByRefObject;
|
||||
if (mbr != null)
|
||||
{
|
||||
throw new NotImplementedException ("MarshalByRefObject.GetIdentity");
|
||||
/*
|
||||
bool fServer;
|
||||
srvID = MarshalByRefObject.GetIdentity(mbr, out fServer) as ServerIdentity;
|
||||
uri = srvID.URI;
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_typeName = smuggledMsg.TypeName;
|
||||
_methodName = smuggledMsg.MethodName;
|
||||
_methodSignature = (Type[])smuggledMsg.MethodSignature;
|
||||
_args = smuggledMsg.Args;
|
||||
_genericArguments = smuggledMsg.InstantiationArgs;
|
||||
_callContext = smuggledMsg.LogicalCallContext;
|
||||
|
||||
ResolveMethod();
|
||||
|
||||
if (smuggledMsg.HasProperties)
|
||||
smuggledMsg.PopulateMessageProperties(Properties);
|
||||
}
|
||||
#endif
|
||||
internal MethodCall ()
|
||||
{
|
||||
}
|
||||
@ -244,7 +279,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
internal virtual void InitDictionary()
|
||||
{
|
||||
MethodCallDictionary props = new MethodCallDictionary (this);
|
||||
var props = new MCMDictionary (this);
|
||||
ExternalProperties = props;
|
||||
InternalProperties = props.GetInternalProperties();
|
||||
}
|
||||
@ -386,6 +421,11 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
set { _targetIdentity = value; }
|
||||
}
|
||||
|
||||
bool IInternalMessage.HasProperties()
|
||||
{
|
||||
return (ExternalProperties != null) || (InternalProperties != null);
|
||||
}
|
||||
|
||||
Type[] GenericArguments {
|
||||
get {
|
||||
if (_genericArguments != null)
|
||||
|
@ -4,7 +4,7 @@
|
||||
// Author: Lluis Sanchez Gual (lluis@ideary.com)
|
||||
//
|
||||
// 2003 (C) Lluis Sanchez Gual
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
|
||||
@ -28,18 +28,18 @@
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
internal class MethodCallDictionary : MethodDictionary
|
||||
{
|
||||
public static string[] InternalKeys = new string[] {"__Uri", "__MethodName", "__TypeName", "__MethodSignature", "__Args", "__CallContext"};
|
||||
|
||||
public MethodCallDictionary(IMethodMessage message) : base (message)
|
||||
{
|
||||
MethodKeys = InternalKeys;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
internal class MCMDictionary : MessageDictionary
|
||||
{
|
||||
public static string[] InternalKeys = new string[] {"__Uri", "__MethodName", "__TypeName", "__MethodSignature", "__Args", "__CallContext"};
|
||||
|
||||
public MCMDictionary(IMethodMessage message) : base (message)
|
||||
{
|
||||
MethodKeys = InternalKeys;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
return _inArgInfo.GetInOutArgName(index);
|
||||
}
|
||||
|
||||
class DictionaryWrapper : MethodCallDictionary
|
||||
class DictionaryWrapper : MCMDictionary
|
||||
{
|
||||
IDictionary _wrappedDictionary;
|
||||
static string[] _keys = new string[] {"__Args"};
|
||||
|
@ -35,42 +35,39 @@ using System.Collections;
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
[Serializable]
|
||||
internal class MethodDictionary : IDictionary
|
||||
internal class MessageDictionary : IDictionary
|
||||
{
|
||||
IDictionary _internalProperties = null;
|
||||
protected IMethodMessage _message;
|
||||
string[] _methodKeys;
|
||||
bool _ownProperties = false;
|
||||
|
||||
public MethodDictionary (IMethodMessage message)
|
||||
public MessageDictionary (IMethodMessage message)
|
||||
{
|
||||
_message = message;
|
||||
}
|
||||
|
||||
internal bool HasInternalProperties
|
||||
internal bool HasUserData ()
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != _internalProperties)
|
||||
{
|
||||
// MethodCallMessageWrapper uses a nested MethodDictionary
|
||||
if (_internalProperties is MethodDictionary)
|
||||
return ((MethodDictionary)_internalProperties).HasInternalProperties;
|
||||
// MethodCallMessageWrapper uses a nested MessageDictionary
|
||||
if (_internalProperties is MessageDictionary)
|
||||
return ((MessageDictionary)_internalProperties).HasUserData ();
|
||||
else
|
||||
return _internalProperties.Count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal IDictionary InternalProperties
|
||||
internal IDictionary InternalDictionary
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null != _internalProperties)
|
||||
{
|
||||
if (_internalProperties is MethodDictionary)
|
||||
return ((MethodDictionary)_internalProperties).InternalProperties;
|
||||
if (_internalProperties is MessageDictionary)
|
||||
return ((MessageDictionary)_internalProperties).InternalDictionary;
|
||||
}
|
||||
return _internalProperties;
|
||||
}
|
||||
@ -106,7 +103,7 @@ namespace System.Runtime.Remoting.Messaging
|
||||
return false;
|
||||
}
|
||||
|
||||
public MethodDictionary(string[] keys)
|
||||
public MessageDictionary(string[] keys)
|
||||
{
|
||||
_methodKeys = keys;
|
||||
}
|
||||
@ -165,10 +162,10 @@ namespace System.Runtime.Remoting.Messaging
|
||||
case "__OutArgs":
|
||||
case "__Return": return;
|
||||
|
||||
case "__MethodName" :
|
||||
case "__TypeName" :
|
||||
case "__MethodSignature" :
|
||||
case "__Args" : throw new ArgumentException ("key was invalid");
|
||||
case "__MethodName" :
|
||||
case "__TypeName" :
|
||||
case "__MethodSignature" :
|
||||
case "__Args" : return; //throw new ArgumentException ("key was invalid " + key);
|
||||
case "__Uri": ((IInternalMessage)_message).Uri = (string) value; return;
|
||||
}
|
||||
}
|
||||
@ -284,11 +281,11 @@ namespace System.Runtime.Remoting.Messaging
|
||||
|
||||
class DictionaryEnumerator : IDictionaryEnumerator
|
||||
{
|
||||
MethodDictionary _methodDictionary;
|
||||
MessageDictionary _methodDictionary;
|
||||
IDictionaryEnumerator _hashtableEnum;
|
||||
int _posMethod;
|
||||
|
||||
public DictionaryEnumerator (MethodDictionary methodDictionary)
|
||||
public DictionaryEnumerator (MessageDictionary methodDictionary)
|
||||
{
|
||||
_methodDictionary = methodDictionary;
|
||||
_hashtableEnum = (_methodDictionary._internalProperties != null) ? _methodDictionary._internalProperties.GetEnumerator() : null;
|
||||
@ -297,7 +294,7 @@ namespace System.Runtime.Remoting.Messaging
|
||||
|
||||
public object Current
|
||||
{
|
||||
get {return Entry.Value; }
|
||||
get {return Entry; }
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
|
@ -35,6 +35,7 @@ using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
@ -124,7 +125,37 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
if (retmsg.PropertiesCount > 0)
|
||||
CADMessageBase.UnmarshalProperties (Properties, retmsg.PropertiesCount, args);
|
||||
}
|
||||
#if FEATURE_REMOTING
|
||||
internal MethodResponse(IMethodCallMessage msg,
|
||||
Object handlerObject,
|
||||
BinaryMethodReturnMessage smuggledMrm)
|
||||
{
|
||||
if (msg != null)
|
||||
{
|
||||
_methodBase = (MethodBase)msg.MethodBase;
|
||||
// _methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
|
||||
|
||||
_methodName = msg.MethodName;
|
||||
_uri = msg.Uri;
|
||||
// _typeName = msg.TypeName;
|
||||
|
||||
// if (_methodCache.IsOverloaded())
|
||||
// _methodSignature = (Type[])msg.MethodSignature;
|
||||
|
||||
// argCount = _methodCache.Parameters.Length;
|
||||
|
||||
}
|
||||
|
||||
_returnValue = smuggledMrm.ReturnValue;
|
||||
_args = smuggledMrm.Args;
|
||||
_exception = smuggledMrm.Exception;
|
||||
|
||||
_callContext = smuggledMrm.LogicalCallContext;
|
||||
|
||||
if (smuggledMrm.HasProperties)
|
||||
smuggledMrm.PopulateMessageProperties(Properties);
|
||||
}
|
||||
#endif
|
||||
internal MethodResponse (SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
foreach (SerializationEntry entry in info)
|
||||
@ -344,5 +375,10 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
set { _targetIdentity = value; }
|
||||
}
|
||||
|
||||
bool IInternalMessage.HasProperties()
|
||||
{
|
||||
return (ExternalProperties != null) || (InternalProperties != null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -29,21 +29,21 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
internal class MethodReturnDictionary : MethodDictionary
|
||||
{
|
||||
public static string[] InternalReturnKeys = new string[] {"__Uri", "__MethodName", "__TypeName", "__MethodSignature", "__OutArgs", "__Return", "__CallContext"};
|
||||
public static string[] InternalExceptionKeys = new string[] {"__CallContext"};
|
||||
|
||||
public MethodReturnDictionary (IMethodReturnMessage message) : base (message)
|
||||
{
|
||||
if (message.Exception == null)
|
||||
MethodKeys = InternalReturnKeys;
|
||||
else
|
||||
MethodKeys = InternalExceptionKeys;
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.Remoting.Messaging
|
||||
{
|
||||
internal class MethodReturnDictionary : MessageDictionary
|
||||
{
|
||||
public static string[] InternalReturnKeys = new string[] {"__Uri", "__MethodName", "__TypeName", "__MethodSignature", "__OutArgs", "__Return", "__CallContext"};
|
||||
public static string[] InternalExceptionKeys = new string[] {"__CallContext"};
|
||||
|
||||
public MethodReturnDictionary (IMethodReturnMessage message) : base (message)
|
||||
{
|
||||
if (message.Exception == null)
|
||||
MethodKeys = InternalReturnKeys;
|
||||
else
|
||||
MethodKeys = InternalExceptionKeys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,12 +59,14 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
string uri;
|
||||
|
||||
MethodCallDictionary properties;
|
||||
MCMDictionary properties;
|
||||
|
||||
Type[] methodSignature;
|
||||
|
||||
Identity identity;
|
||||
|
||||
internal static String CallContextKey = "__CallContext";
|
||||
internal static String UriKey = "__Uri";
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern void InitMessage (MonoMethod method, object [] out_args);
|
||||
@ -92,7 +94,7 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
|
||||
public IDictionary Properties {
|
||||
get {
|
||||
if (properties == null) properties = new MethodCallDictionary (this);
|
||||
if (properties == null) properties = new MCMDictionary (this);
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
@ -331,6 +333,11 @@ namespace System.Runtime.Remoting.Messaging {
|
||||
set { identity = value; }
|
||||
}
|
||||
|
||||
bool IInternalMessage.HasProperties()
|
||||
{
|
||||
return properties != null;
|
||||
}
|
||||
|
||||
public bool IsAsync
|
||||
{
|
||||
get { return asyncResult != null; }
|
||||
|
@ -225,5 +225,14 @@ namespace System.Runtime.Remoting.Messaging
|
||||
set { _targetIdentity = value; }
|
||||
}
|
||||
|
||||
bool IInternalMessage.HasProperties ()
|
||||
{
|
||||
return _properties != null;
|
||||
}
|
||||
|
||||
internal bool HasProperties ()
|
||||
{
|
||||
return _properties != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user