Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
//
// System.Runtime.Remoting.ActivatedClientTypeEntry.cs
//
// AUthor: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Contexts;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public class ActivatedClientTypeEntry : TypeEntry
{
string applicationUrl;
Type obj_type;
public ActivatedClientTypeEntry (Type type, string appUrl)
{
AssemblyName = type.Assembly.FullName;
TypeName = type.FullName;
applicationUrl = appUrl;
obj_type = type;
}
public ActivatedClientTypeEntry (string typeName, string assemblyName, string appUrl)
{
AssemblyName = assemblyName;
TypeName = typeName;
applicationUrl = appUrl;
Assembly a = Assembly.Load (assemblyName);
obj_type = a.GetType (typeName);
if (obj_type == null)
throw new RemotingException ("Type not found: " + typeName + ", " + assemblyName);
}
public string ApplicationUrl {
get { return applicationUrl; }
}
public IContextAttribute [] ContextAttributes {
get { return null; }
set { } // This is not implemented in the MS runtime yet.
}
public Type ObjectType {
get { return obj_type; }
}
public override string ToString ()
{
return TypeName + AssemblyName + ApplicationUrl;
}
}
}

View File

@@ -0,0 +1,75 @@
//
// System.Runtime.Remoting.ActivatedServiceTypeEntry.cs
//
// AUthor: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Contexts;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public class ActivatedServiceTypeEntry : TypeEntry
{
Type obj_type;
public ActivatedServiceTypeEntry (Type type)
{
AssemblyName = type.Assembly.FullName;
TypeName = type.FullName;
obj_type = type;
}
public ActivatedServiceTypeEntry (string typeName, string assemblyName)
{
AssemblyName = assemblyName;
TypeName = typeName;
Assembly a = Assembly.Load (assemblyName);
obj_type = a.GetType (typeName);
if (obj_type == null)
throw new RemotingException ("Type not found: " + typeName + ", " + assemblyName);
}
public IContextAttribute [] ContextAttributes {
get { return null; }
set { } // This is not implemented in the MS runtime yet.
}
public Type ObjectType {
get { return obj_type; }
}
public override string ToString ()
{
return AssemblyName + TypeName;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
//
// System.Runtime.Remoting.CustomErrorsModes.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
//
// Copyright (C) 2007 Novell, Inc (http://www.novell.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;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public enum CustomErrorsModes
{
On,
Off,
RemoteOnly,
}
}

View File

@@ -0,0 +1,53 @@
//
// System.Runtime.Remoting.EnvoyInfo.cs
//
// Author: Lluis Sanchez Gual (lluis@ideary.com)
//
// (C) 2002, Lluis Sanchez Gual
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Remoting.Messaging;
namespace System.Runtime.Remoting
{
[Serializable]
internal class EnvoyInfo: IEnvoyInfo
{
IMessageSink envoySinks;
public EnvoyInfo (IMessageSink sinks)
{
envoySinks = sinks;
}
public IMessageSink EnvoySinks
{
get { return envoySinks; }
set { envoySinks = value; }
}
}
}

View File

@@ -0,0 +1,41 @@
//
// System.Runtime.Remoting.IChannelInfo.cs
//
// AUthor: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public interface IChannelInfo
{
object[] ChannelData { get; set; }
}
}

View File

@@ -0,0 +1,41 @@
//
// System.Runtime.Remoting.IEnvoyInfo.cs
//
// AUthor: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Remoting.Messaging;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public interface IEnvoyInfo
{
IMessageSink EnvoySinks { get; set; }
}
}

View File

@@ -0,0 +1,46 @@
//
// System.Runtime.Remoting.IObjectHandle.cs
//
// Authors:
// Gonzalo Paniagua (gonzalo@ximian.com)
//
// (C) 2002 Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.InteropServices;
namespace System.Runtime.Remoting
{
[Guid("C460E2B4-E199-412a-8456-84DC3E4838C3")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[System.Runtime.InteropServices.ComVisible (true)]
public interface IObjectHandle
{
object Unwrap ();
}
}

View File

@@ -0,0 +1,43 @@
//
// System.Runtime.Remoting.IRemotingTypeInfo.cs
//
// AUthor: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Reflection;
using System.Runtime.Remoting.Messaging;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public interface IRemotingTypeInfo
{
string TypeName { get; set; }
bool CanCastTo (Type fromType, object o);
}
}

View File

@@ -0,0 +1,174 @@
//
// System.Runtime.Remoting.Identity.cs
//
// Author: Lluis Sanchez Gual (lluis@ideary.com)
//
// (C) 2002, Lluis Sanchez Gual
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Lifetime;
namespace System.Runtime.Remoting
{
internal abstract class Identity
{
// An Identity object holds remoting information about
// an object. It can be used to store client side information
// (information about how to reach the remote server),
// and also to store server side information (information
// about how to dispatch messages to the object in the server).
// URI of the object
protected string _objectUri;
// Message sink to use to send a message to the remote server
protected IMessageSink _channelSink = null;
protected IMessageSink _envoySink = null;
DynamicPropertyCollection _clientDynamicProperties;
DynamicPropertyCollection _serverDynamicProperties;
// The ObjRef
protected ObjRef _objRef;
// This flag is set when the identity is removed from the uri table.
// It is needed because in some scenarios the runtime may try to
// dispose the identity twice.
bool _disposed = false;
public Identity(string objectUri)
{
_objectUri = objectUri;
}
public abstract ObjRef CreateObjRef (Type requestedType);
public bool IsFromThisAppDomain
{
get
{
return (_channelSink == null);
}
}
public IMessageSink ChannelSink
{
get { return _channelSink; }
set { _channelSink = value; }
}
public IMessageSink EnvoySink
{
get { return _envoySink; }
}
public string ObjectUri
{
get { return _objectUri; }
set { _objectUri = value; }
}
public bool IsConnected
{
get { return _objectUri != null; }
}
public bool Disposed
{
get { return _disposed; }
set { _disposed = value; }
}
public DynamicPropertyCollection ClientDynamicProperties
{
get {
if (_clientDynamicProperties == null) _clientDynamicProperties = new DynamicPropertyCollection();
return _clientDynamicProperties;
}
}
public DynamicPropertyCollection ServerDynamicProperties
{
get {
if (_serverDynamicProperties == null) _serverDynamicProperties = new DynamicPropertyCollection();
return _serverDynamicProperties;
}
}
public bool HasClientDynamicSinks
{
get { return (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties); }
}
public bool HasServerDynamicSinks
{
get { return (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties); }
}
public void NotifyClientDynamicSinks (bool start, IMessage req_msg, bool client_site, bool async)
{
if (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties)
_clientDynamicProperties.NotifyMessage (start, req_msg, client_site, async);
}
public void NotifyServerDynamicSinks (bool start, IMessage req_msg, bool client_site, bool async)
{
if (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties)
_serverDynamicProperties.NotifyMessage (start, req_msg, client_site, async);
}
}
internal class ClientIdentity : Identity
{
WeakReference _proxyReference;
public ClientIdentity (string objectUri, ObjRef objRef): base (objectUri)
{
_objRef = objRef;
_envoySink = (_objRef.EnvoyInfo != null) ? _objRef.EnvoyInfo.EnvoySinks : null;
}
public MarshalByRefObject ClientProxy
{
get { return (MarshalByRefObject) _proxyReference.Target; }
set { _proxyReference = new WeakReference (value); }
}
public override ObjRef CreateObjRef (Type requestedType)
{
return _objRef;
}
public string TargetUri
{
get { return _objRef.URI; }
}
}
}

View File

@@ -0,0 +1,109 @@
//
// System.Runtime.Remoting.InternalRemotingServices.cs
//
// Authors:
// Lluis Sanchez Gual (lluis@ximian.com)
//
// (C) 2003 Novell, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Runtime.Remoting.Metadata;
using System.Runtime.Remoting.Messaging;
namespace System.Runtime.Remoting
{
[System.Runtime.InteropServices.ComVisible (true)]
public class InternalRemotingServices
{
static Hashtable _soapAttributes = new Hashtable ();
public InternalRemotingServices ()
{
}
[Conditional("_LOGGING")]
public static void DebugOutChnl (string s)
{
// Mono does not support this internal method
throw new NotSupportedException ();
}
public static SoapAttribute GetCachedSoapAttribute (object reflectionObject)
{
lock (_soapAttributes.SyncRoot) {
SoapAttribute att = _soapAttributes [reflectionObject] as SoapAttribute;
if (att != null) return att;
ICustomAttributeProvider ap = (ICustomAttributeProvider) reflectionObject;
object[] atts = ap.GetCustomAttributes (typeof(SoapAttribute), true);
if (atts.Length > 0)
att = (SoapAttribute) atts[0];
else
{
if (reflectionObject is Type)
att = new SoapTypeAttribute ();
else if (reflectionObject is FieldInfo)
att = new SoapFieldAttribute ();
else if (reflectionObject is MethodBase)
att = new SoapMethodAttribute ();
else if (reflectionObject is ParameterInfo)
att = new SoapParameterAttribute ();
}
att.SetReflectionObject (reflectionObject);
_soapAttributes [reflectionObject] = att;
return att;
}
}
[Conditional("_DEBUG")]
public static void RemotingAssert (bool condition, string message)
{
// Mono does not support this internal method
throw new NotSupportedException ();
}
[Conditional("_LOGGING")]
public static void RemotingTrace (params object[] messages)
{
// Mono does not support this internal method
throw new NotSupportedException ();
}
[CLSCompliant (false)]
public static void SetServerIdentity (MethodCall m, object srvID)
{
Identity ident = srvID as Identity;
if (ident == null) throw new ArgumentException ("srvID");
RemotingServices.SetMessageTargetIdentity (m, ident);
}
}
}

View File

@@ -0,0 +1,264 @@
//
// System.Runtime.Remoting.ObjRef.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
// Dietmar Maurer (dietmar@ximian.com)
// Lluis Sanchez Gual (lluis@ideary.com)
// Patrik Torstensson
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Serialization;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Runtime.ConstrainedExecution;
namespace System.Runtime.Remoting {
[Serializable]
[System.Runtime.InteropServices.ComVisible (true)]
public class ObjRef : IObjectReference, ISerializable
{
IChannelInfo channel_info;
string uri;
IRemotingTypeInfo typeInfo;
IEnvoyInfo envoyInfo;
int flags;
Type _serverType;
static int MarshalledObjectRef = 1;
static int WellKnowObjectRef = 2;
public ObjRef ()
{
// no idea why this needs to be public
UpdateChannelInfo();
}
internal ObjRef (string typeName, string uri, IChannelInfo cinfo)
{
this.uri = uri;
channel_info = cinfo;
typeInfo = new TypeInfo (Type.GetType (typeName, true));
}
internal ObjRef (ObjRef o, bool unmarshalAsProxy) {
channel_info = o.channel_info;
uri = o.uri;
typeInfo = o.typeInfo;
envoyInfo = o.envoyInfo;
flags = o.flags;
if (unmarshalAsProxy) flags |= MarshalledObjectRef;
}
public ObjRef (MarshalByRefObject o, Type requestedType)
{
if (o == null)
throw new ArgumentNullException ("o");
if (requestedType == null)
throw new ArgumentNullException ("requestedType");
// The ObjRef can only be constructed if the given o
// has already been marshalled using RemotingServices.Marshall
uri = RemotingServices.GetObjectUri (o);
typeInfo = new TypeInfo (requestedType);
if (!requestedType.IsInstanceOfType (o))
throw new RemotingException ("The server object type cannot be cast to the requested type " + requestedType.FullName);
UpdateChannelInfo();
}
internal ObjRef (Type type, string url, object remoteChannelData)
{
uri = url;
typeInfo = new TypeInfo(type);
if (remoteChannelData != null)
channel_info = new ChannelInfo (remoteChannelData);
flags |= WellKnowObjectRef;
}
protected ObjRef (SerializationInfo info, StreamingContext context)
{
SerializationInfoEnumerator en = info.GetEnumerator();
// Info to serialize: uri, objrefFlags, typeInfo, envoyInfo, channelInfo
bool marshalledValue = true;
while (en.MoveNext ()) {
switch (en.Name) {
case "uri":
uri = (string)en.Value;
break;
case "typeInfo":
typeInfo = (IRemotingTypeInfo)en.Value;
break;
case "channelInfo":
channel_info = (IChannelInfo)en.Value;
break;
case "envoyInfo":
envoyInfo = (IEnvoyInfo)en.Value;
break;
case "fIsMarshalled":
int status;
Object o = en.Value;
if (o is string)
status = ((IConvertible) o).ToInt32(null);
else
status = (int) o;
if (status == 0)
marshalledValue = false;
break;
case "objrefFlags":
flags = Convert.ToInt32 (en.Value);
break;
default:
throw new NotSupportedException ();
}
}
if (marshalledValue) flags |= MarshalledObjectRef;
}
internal bool IsPossibleToCAD ()
{
// we should check if this obj ref belongs to a cross app context.
// Return false. If not, serialization of this ObjRef will not work
// on the target AD.
return false;
}
internal bool IsReferenceToWellKnow
{
get { return (flags & WellKnowObjectRef) > 0; }
}
public virtual IChannelInfo ChannelInfo {
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
get {
return channel_info;
}
set {
channel_info = value;
}
}
public virtual IEnvoyInfo EnvoyInfo {
get {
return envoyInfo;
}
set {
envoyInfo = value;
}
}
public virtual IRemotingTypeInfo TypeInfo {
get {
return typeInfo;
}
set {
typeInfo = value;
}
}
public virtual string URI {
get {
return uri;
}
set {
uri = value;
}
}
public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
{
info.SetType (GetType());
info.AddValue ("uri", uri);
info.AddValue ("typeInfo", typeInfo, typeof (IRemotingTypeInfo));
info.AddValue ("envoyInfo", envoyInfo, typeof (IEnvoyInfo));
info.AddValue ("channelInfo", channel_info, typeof(IChannelInfo));
info.AddValue ("objrefFlags", flags);
}
public virtual object GetRealObject (StreamingContext context)
{
if ((flags & MarshalledObjectRef) > 0)
return RemotingServices.Unmarshal (this);
else
return this;
}
public bool IsFromThisAppDomain ()
{
Identity identity = RemotingServices.GetIdentityForUri (uri);
if (identity == null) return false; // URI not registered in this domain
return identity.IsFromThisAppDomain;
}
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
public bool IsFromThisProcess ()
{
foreach (object data in channel_info.ChannelData)
{
if (data is CrossAppDomainData)
{
string refProcId = ((CrossAppDomainData)data).ProcessID;
return (refProcId == RemotingConfiguration.ProcessId);
}
}
return true;
}
internal void UpdateChannelInfo()
{
channel_info = new ChannelInfo ();
}
internal Type ServerType
{
get
{
if (_serverType == null) _serverType = Type.GetType (typeInfo.TypeName);
return _serverType;
}
}
}
}

View File

@@ -0,0 +1,64 @@
//
// System.Runtime.Remoting.ObjectHandle.cs
//
// Authors:
// Dietmar Maurer (dietmar@ximian.com)
// Gonzalo Paniagua (gonzalo@ximian.com)
// Jaime Anguiano Olarra (jaime@gnome.org)
//
// (C) Ximian, Inc. http://www.ximian.com
//
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Serialization;
using System.Runtime.Remoting.Lifetime;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting {
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible (true)]
public class ObjectHandle : MarshalByRefObject, IObjectHandle {
private object _wrapped;
public ObjectHandle (object o)
{
_wrapped = o;
}
public override object InitializeLifetimeService ()
{
return base.InitializeLifetimeService ();
}
public object Unwrap ()
{
return _wrapped;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
//
// System.Runtime.Remoting.RemotingException.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Serialization;
namespace System.Runtime.Remoting {
[Serializable]
[System.Runtime.InteropServices.ComVisible (true)]
public class RemotingException : SystemException
{
public RemotingException ()
: base ()
{
}
public RemotingException (string message)
: base (message)
{
}
protected RemotingException (SerializationInfo info, StreamingContext context)
: base (info, context)
{
}
public RemotingException (string message, Exception InnerException)
: base (message, InnerException)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
//
// System.Runtime.Remoting.RemotingTimeoutException.cs
//
// Author: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Serialization;
namespace System.Runtime.Remoting {
[Serializable]
[System.Runtime.InteropServices.ComVisible (true)]
public class RemotingTimeoutException : RemotingException
{
public RemotingTimeoutException ()
: base ()
{
}
public RemotingTimeoutException (string message)
: base (message)
{
}
public RemotingTimeoutException (string message, Exception InnerException)
: base (message, InnerException)
{
}
internal RemotingTimeoutException (SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@@ -0,0 +1,61 @@
//
// System.Runtime.Remoting.ServerException.cs
//
// AUthor: Duncan Mak (duncan@ximian.com)
//
// 2002 (C) Copyright. Ximian, Inc.
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Serialization;
namespace System.Runtime.Remoting {
[Serializable]
[System.Runtime.InteropServices.ComVisible (true)]
public class ServerException : SystemException
{
public ServerException ()
: base ()
{
}
public ServerException (string message)
: base (message)
{
}
public ServerException (string message, Exception InnerException)
: base (message, InnerException)
{
}
internal ServerException (SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@@ -0,0 +1,294 @@
//
// System.Runtime.Remoting.Identity.cs
//
// Author: Lluis Sanchez Gual (lluis@ideary.com)
//
// (C) 2002, Lluis Sanchez Gual
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Lifetime;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Services;
namespace System.Runtime.Remoting
{
internal abstract class ServerIdentity : Identity
{
protected Type _objectType;
protected MarshalByRefObject _serverObject;
// Message sink used in the server to dispatch a message
// to the server object
protected IMessageSink _serverSink = null;
protected Context _context;
protected Lease _lease;
public ServerIdentity (string objectUri, Context context, Type objectType): base (objectUri)
{
_objectType = objectType;
_context = context;
}
public Type ObjectType
{
get { return _objectType; }
}
public void StartTrackingLifetime (ILease lease)
{
// Adds this identity to the LeaseManager.
// _serverObject must be set.
if (lease != null && lease.CurrentState == LeaseState.Null) lease = null;
if (lease != null)
{
if (! (lease is Lease)) lease = new Lease(); // This seems to be MS behavior
_lease = (Lease) lease;
LifetimeServices.TrackLifetime (this);
}
}
public virtual void OnLifetimeExpired()
{
DisposeServerObject();
}
public override ObjRef CreateObjRef (Type requestedType)
{
if (_objRef != null)
{
// Just update channel info. It may have changed.
_objRef.UpdateChannelInfo();
return _objRef;
}
if (requestedType == null) requestedType = _objectType;
_objRef = new ObjRef ();
_objRef.TypeInfo = new TypeInfo(requestedType);
_objRef.URI = _objectUri;
if (_envoySink != null && !(_envoySink is EnvoyTerminatorSink))
_objRef.EnvoyInfo = new EnvoyInfo (_envoySink);
return _objRef;
}
public void AttachServerObject (MarshalByRefObject serverObject, Context context)
{
DisposeServerObject();
_context = context;
_serverObject = serverObject;
if (RemotingServices.IsTransparentProxy (serverObject))
{
RealProxy rp = RemotingServices.GetRealProxy (serverObject);
if (rp.ObjectIdentity == null)
rp.ObjectIdentity = this;
}
else
{
if (_objectType.IsContextful)
_envoySink = context.CreateEnvoySink (serverObject);
_serverObject.ObjectIdentity = this;
}
}
public Lease Lease
{
get { return _lease; }
}
public Context Context
{
get { return _context; }
set { _context = value; }
}
public abstract IMessage SyncObjectProcessMessage (IMessage msg);
public abstract IMessageCtrl AsyncObjectProcessMessage (IMessage msg, IMessageSink replySink);
protected void DisposeServerObject()
{
// Detach identity from server object to avoid problems if the
// object is marshalled again.
if (_serverObject != null) {
MarshalByRefObject obj = _serverObject;
_serverObject.ObjectIdentity = null;
_serverObject = null;
_serverSink = null;
TrackingServices.NotifyDisconnectedObject (obj);
}
}
}
internal class ClientActivatedIdentity : ServerIdentity
{
MarshalByRefObject _targetThis;
public ClientActivatedIdentity (string objectUri, Type objectType): base (objectUri, null, objectType)
{
}
public MarshalByRefObject GetServerObject ()
{
return _serverObject;
}
public MarshalByRefObject GetClientProxy ()
{
return _targetThis;
}
public void SetClientProxy (MarshalByRefObject obj)
{
_targetThis = obj;
}
public override void OnLifetimeExpired()
{
base.OnLifetimeExpired();
RemotingServices.DisposeIdentity (this);
}
public override IMessage SyncObjectProcessMessage (IMessage msg)
{
if (_serverSink == null) {
bool useProxy = _targetThis != null;
_serverSink = _context.CreateServerObjectSinkChain ((useProxy ? _targetThis : _serverObject), useProxy);
}
return _serverSink.SyncProcessMessage (msg);
}
public override IMessageCtrl AsyncObjectProcessMessage (IMessage msg, IMessageSink replySink)
{
if (_serverSink == null) {
bool useProxy = _targetThis != null;
_serverSink = _context.CreateServerObjectSinkChain ((useProxy ? _targetThis : _serverObject), useProxy);
}
return _serverSink.AsyncProcessMessage (msg, replySink);
}
}
internal class SingletonIdentity : ServerIdentity
{
public SingletonIdentity (string objectUri, Context context, Type objectType): base (objectUri, context, objectType)
{
}
public MarshalByRefObject GetServerObject ()
{
if (_serverObject != null) return _serverObject;
lock (this)
{
if (_serverObject == null) {
MarshalByRefObject server = (MarshalByRefObject) Activator.CreateInstance (_objectType, true);
AttachServerObject (server, Context.DefaultContext);
StartTrackingLifetime ((ILease)server.InitializeLifetimeService ());
}
}
return _serverObject;
}
public override IMessage SyncObjectProcessMessage (IMessage msg)
{
MarshalByRefObject obj = GetServerObject ();
if (_serverSink == null) _serverSink = _context.CreateServerObjectSinkChain (obj, false);
return _serverSink.SyncProcessMessage (msg);
}
public override IMessageCtrl AsyncObjectProcessMessage (IMessage msg, IMessageSink replySink)
{
MarshalByRefObject obj = GetServerObject ();
if (_serverSink == null) _serverSink = _context.CreateServerObjectSinkChain (obj, false);
return _serverSink.AsyncProcessMessage (msg, replySink);
}
}
internal class SingleCallIdentity : ServerIdentity
{
public SingleCallIdentity (string objectUri, Context context, Type objectType): base (objectUri, context, objectType)
{
}
public override IMessage SyncObjectProcessMessage (IMessage msg)
{
// SingleCallIdentity creates and disposes an instance in each call
MarshalByRefObject obj = (MarshalByRefObject)Activator.CreateInstance (_objectType, true);
if (obj.ObjectIdentity == null) obj.ObjectIdentity = this;
IMessageSink serverSink = _context.CreateServerObjectSinkChain (obj, false);
IMessage result = serverSink.SyncProcessMessage (msg);
if (obj is IDisposable) ((IDisposable)obj).Dispose();
return result;
}
public override IMessageCtrl AsyncObjectProcessMessage (IMessage msg, IMessageSink replySink)
{
MarshalByRefObject obj = (MarshalByRefObject)Activator.CreateInstance (_objectType, true);
IMessageSink serverSink = _context.CreateServerObjectSinkChain (obj, false);
if (obj is IDisposable) replySink = new DisposerReplySink(replySink, ((IDisposable)obj));
return serverSink.AsyncProcessMessage (msg, replySink);
}
}
internal class DisposerReplySink : IMessageSink
{
IMessageSink _next;
IDisposable _disposable;
public DisposerReplySink (IMessageSink next, IDisposable disposable)
{
_next = next;
_disposable = disposable;
}
public IMessage SyncProcessMessage (IMessage msg)
{
_disposable.Dispose();
return _next.SyncProcessMessage (msg);
}
public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink)
{
throw new NotSupportedException();
}
public IMessageSink NextSink
{
get { return _next; }
}
}
}

View File

@@ -0,0 +1,408 @@
//
// System.Runtime.Remoting.SoapServices.cs
//
// Author: Jaime Anguiano Olarra (jaime@gnome.org)
// Lluis Sanchez Gual (lluis@ximian.com)
//
// (c) 2002, Jaime Anguiano Olarra
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.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.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Metadata;
using System.Reflection;
using System.Runtime.InteropServices;
namespace System.Runtime.Remoting {
[System.Runtime.InteropServices.ComVisible (true)]
public class SoapServices
{
static Hashtable _xmlTypes = new Hashtable ();
static Hashtable _xmlElements = new Hashtable ();
static Hashtable _soapActions = new Hashtable ();
static Hashtable _soapActionsMethods = new Hashtable ();
static Hashtable _typeInfos = new Hashtable ();
class TypeInfo
{
public Hashtable Attributes;
public Hashtable Elements;
}
// Private constructor: nobody instantiates this class
private SoapServices () {}
// properties
public static string XmlNsForClrType
{
get { return "http://schemas.microsoft.com/clr/"; }
}
public static string XmlNsForClrTypeWithAssembly
{
get { return "http://schemas.microsoft.com/clr/assem/"; }
}
public static string XmlNsForClrTypeWithNs
{
get { return "http://schemas.microsoft.com/clr/ns/"; }
}
public static string XmlNsForClrTypeWithNsAndAssembly
{
get { return "http://schemas.microsoft.com/clr/nsassem/"; }
}
// public methods
public static string CodeXmlNamespaceForClrTypeNamespace (string typeNamespace,
string assemblyName)
{
// If assemblyName is empty, then use the corlib namespace
if (assemblyName == string.Empty)
return XmlNsForClrTypeWithNs + typeNamespace;
else if (typeNamespace == string.Empty)
return EncodeNs (XmlNsForClrTypeWithAssembly + assemblyName);
else
return EncodeNs (XmlNsForClrTypeWithNsAndAssembly + typeNamespace + "/" + assemblyName);
}
public static bool DecodeXmlNamespaceForClrTypeNamespace (string inNamespace,
out string typeNamespace,
out string assemblyName) {
if (inNamespace == null) throw new ArgumentNullException ("inNamespace");
inNamespace = DecodeNs (inNamespace);
typeNamespace = null;
assemblyName = null;
if (inNamespace.StartsWith(XmlNsForClrTypeWithNsAndAssembly))
{
int typePos = XmlNsForClrTypeWithNsAndAssembly.Length;
if (typePos >= inNamespace.Length) return false;
int assemPos = inNamespace.IndexOf ('/', typePos+1);
if (assemPos == -1) return false;
typeNamespace = inNamespace.Substring (typePos, assemPos - typePos);
assemblyName = inNamespace.Substring (assemPos+1);
return true;
}
else if (inNamespace.StartsWith(XmlNsForClrTypeWithNs))
{
int typePos = XmlNsForClrTypeWithNs.Length;
typeNamespace = inNamespace.Substring (typePos);
return true;
}
else if (inNamespace.StartsWith(XmlNsForClrTypeWithAssembly))
{
int typePos = XmlNsForClrTypeWithAssembly.Length;
assemblyName = inNamespace.Substring (typePos);
return true;
}
else
return false;
}
public static void GetInteropFieldTypeAndNameFromXmlAttribute (Type containingType,
string xmlAttribute, string xmlNamespace,
out Type type, out string name)
{
TypeInfo tf = (TypeInfo) _typeInfos [containingType];
Hashtable ht = tf != null ? tf.Attributes : null;
GetInteropFieldInfo (ht, xmlAttribute, xmlNamespace, out type, out name);
}
public static void GetInteropFieldTypeAndNameFromXmlElement (Type containingType,
string xmlElement, string xmlNamespace,
out Type type, out string name)
{
TypeInfo tf = (TypeInfo) _typeInfos [containingType];
Hashtable ht = tf != null ? tf.Elements : null;
GetInteropFieldInfo (ht, xmlElement, xmlNamespace, out type, out name);
}
static void GetInteropFieldInfo (Hashtable fields,
string xmlName, string xmlNamespace,
out Type type, out string name)
{
if (fields != null)
{
FieldInfo field = (FieldInfo) fields [GetNameKey (xmlName, xmlNamespace)];
if (field != null)
{
type = field.FieldType;
name = field.Name;
return;
}
}
type = null;
name = null;
}
static string GetNameKey (string name, string namspace)
{
if (namspace == null) return name;
else return name + " " + namspace;
}
public static Type GetInteropTypeFromXmlElement (string xmlElement, string xmlNamespace)
{
lock (_xmlElements.SyncRoot)
{
return (Type) _xmlElements [xmlElement + " " + xmlNamespace];
}
}
public static Type GetInteropTypeFromXmlType (string xmlType, string xmlTypeNamespace)
{
lock (_xmlTypes.SyncRoot)
{
return (Type) _xmlTypes [xmlType + " " + xmlTypeNamespace];
}
}
private static string GetAssemblyName(MethodBase mb)
{
if (mb.DeclaringType.Assembly == typeof (object).Assembly)
return string.Empty;
else
return mb.DeclaringType.Assembly.GetName().Name;
}
public static string GetSoapActionFromMethodBase (MethodBase mb)
{
return InternalGetSoapAction (mb);
}
public static bool GetTypeAndMethodNameFromSoapAction (string soapAction,
out string typeName,
out string methodName)
{
lock (_soapActions.SyncRoot)
{
MethodBase mb = (MethodBase) _soapActionsMethods [soapAction];
if (mb != null)
{
typeName = mb.DeclaringType.AssemblyQualifiedName;
methodName = mb.Name;
return true;
}
}
string type;
string assembly;
typeName = null;
methodName = null;
int i = soapAction.LastIndexOf ('#');
if (i == -1) return false;
methodName = soapAction.Substring (i+1);
if (!DecodeXmlNamespaceForClrTypeNamespace (soapAction.Substring (0,i), out type, out assembly) )
return false;
if (assembly == null)
typeName = type + ", " + typeof (object).Assembly.GetName().Name;
else
typeName = type + ", " + assembly;
return true;
}
public static bool GetXmlElementForInteropType (Type type, out string xmlElement, out string xmlNamespace)
{
SoapTypeAttribute att = (SoapTypeAttribute) InternalRemotingServices.GetCachedSoapAttribute (type);
if (!att.IsInteropXmlElement)
{
xmlElement = null;
xmlNamespace = null;
return false;
}
xmlElement = att.XmlElementName;
xmlNamespace = att.XmlNamespace;
return true;
}
public static string GetXmlNamespaceForMethodCall (MethodBase mb)
{
return CodeXmlNamespaceForClrTypeNamespace (mb.DeclaringType.FullName, GetAssemblyName(mb));
}
public static string GetXmlNamespaceForMethodResponse (MethodBase mb)
{
return CodeXmlNamespaceForClrTypeNamespace (mb.DeclaringType.FullName, GetAssemblyName(mb));
}
public static bool GetXmlTypeForInteropType (Type type, out string xmlType, out string xmlTypeNamespace)
{
SoapTypeAttribute att = (SoapTypeAttribute) InternalRemotingServices.GetCachedSoapAttribute (type);
if (!att.IsInteropXmlType)
{
xmlType = null;
xmlTypeNamespace = null;
return false;
}
xmlType = att.XmlTypeName;
xmlTypeNamespace = att.XmlTypeNamespace;
return true;
}
public static bool IsClrTypeNamespace (string namespaceString)
{
return namespaceString.StartsWith (XmlNsForClrType);
}
public static bool IsSoapActionValidForMethodBase (string soapAction, MethodBase mb)
{
string typeName;
string methodName;
GetTypeAndMethodNameFromSoapAction (soapAction, out typeName, out methodName);
if (methodName != mb.Name) return false;
string methodClassType = mb.DeclaringType.AssemblyQualifiedName;
return typeName == methodClassType;
}
public static void PreLoad (Assembly assembly)
{
foreach (Type t in assembly.GetTypes ())
PreLoad (t);
}
public static void PreLoad (Type type)
{
string name, namspace;
TypeInfo tf = _typeInfos [type] as TypeInfo;
if (tf != null) return;
if (GetXmlTypeForInteropType (type, out name, out namspace))
RegisterInteropXmlType (name, namspace, type);
if (GetXmlElementForInteropType (type, out name, out namspace))
RegisterInteropXmlElement (name, namspace, type);
lock (_typeInfos.SyncRoot)
{
tf = new TypeInfo ();
FieldInfo[] fields = type.GetFields (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo field in fields)
{
SoapFieldAttribute att = (SoapFieldAttribute) InternalRemotingServices.GetCachedSoapAttribute (field);
if (!att.IsInteropXmlElement ()) continue;
string key = GetNameKey (att.XmlElementName, att.XmlNamespace);
if (att.UseAttribute)
{
if (tf.Attributes == null) tf.Attributes = new Hashtable ();
tf.Attributes [key] = field;
}
else
{
if (tf.Elements == null) tf.Elements = new Hashtable ();
tf.Elements [key] = field;
}
}
_typeInfos [type] = tf;
}
}
public static void RegisterInteropXmlElement (string xmlElement, string xmlNamespace, Type type)
{
lock (_xmlElements.SyncRoot)
{
_xmlElements [xmlElement + " " + xmlNamespace] = type;
}
}
public static void RegisterInteropXmlType (string xmlType, string xmlTypeNamespace, Type type)
{
lock (_xmlTypes.SyncRoot)
{
_xmlTypes [xmlType + " " + xmlTypeNamespace] = type;
}
}
public static void RegisterSoapActionForMethodBase (MethodBase mb)
{
InternalGetSoapAction (mb);
}
static string InternalGetSoapAction (MethodBase mb)
{
lock (_soapActions.SyncRoot)
{
string action = (string) _soapActions [mb];
if (action == null)
{
SoapMethodAttribute att = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute (mb);
action = att.SoapAction;
_soapActions [mb] = action;
_soapActionsMethods [action] = mb;
}
return action;
}
}
public static void RegisterSoapActionForMethodBase (MethodBase mb, string soapAction)
{
lock (_soapActions.SyncRoot)
{
_soapActions [mb] = soapAction;
_soapActionsMethods [soapAction] = mb;
}
}
static string EncodeNs (string ns)
{
// Simple url encoding for namespaces
ns = ns.Replace (",","%2C");
ns = ns.Replace (" ","%20");
return ns.Replace ("=","%3D");
}
static string DecodeNs (string ns)
{
ns = ns.Replace ("%2C",",");
ns = ns.Replace ("%20"," ");
return ns.Replace ("%3D","=");
}
}
}

Some files were not shown because too many files have changed in this diff Show More