static void ConfigFormatExtensionTypes(XmlNode section, WSConfig config) { if (section.Attributes != null && section.Attributes.Count != 0) { ThrowException("Unrecognized attribute", section); } XmlNodeList nodes = section.ChildNodes; foreach (XmlNode child in nodes) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "add") { string typeName = AttValue("name", child, false); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } try { config.FormatExtensionTypes.Add(Type.GetType(typeName, true)); } catch (Exception e) { ThrowException(e.Message, child); } continue; } ThrowException("Unexpected element", child); } }
static void ThrowException(string message, XmlNode node) { HandlersUtil.ThrowException(message, node); }
static string AttValue(string name, XmlNode node) { return(HandlersUtil.ExtractAttributeValue(name, node, true)); }
// To save some typing... static string AttValue(string name, XmlNode node, bool optional) { return(HandlersUtil.ExtractAttributeValue(name, node, optional)); }
static void ConfigProtocols(XmlNode section, WSConfig config) { if (section.Attributes != null && section.Attributes.Count != 0) { ThrowException("Unrecognized attribute", section); } XmlNodeList nodes = section.ChildNodes; foreach (XmlNode child in nodes) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { ThrowException("Only elements allowed", child); } string name = child.Name; string error; if (name == "add") { string protoName = AttValue("name", child, false); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } if (!config.AddProtocol(protoName, out error)) { ThrowException(error, child); } continue; } if (name == "remove") { string protoName = AttValue("name", child, false); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } if (!config.RemoveProtocol(protoName, out error)) { ThrowException(error, child); } continue; } if (name == "clear") { if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } config.ClearProtocol(); continue; } ThrowException("Unexpected element", child); } }
public object Create(object parent, object context, XmlNode section) { WSConfig config = new WSConfig(parent as WSConfig, context); if (section.Attributes != null && section.Attributes.Count != 0) { ThrowException("Unrecognized attribute", section); } XmlNodeList nodes = section.ChildNodes; foreach (XmlNode child in nodes) { XmlNodeType ntype = child.NodeType; if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment) { continue; } if (ntype != XmlNodeType.Element) { ThrowException("Only elements allowed", child); } string name = child.Name; if (name == "protocols") { ConfigProtocols(child, config); continue; } if (name == "soapExtensionTypes") { ConfigSoapExtensionTypes(child, config.ExtensionTypes); continue; } if (name == "soapExtensionReflectorTypes") { ConfigSoapExtensionTypes(child, config.ExtensionReflectorTypes); continue; } if (name == "soapExtensionImporterTypes") { ConfigSoapExtensionTypes(child, config.ExtensionImporterTypes); continue; } if (name == "serviceDescriptionFormatExtensionTypes") { ConfigFormatExtensionTypes(child, config); continue; } if (name == "wsdlHelpGenerator") { string href = AttValue("href", child, false); if (child.Attributes != null && child.Attributes.Count != 0) { HandlersUtil.ThrowException("Unrecognized attribute", child); } config.ConfigFilePath = context as string; config.WsdlHelpPage = href; continue; } ThrowException("Unexpected element", child); } return(config); }