public static List<ConfigInfo> GetConfigsFromElement(XmlNode root, string xmlnode, Type defaultType) { List<ConfigInfo> configs = new List<ConfigInfo> (); foreach (XmlElement node in root.SelectNodes(xmlnode)) { ConfigInfo configInfo = null; XmlAttribute attrType = node.Attributes ["type"]; if (attrType != null && !String.IsNullOrEmpty (attrType.Value)) { Type t = Type.GetType (attrType.Value); if (t == null) { Logger.Write (LogLevel.Error, "Could not load type '{0}' from node '{1}'. Skipping. ", attrType.Value, node.Name, defaultType); continue; } configInfo = new ConfigInfo () { Type = t }; object[] attrs = t.GetCustomAttributes (typeof(ConfigAttribute), false); if (attrs != null && attrs.Length > 0) { configInfo.Config = GetConfigFromElement (((ConfigAttribute)attrs [0]).Type, node); } else { configInfo.Config = GetConfigFromElement (defaultType, node); } } if (configInfo == null) { configInfo = new ConfigInfo () { Type = null, Config = GetConfigFromElement (defaultType, node) }; } //special thing for 'listener' node if (node.Name == "listener") { List<ConfigInfo> transports = GetConfigsFromElement (node, "listener-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.ListenerTransport = transports [0]; } transports = GetConfigsFromElement (node, "apphost-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.AppHostTransport = transports [0]; } } configs.Add (configInfo); } return configs; }
public static List <ConfigInfo> GetConfigsFromElement(XmlNode root, string xmlnode, Type defaultType) { List <ConfigInfo> configs = new List <ConfigInfo> (); foreach (XmlElement node in root.SelectNodes(xmlnode)) { ConfigInfo configInfo = null; XmlAttribute attrType = node.Attributes ["type"]; if (attrType != null && !String.IsNullOrEmpty(attrType.Value)) { Type t = Type.GetType(attrType.Value); if (t == null) { Logger.Write(LogLevel.Error, "Could not load type '{0}' from node '{1}'. Skipping. ", attrType.Value, node.Name, defaultType); continue; } configInfo = new ConfigInfo() { Type = t }; object[] attrs = t.GetCustomAttributes(typeof(ConfigAttribute), false); if (attrs != null && attrs.Length > 0) { configInfo.Config = GetConfigFromElement(((ConfigAttribute)attrs [0]).Type, node); } else { configInfo.Config = GetConfigFromElement(defaultType, node); } } if (configInfo == null) { configInfo = new ConfigInfo() { Type = null, Config = GetConfigFromElement(defaultType, node) }; } //special thing for 'listener' node if (node.Name == "listener") { List <ConfigInfo> transports = GetConfigsFromElement(node, "listener-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.ListenerTransport = transports [0]; } transports = GetConfigsFromElement(node, "apphost-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.AppHostTransport = transports [0]; } var listenerConfig = configInfo.Config as ListenerConfig; if (listenerConfig != null) { var address = listenerConfig.Address; var perm = listenerConfig.Permission.ToString(); if (!string.IsNullOrEmpty(address) && address.StartsWith("//") && address.Contains("@")) { var arr = address.Split('@'); perm = arr[0].Trim('/'); listenerConfig.Address = arr[1]; } listenerConfig.Permission = Convert.ToInt32(perm, 8); } } configs.Add(configInfo); } return(configs); }
public static List <ConfigInfo> GetConfigsFromElement(XmlNode root, string xmlnode, Type defaultType) { List <ConfigInfo> configs = new List <ConfigInfo> (); foreach (XmlElement node in root.SelectNodes(xmlnode)) { ConfigInfo configInfo = null; XmlAttribute attrType = node.Attributes ["type"]; if (attrType != null && !String.IsNullOrEmpty(attrType.Value)) { Type t = Type.GetType(attrType.Value); if (t == null) { Logger.Write(LogLevel.Error, "Could not load type '{0}' from node '{1}'. Skipping. ", attrType.Value, node.Name, defaultType); continue; } configInfo = new ConfigInfo() { Type = t }; object[] attrs = t.GetCustomAttributes(typeof(ConfigAttribute), false); if (attrs != null && attrs.Length > 0) { configInfo.Config = GetConfigFromElement(((ConfigAttribute)attrs [0]).Type, node); } else { configInfo.Config = GetConfigFromElement(defaultType, node); } } if (configInfo == null) { configInfo = new ConfigInfo() { Type = null, Config = GetConfigFromElement(defaultType, node) }; } //special thing for 'listener' node if (node.Name == "listener") { List <ConfigInfo> transports = GetConfigsFromElement(node, "listener-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.ListenerTransport = transports [0]; } transports = GetConfigsFromElement(node, "apphost-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.AppHostTransport = transports [0]; } } configs.Add(configInfo); } return(configs); }
public static List<ConfigInfo> GetConfigsFromElement(XmlNode root, string xmlnode, Type defaultType) { List<ConfigInfo> configs = new List<ConfigInfo> (); foreach (XmlElement node in root.SelectNodes(xmlnode)) { ConfigInfo configInfo = null; XmlAttribute attrType = node.Attributes ["type"]; if (attrType != null && !String.IsNullOrEmpty (attrType.Value)) { Type t = Type.GetType (attrType.Value); if (t == null) { Logger.Write (LogLevel.Error, "Could not load type '{0}' from node '{1}'. Skipping. ", attrType.Value, node.Name, defaultType); continue; } configInfo = new ConfigInfo () { Type = t }; object[] attrs = t.GetCustomAttributes (typeof(ConfigAttribute), false); if (attrs != null && attrs.Length > 0) { configInfo.Config = GetConfigFromElement (((ConfigAttribute)attrs [0]).Type, node); } else { configInfo.Config = GetConfigFromElement (defaultType, node); } } if (configInfo == null) { configInfo = new ConfigInfo () { Type = null, Config = GetConfigFromElement (defaultType, node) }; } //special thing for 'listener' node if (node.Name == "listener") { List<ConfigInfo> transports = GetConfigsFromElement (node, "listener-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.ListenerTransport = transports [0]; } transports = GetConfigsFromElement (node, "apphost-transport", typeof(TransportConfig)); if (transports != null && transports.Count > 0) { configInfo.AppHostTransport = transports [0]; } var listenerConfig = configInfo.Config as ListenerConfig; if (listenerConfig != null) { var address = listenerConfig.Address; var perm = listenerConfig.Permission.ToString(); if (!string.IsNullOrEmpty(address) && address.StartsWith("//") && address.Contains("@")) { var arr = address.Split('@'); perm = arr[0].Trim('/'); listenerConfig.Address = arr[1]; } listenerConfig.Permission = Convert.ToInt32(perm, 8); } } configs.Add (configInfo); } return configs; }