134 lines
4.6 KiB
C#
134 lines
4.6 KiB
C#
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<HostConfig>
|
|
{
|
|
private int _port;
|
|
private CustomErrorsModes _errorModes;
|
|
private List<ContainersNode> _containers = new List<ContainersNode>();
|
|
|
|
public IList<ContainersNode> 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<ContainersNode>(node, "containers", _containers);
|
|
}
|
|
|
|
public class ContainersNode : ConfigChildElementTemplate<ContainersNode, HostConfig>
|
|
{
|
|
private Assembly _assembly;
|
|
private WellKnownObjectMode _activationMode;
|
|
private List<Type> _types = new List<Type>();
|
|
private List<MethodNode> _finalizers = new List<MethodNode>();
|
|
private List<MethodNode> _initializers = new List<MethodNode>();
|
|
|
|
public WellKnownObjectMode ActivationMode
|
|
{
|
|
get { return _activationMode; }
|
|
}
|
|
|
|
public IList<Type> Types
|
|
{
|
|
get { return _types; }
|
|
}
|
|
|
|
public Assembly Assembly
|
|
{
|
|
get { return _assembly; }
|
|
}
|
|
|
|
public IList<MethodNode> Initializers
|
|
{
|
|
get { return _initializers; }
|
|
}
|
|
|
|
public IList<MethodNode> Finalizers
|
|
{
|
|
get { return _finalizers; }
|
|
}
|
|
|
|
protected override void Parse(XmlElement node)
|
|
{
|
|
this.CheckRequiredAttributes(node, "assembly");
|
|
_assembly = Assembly.Load(node.GetAttribute("assembly"));
|
|
|
|
this.AddChildren<MethodNode>(node, "initializer", _initializers);
|
|
this.AddChildren<MethodNode>(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<MethodNode, ContainersNode>
|
|
{
|
|
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"));
|
|
}
|
|
}
|
|
}
|
|
}
|