We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- using System;
- using System.Collections;
- using System.IO;
- using System.Reflection;
- using System.Runtime.Remoting;
- using System.Runtime.Remoting.Channels;
- using System.Globalization;
- using System.Runtime.Versioning;
- namespace System.Runtime.Remoting.Activation
- {
-
-
- internal class RemotingXmlConfigFileData
- {
-
- static internal bool LoadTypes = false;
-
-
-
-
-
-
-
- internal class ChannelEntry
- {
- internal string TypeName;
- internal string AssemblyName;
- internal Hashtable Properties;
- internal bool DelayLoad = false;
- internal ArrayList ClientSinkProviders = new ArrayList();
- internal ArrayList ServerSinkProviders = new ArrayList();
-
- internal ChannelEntry(string typeName, string assemblyName, Hashtable properties)
- {
- TypeName = typeName;
- AssemblyName = assemblyName;
- Properties = properties;
- }
-
- }
-
-
- internal class ClientWellKnownEntry
- {
- internal string TypeName;
- internal string AssemblyName;
- internal string Url;
-
- internal ClientWellKnownEntry(string typeName, string assemName, string url)
- {
- TypeName = typeName;
- AssemblyName = assemName;
- Url = url;
- }
- }
-
-
- internal class ContextAttributeEntry
- {
- internal string TypeName;
- internal string AssemblyName;
- internal Hashtable Properties;
-
- internal ContextAttributeEntry(string typeName, string assemName, Hashtable properties)
- {
- TypeName = typeName;
- AssemblyName = assemName;
- Properties = properties;
- }
- }
-
-
- internal class InteropXmlElementEntry
- {
- internal string XmlElementName;
- internal string XmlElementNamespace;
- internal string UrtTypeName;
- internal string UrtAssemblyName;
-
- internal InteropXmlElementEntry(string xmlElementName, string xmlElementNamespace, string urtTypeName, string urtAssemblyName)
- {
- XmlElementName = xmlElementName;
- XmlElementNamespace = xmlElementNamespace;
- UrtTypeName = urtTypeName;
- UrtAssemblyName = urtAssemblyName;
- }
- }
-
- internal class CustomErrorsEntry
- {
- internal CustomErrorsModes Mode;
-
- internal CustomErrorsEntry(CustomErrorsModes mode)
- {
- Mode = mode;
- }
- }
-
- internal class InteropXmlTypeEntry
- {
- internal string XmlTypeName;
- internal string XmlTypeNamespace;
- internal string UrtTypeName;
- internal string UrtAssemblyName;
-
- internal InteropXmlTypeEntry(string xmlTypeName, string xmlTypeNamespace, string urtTypeName, string urtAssemblyName)
- {
- XmlTypeName = xmlTypeName;
- XmlTypeNamespace = xmlTypeNamespace;
- UrtTypeName = urtTypeName;
- UrtAssemblyName = urtAssemblyName;
- }
- }
-
-
- internal class LifetimeEntry
- {
-
-
- internal bool IsLeaseTimeSet = false;
- internal bool IsRenewOnCallTimeSet = false;
- internal bool IsSponsorshipTimeoutSet = false;
- internal bool IsLeaseManagerPollTimeSet = false;
-
- private TimeSpan _leaseTime;
- private TimeSpan _renewOnCallTime;
- private TimeSpan _sponsorshipTimeout;
- private TimeSpan _leaseManagerPollTime;
-
- internal TimeSpan LeaseTime {
- get {
- BCLDebug.Assert(IsLeaseTimeSet == true, "LeaseTime not set");
- return _leaseTime;
- }
- set {
- _leaseTime = value;
- IsLeaseTimeSet = true;
- }
- }
-
- internal TimeSpan RenewOnCallTime {
- get {
- BCLDebug.Assert(IsRenewOnCallTimeSet == true, "RenewOnCallTime not set");
- return _renewOnCallTime;
- }
- set {
- _renewOnCallTime = value;
- IsRenewOnCallTimeSet = true;
- }
- }
-
- internal TimeSpan SponsorshipTimeout {
- get {
- BCLDebug.Assert(IsSponsorshipTimeoutSet == true, "SponsorShipTimeout not set");
- return _sponsorshipTimeout;
- }
- set {
- _sponsorshipTimeout = value;
- IsSponsorshipTimeoutSet = true;
- }
- }
-
- internal TimeSpan LeaseManagerPollTime {
- get {
- BCLDebug.Assert(IsLeaseManagerPollTimeSet == true, "LeaseManagerPollTime not set");
- return _leaseManagerPollTime;
- }
- set {
- _leaseManagerPollTime = value;
- IsLeaseManagerPollTimeSet = true;
- }
- }
-
- }
-
-
- internal class PreLoadEntry
- {
-
-
-
- internal string TypeName;
- internal string AssemblyName;
-
- public PreLoadEntry(string typeName, string assemblyName)
- {
- TypeName = typeName;
- AssemblyName = assemblyName;
- }
- }
-
-
- internal class RemoteAppEntry
- {
- internal string AppUri;
-
- internal ArrayList WellKnownObjects = new ArrayList();
- internal ArrayList ActivatedObjects = new ArrayList();
-
- internal RemoteAppEntry(string appUri)
- {
- AppUri = appUri;
- }
-
- internal void AddWellKnownEntry(string typeName, string assemName, string url)
- {
- ClientWellKnownEntry cwke = new ClientWellKnownEntry(typeName, assemName, url);
- WellKnownObjects.Add(cwke);
- }
-
- internal void AddActivatedEntry(string typeName, string assemName, ArrayList contextAttributes)
- {
- TypeEntry te = new TypeEntry(typeName, assemName, contextAttributes);
- ActivatedObjects.Add(te);
- }
-
- }
-
-
- internal class ServerWellKnownEntry : TypeEntry
- {
- internal string ObjectURI;
- internal WellKnownObjectMode ObjectMode;
-
- internal ServerWellKnownEntry(string typeName, string assemName, ArrayList contextAttributes, string objURI, WellKnownObjectMode objMode) : base(typeName, assemName, contextAttributes)
- {
- ObjectURI = objURI;
- ObjectMode = objMode;
- }
- }
-
-
- internal class SinkProviderEntry
- {
- internal string TypeName;
- internal string AssemblyName;
- internal Hashtable Properties;
- internal ArrayList ProviderData = new ArrayList();
-
- internal bool IsFormatter;
-
- internal SinkProviderEntry(string typeName, string assemName, Hashtable properties, bool isFormatter)
- {
- TypeName = typeName;
- AssemblyName = assemName;
- Properties = properties;
- IsFormatter = isFormatter;
- }
- }
-
-
- internal class TypeEntry
- {
- internal string TypeName;
- internal string AssemblyName;
- internal ArrayList ContextAttributes;
-
- internal TypeEntry(string typeName, string assemName, ArrayList contextAttributes)
- {
- TypeName = typeName;
- AssemblyName = assemName;
- ContextAttributes = contextAttributes;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- internal string ApplicationName = null;
-
- internal LifetimeEntry Lifetime = null;
-
- internal bool UrlObjRefMode = RemotingConfigHandler.UrlObjRefMode;
-
- internal CustomErrorsEntry CustomErrors = null;
-
- internal ArrayList ChannelEntries = new ArrayList();
- internal ArrayList InteropXmlElementEntries = new ArrayList();
- internal ArrayList InteropXmlTypeEntries = new ArrayList();
- internal ArrayList PreLoadEntries = new ArrayList();
- internal ArrayList RemoteAppEntries = new ArrayList();
- internal ArrayList ServerActivatedEntries = new ArrayList();
- internal ArrayList ServerWellKnownEntries = new ArrayList();
-
-
-
-
-
-
-
-
-
-
-
- internal void AddInteropXmlElementEntry(string xmlElementName, string xmlElementNamespace, string urtTypeName, string urtAssemblyName)
- {
- TryToLoadTypeIfApplicable(urtTypeName, urtAssemblyName);
- InteropXmlElementEntry ixee = new InteropXmlElementEntry(xmlElementName, xmlElementNamespace, urtTypeName, urtAssemblyName);
- InteropXmlElementEntries.Add(ixee);
- }
-
- internal void AddInteropXmlTypeEntry(string xmlTypeName, string xmlTypeNamespace, string urtTypeName, string urtAssemblyName)
- {
- TryToLoadTypeIfApplicable(urtTypeName, urtAssemblyName);
- InteropXmlTypeEntry ixte = new InteropXmlTypeEntry(xmlTypeName, xmlTypeNamespace, urtTypeName, urtAssemblyName);
- InteropXmlTypeEntries.Add(ixte);
- }
-
- internal void AddPreLoadEntry(string typeName, string assemblyName)
- {
- TryToLoadTypeIfApplicable(typeName, assemblyName);
- PreLoadEntry ple = new PreLoadEntry(typeName, assemblyName);
- PreLoadEntries.Add(ple);
- }
-
- internal RemoteAppEntry AddRemoteAppEntry(string appUri)
- {
- RemoteAppEntry rae = new RemoteAppEntry(appUri);
- RemoteAppEntries.Add(rae);
- return rae;
- }
-
- internal void AddServerActivatedEntry(string typeName, string assemName, ArrayList contextAttributes)
- {
- TryToLoadTypeIfApplicable(typeName, assemName);
- TypeEntry te = new TypeEntry(typeName, assemName, contextAttributes);
- ServerActivatedEntries.Add(te);
- }
-
- internal ServerWellKnownEntry AddServerWellKnownEntry(string typeName, string assemName, ArrayList contextAttributes, string objURI, WellKnownObjectMode objMode)
- {
- TryToLoadTypeIfApplicable(typeName, assemName);
- ServerWellKnownEntry swke = new ServerWellKnownEntry(typeName, assemName, contextAttributes, objURI, objMode);
- ServerWellKnownEntries.Add(swke);
- return swke;
- }
-
-
-
- private void TryToLoadTypeIfApplicable(string typeName, string assemblyName)
- {
- if (!LoadTypes)
- return;
-
- Assembly asm = Assembly.Load(assemblyName);
- if (asm == null) {
- throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_AssemblyLoadFailed"), assemblyName));
- }
-
- Type type = asm.GetType(typeName, false, false);
- if (type == null) {
- throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), typeName));
- }
- }
-
- }
-
-
-
-
- static internal class RemotingXmlConfigFileParser
- {
-
- private static Hashtable _channelTemplates = CreateSyncCaseInsensitiveHashtable();
- private static Hashtable _clientChannelSinkTemplates = CreateSyncCaseInsensitiveHashtable();
- private static Hashtable _serverChannelSinkTemplates = CreateSyncCaseInsensitiveHashtable();
-
-
- private static Hashtable CreateSyncCaseInsensitiveHashtable()
- {
- return Hashtable.Synchronized(CreateCaseInsensitiveHashtable());
- }
-
- private static Hashtable CreateCaseInsensitiveHashtable()
- {
- return new Hashtable(StringComparer.InvariantCultureIgnoreCase);
- }
-
-
- public static RemotingXmlConfigFileData ParseDefaultConfiguration()
- {
- ConfigNode node;
-
-
- ConfigNode rootNode = new ConfigNode("system.runtime.remoting", null);
-
-
-
- ConfigNode appNode = new ConfigNode("application", rootNode);
- rootNode.Children.Add(appNode);
-
- ConfigNode channelsNode = new ConfigNode("channels", appNode);
- appNode.Children.Add(channelsNode);
-
- node = new ConfigNode("channel", appNode);
- node.Attributes.Add(new DictionaryEntry("ref", "http client"));
- node.Attributes.Add(new DictionaryEntry("displayName", "http client (delay loaded)"));
- node.Attributes.Add(new DictionaryEntry("delayLoadAsClientChannel", "true"));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", appNode);
- node.Attributes.Add(new DictionaryEntry("ref", "tcp client"));
- node.Attributes.Add(new DictionaryEntry("displayName", "tcp client (delay loaded)"));
- node.Attributes.Add(new DictionaryEntry("delayLoadAsClientChannel", "true"));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", appNode);
- node.Attributes.Add(new DictionaryEntry("ref", "ipc client"));
- node.Attributes.Add(new DictionaryEntry("displayName", "ipc client (delay loaded)"));
- node.Attributes.Add(new DictionaryEntry("delayLoadAsClientChannel", "true"));
- channelsNode.Children.Add(node);
-
-
-
- channelsNode = new ConfigNode("channels", rootNode);
- rootNode.Children.Add(channelsNode);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "http"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Http.HttpChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "http client"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Http.HttpClientChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "http server"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Http.HttpServerChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "tcp"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Tcp.TcpChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "tcp client"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Tcp.TcpClientChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "tcp server"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Tcp.TcpServerChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "ipc"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Ipc.IpcChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "ipc client"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Ipc.IpcClientChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
- node = new ConfigNode("channel", channelsNode);
- node.Attributes.Add(new DictionaryEntry("id", "ipc server"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.Ipc.IpcServerChannel, " + AssemblyRef.SystemRuntimeRemoting));
- channelsNode.Children.Add(node);
-
-
-
- ConfigNode channelsSinkNode = new ConfigNode("channelSinkProviders", rootNode);
- rootNode.Children.Add(channelsSinkNode);
-
- ConfigNode clientProvidersNode = new ConfigNode("clientProviders", channelsSinkNode);
- channelsSinkNode.Children.Add(clientProvidersNode);
-
- node = new ConfigNode("formatter", clientProvidersNode);
- node.Attributes.Add(new DictionaryEntry("id", "soap"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.SoapClientFormatterSinkProvider, " + AssemblyRef.SystemRuntimeRemoting));
- clientProvidersNode.Children.Add(node);
-
- node = new ConfigNode("formatter", clientProvidersNode);
- node.Attributes.Add(new DictionaryEntry("id", "binary"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.BinaryClientFormatterSinkProvider, " + AssemblyRef.SystemRuntimeRemoting));
- clientProvidersNode.Children.Add(node);
-
- ConfigNode serverProvidersNode = new ConfigNode("serverProviders", channelsSinkNode);
- channelsSinkNode.Children.Add(serverProvidersNode);
-
- node = new ConfigNode("formatter", serverProvidersNode);
- node.Attributes.Add(new DictionaryEntry("id", "soap"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.SoapServerFormatterSinkProvider, " + AssemblyRef.SystemRuntimeRemoting));
- serverProvidersNode.Children.Add(node);
-
- node = new ConfigNode("formatter", serverProvidersNode);
- node.Attributes.Add(new DictionaryEntry("id", "binary"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider, " + AssemblyRef.SystemRuntimeRemoting));
- serverProvidersNode.Children.Add(node);
-
- node = new ConfigNode("provider", serverProvidersNode);
- node.Attributes.Add(new DictionaryEntry("id", "wsdl"));
- node.Attributes.Add(new DictionaryEntry("type", "System.Runtime.Remoting.MetadataServices.SdlChannelSinkProvider, " + AssemblyRef.SystemRuntimeRemoting));
- serverProvidersNode.Children.Add(node);
-
- return ParseConfigNode(rootNode);
- }
-
-
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
- public static RemotingXmlConfigFileData ParseConfigFile(string filename)
- {
- ConfigTreeParser parser = new ConfigTreeParser();
- ConfigNode rootNode = parser.Parse(filename, "/configuration/system.runtime.remoting");
-
- return ParseConfigNode(rootNode);
- }
-
- private static RemotingXmlConfigFileData ParseConfigNode(ConfigNode rootNode)
- {
- RemotingXmlConfigFileData configData = new RemotingXmlConfigFileData();
-
-
- if (rootNode == null)
- return null;
-
-
- foreach (DictionaryEntry entry in rootNode.Attributes) {
- string key = entry.Key.ToString();
- switch (key) {
- case "version":
-
- {
-
-
- break;
- }
- break;
- default:
-
- break;
- }
-
- }
-
- ConfigNode appNode = null;
-
- ConfigNode channelsNode = null;
-
- ConfigNode providerNode = null;
-
- ConfigNode debugNode = null;
-
- ConfigNode customErrorsNode = null;
-
- foreach (ConfigNode node in rootNode.Children) {
- switch (node.Name) {
- case "application":
-
-
- {
-
- if (appNode != null)
- ReportUniqueSectionError(rootNode, appNode, configData);
-
- appNode = node;
- break;
- }
- break;
- case "channels":
-
-
- {
- if (channelsNode != null)
- ReportUniqueSectionError(rootNode, channelsNode, configData);
-
- channelsNode = node;
- break;
- }
- break;
- case "channelSinkProviders":
-
-
- {
- if (providerNode != null)
- ReportUniqueSectionError(rootNode, providerNode, configData);
-
- providerNode = node;
- break;
- }
- break;
- case "debug":
-
-
- {
- if (debugNode != null)
- ReportUniqueSectionError(rootNode, debugNode, configData);
-
- debugNode = node;
- break;
- }
- break;
- case "customErrors":
-
-
- {
- if (customErrorsNode != null)
- ReportUniqueSectionError(rootNode, customErrorsNode, configData);
-
- customErrorsNode = node;
- break;
- }
- break;
- default:
-
- break;
- }
-
- }
-
-
- if (debugNode != null)
- ProcessDebugNode(debugNode, configData);
-
- if (providerNode != null)
- ProcessChannelSinkProviderTemplates(providerNode, configData);
-
- if (channelsNode != null)
- ProcessChannelTemplates(channelsNode, configData);
-
- if (appNode != null)
- ProcessApplicationNode(appNode, configData);
-
- if (customErrorsNode != null)
- ProcessCustomErrorsNode(customErrorsNode, configData);
-
- return configData;
- }
-
-
- private static void ReportError(string errorStr, RemotingXmlConfigFileData configData)
- {
-
- throw new RemotingException(errorStr);
- }
-
-
- private static void ReportUniqueSectionError(ConfigNode parent, ConfigNode child, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_NodeMustBeUnique"), child.Name, parent.Name), configData);
- }
-
- private static void ReportUnknownValueError(ConfigNode node, string value, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_UnknownValue"), node.Name, value), configData);
- }
-
- private static void ReportMissingAttributeError(ConfigNode node, string attributeName, RemotingXmlConfigFileData configData)
- {
- ReportMissingAttributeError(node.Name, attributeName, configData);
- }
-
- private static void ReportMissingAttributeError(string nodeDescription, string attributeName, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_RequiredXmlAttribute"), nodeDescription, attributeName), configData);
- }
-
- private static void ReportMissingTypeAttributeError(ConfigNode node, string attributeName, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_MissingTypeAttribute"), node.Name, attributeName), configData);
- }
-
- private static void ReportMissingXmlTypeAttributeError(ConfigNode node, string attributeName, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_MissingXmlTypeAttribute"), node.Name, attributeName), configData);
- }
-
- private static void ReportInvalidTimeFormatError(string time, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_InvalidTimeFormat"), time), configData);
- }
-
-
-
- private static void ReportNonTemplateIdAttributeError(ConfigNode node, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_NonTemplateIdAttribute"), node.Name), configData);
- }
-
- private static void ReportTemplateCannotReferenceTemplateError(ConfigNode node, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_TemplateCannotReferenceTemplate"), node.Name), configData);
- }
-
- private static void ReportUnableToResolveTemplateReferenceError(ConfigNode node, string referenceName, RemotingXmlConfigFileData configData)
- {
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_UnableToResolveTemplate"), node.Name, referenceName), configData);
- }
-
- private static void ReportAssemblyVersionInfoPresent(string assemName, string entryDescription, RemotingXmlConfigFileData configData)
- {
-
- ReportError(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Config_VersionPresent"), assemName, entryDescription), configData);
- }
-