/// <exception cref="System.TypeLoadException" /> /// <exception cref="System.MemberAccessException" /> /// <exception cref="System.Reflection.TargetInvocationException" /> private void LoadFunctions(XmlElement root) { var list = root.GetElementsByTagName("function"); XmlNode node = null; XmlElement e = null; for (int i = 0, n = list.Count; i < n; i++) { node = list.Item(i); if (node.NodeType == XmlNodeType.Element) { e = (XmlElement)node; var name = e.GetAttribute("name"); if (functions.ContainsKey(name)) { throw new ConfigException("rule function " + name + " duplicated!"); } var clazz = e.GetAttribute("class"); var function = CreateFunction(name, clazz); ParameterMapping.Mapping(function, ConfigUtil.LoadElements(e)); functions[name] = function; } } }
/// <exception cref="System.MemberAccessException" /> /// <exception cref="System.Reflection.TargetInvocationException" /> private void LoadSystem(XmlElement root) { var list = root.GetElementsByTagName("system"); for (int i = 0, n = list.Count; i < n; i++) { var node = list.Item(i); if (node.NodeType != XmlNodeType.Element) { continue; } var props = ConfigUtil.LoadElements((XmlElement)node); ParameterMapping.Mapping(System, props); } }
private void LoadDataNodes(XmlElement root) { var list = root.GetElementsByTagName("dataNode"); XmlElement element = null; XmlElement dsElement = null; XmlNodeList dataSourceList = null; for (int i = 0, n = list.Count; i < n; i++) { element = (XmlElement)list.Item(i); var dnNamePrefix = element.GetAttribute("name"); IList <DataNodeConfig> confList = new List <DataNodeConfig>(); try { dsElement = FindPropertyByName(element, "dataSource"); if (dsElement == null) { throw new ArgumentNullException("dataNode xml XmlElement with name of " + dnNamePrefix + " has no dataSource Element"); } dataSourceList = dsElement.GetElementsByTagName("dataSourceRef"); var dataSources = new string[dataSourceList.Count][]; for (int j = 0, m = dataSourceList.Count; j < m; ++j) { var @ref = (XmlElement)dataSourceList.Item(j); var dsString = @ref.InnerText; dataSources[j] = SplitUtil.Split(dsString, ',', '$', '-', '[', ']'); } if (dataSources.Length <= 0) { throw new ConfigException("no dataSourceRef defined!"); } foreach (var dss in dataSources) { if (dss.Length != dataSources[0].Length) { throw new ConfigException("dataSource number not equals!"); } } for (int k = 0, limit = dataSources[0].Length; k < limit; ++k) { var dsString = new StringBuilder(); for (var dsIndex = 0; dsIndex < dataSources.Length; ++dsIndex) { if (dsIndex > 0) { dsString.Append(','); } dsString.Append(dataSources[dsIndex][k]); } var conf = new DataNodeConfig(); ParameterMapping.Mapping(conf, ConfigUtil.LoadElements(element)); confList.Add(conf); switch (k) { case 0: { conf.Name = limit == 1 ? dnNamePrefix : dnNamePrefix + "[" + k + "]"; break; } default: { conf.Name = dnNamePrefix + "[" + k + "]"; break; } } conf.DataSource = dsString.ToString(); } } catch (Exception e) { throw new ConfigException("dataNode " + dnNamePrefix + " define error", e); } foreach (var conf_1 in confList) { if (dataNodes.ContainsKey(conf_1.Name)) { throw new ConfigException("dataNode " + conf_1.Name + " duplicated!"); } dataNodes[conf_1.Name] = conf_1; } } }
private void LoadDataSources(XmlElement root) { var list = root.GetElementsByTagName("dataSource"); XmlElement element = null; XmlElement locElement = null; XmlNodeList locationList = null; for (int i = 0, n = list.Count; i < n; i++) { element = (XmlElement)list.Item(i); var dscList = new List <DataSourceConfig>(); var dsNamePrefix = element.GetAttribute("name"); try { var dsType = element.GetAttribute("type"); locElement = FindPropertyByName(element, "location"); if (locElement == null) { throw new ArgumentNullException("dataSource xml XmlElement with name of " + dsNamePrefix + " has no location Element"); } locationList = locElement.GetElementsByTagName("location"); var dsIndex = 0; for (int j = 0, m = locationList.Count; j < m; ++j) { var locStr = ((XmlElement)locationList.Item(j)).InnerText; var colonIndex = locStr.IndexOf(':'); var slashIndex = locStr.IndexOf('/'); var dsHost = Runtime.Substring(locStr, 0, colonIndex).Trim(); var dsPort = Convert.ToInt32(Runtime.Substring(locStr, colonIndex + 1, slashIndex).Trim()); var schemas = SplitUtil.Split(Runtime.Substring(locStr, slashIndex + 1).Trim(), ',', '$', '-'); foreach (var dsSchema in schemas) { var dsConf = new DataSourceConfig(); ParameterMapping.Mapping(dsConf, ConfigUtil.LoadElements(element)); dscList.Add(dsConf); switch (dsIndex) { case 0: { dsConf.Name = dsNamePrefix; break; } case 1: { dscList[0].Name = dsNamePrefix + "[0]"; goto default; } default: { dsConf.Name = dsNamePrefix + "[" + dsIndex + "]"; break; } } dsConf.Type = dsType; dsConf.Database = dsSchema; dsConf.Host = dsHost; dsConf.Port = dsPort; ++dsIndex; } } } catch (Exception e) { throw new ConfigException("dataSource " + dsNamePrefix + " define error", e); } foreach (var dsConf_1 in dscList) { if (dataSources.ContainsKey(dsConf_1.Name)) { throw new ConfigException("dataSource name " + dsConf_1.Name + "duplicated!"); } dataSources[dsConf_1.Name] = dsConf_1; } } }