using System; using System.Xml; using System.Reflection; using Ease.CoreV35.Model; using Ease.CoreV35.Utility; using System.Runtime.Remoting; using System.Collections.Generic; namespace Ease.SvcHost { public class HostConfig : ConfigElementTemplate { private int _port; private CustomErrorsModes _errorModes; private List _containers = new List(); public IList Containers { get { return _containers.AsReadOnly(); } } public int Port { get { return _port; } } public CustomErrorsModes ErrorModes { get { return _errorModes; } } public static HostConfig GetConfig() { return GetConfig("Ease.svcHost"); } protected override void Parse(XmlElement node) { this.CheckRequiredAttributes(node, "port"); if (!int.TryParse(node.GetAttribute("port"), out _port)) RaiseError(node, "Invalid value for attribute port: {0}", node.GetAttribute("port")); string errorMode = node.GetAttribute("errorMode"); if (string.IsNullOrEmpty(errorMode)) _errorModes = CustomErrorsModes.Off; else if (Enum.IsDefined(typeof(CustomErrorsModes), errorMode)) _errorModes = (CustomErrorsModes)Enum.Parse(typeof(CustomErrorsModes), errorMode); base.AddChildren(node, "containers", _containers); } public class ContainersNode : ConfigChildElementTemplate { private Assembly _assembly; private WellKnownObjectMode _activationMode; private List _types = new List(); private List _finalizers = new List(); private List _initializers = new List(); public WellKnownObjectMode ActivationMode { get { return _activationMode; } } public IList Types { get { return _types; } } public Assembly Assembly { get { return _assembly; } } public IList Initializers { get { return _initializers; } } public IList Finalizers { get { return _finalizers; } } protected override void Parse(XmlElement node) { this.CheckRequiredAttributes(node, "assembly"); _assembly = Assembly.Load(node.GetAttribute("assembly")); this.AddChildren(node, "initializer", _initializers); this.AddChildren(node, "finalizer", _finalizers); this.CheckRequiredAttributes(node, "activation"); string activation = node.GetAttribute("activation"); if (!Enum.IsDefined(typeof(WellKnownObjectMode), activation)) RaiseError(node, "Invalid value :{0} for activation (expecting SingleCall or Singleton)", activation); _activationMode = (WellKnownObjectMode)Enum.Parse(typeof(WellKnownObjectMode), activation); foreach (Type type in _assembly.GetTypes()) { if (type.IsMarshalByRef && type.BaseType == typeof(ServiceTemplate)) _types.Add(type); } } } public class MethodNode : ConfigChildElementTemplate { private MethodInfo _method; public MethodInfo Method { get { return _method; } } protected override void Parse(XmlElement node) { CheckRequiredAttributes(node, "type", "method"); string typeName = node.GetAttribute("type") + "," + _parent.Assembly.FullName; Type type = Type.GetType(typeName); if (type == null) RaiseError(node, "Type not found: {0}", typeName); _method = type.GetMethod(node.GetAttribute("method"), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); if (_method == null) RaiseError(node, "Specified (static) method not found: {0}.{1}()", type.FullName, node.GetAttribute("method")); } } } }