private void LabelPropertiesFromXml(XDocument doc) { foreach (var propertyGroup in doc.XPathSelectElements("/Structure/PropertyGroups/PropertyGroup")) { var labels = new List <string>(); if (propertyGroup.Attribute("label") != null) { labels.Add(propertyGroup.Attribute("label").Value); } else if (propertyGroup.XPathSelectElements(".//Label").Any()) { labels.AddRange(propertyGroup.XPathSelectElements(".//Label").Select(x => x.Value)); } else { throw new InvalidDataException("PropertyGroup found with no label attribute or nodes"); } var identity = propertyGroup.Attribute("identity").Value; foreach (var label in labels) { SubTagDictionary labelDic; if (ContainsKey(label)) { labelDic = this[label] as SubTagDictionary; if (labelDic == null) { throw new InvalidDataException(string.Format("A label for a method group has been specified that clashes with a property name. The conflicting label is {0}", label)); } } else { labelDic = new SubTagDictionary(); Add(label, labelDic); } Dictionary <string, object> instanceDic; if (labelDic.ContainsKey(identity)) { instanceDic = labelDic[identity] as Dictionary <string, object>; } else { instanceDic = new Dictionary <string, object> { { "identity", identity } }; labelDic.Add(identity, instanceDic); } foreach (var prop in propertyGroup.XPathSelectElements(".//Property")) { var key = prop.Attribute("name").Value; var value = prop.Value.Trim(); instanceDic.AddOrDiscard(key, value); } } } }
private void DbLoginPropertiesFromXml(XDocument doc) { var dbLoginElements = doc.XPathSelectElements("/Structure/DbLogins/DbLogin"); foreach (var dbLoginElement in dbLoginElements) { var username = dbLoginElement.XPathSelectElement("Name").Value; string dbKey; if (dbLoginElement.XPathSelectElement("Key") != null && !string.IsNullOrWhiteSpace(dbLoginElement.XPathSelectElement("Key").Value)) { dbKey = dbLoginElement.XPathSelectElement("Key").Value; } else { dbKey = username.StartsWith("tagClientCode-tagEnvironment-") ? username.Substring(29) : username; } SubTagDictionary dbLogins; if (ContainsKey("DbLogins")) { dbLogins = this["DbLogins"] as SubTagDictionary; } else { dbLogins = new SubTagDictionary(); Add("DbLogins", dbLogins); } if (!dbLogins.ContainsKey(dbKey)) { var dbLoginDic = new Dictionary <string, object> { { "Username", username } }; if (string.IsNullOrWhiteSpace(dbLoginElement.TryXPathValueWithDefault("ConnectionString", ""))) { dbLoginDic.Add("Password", dbLoginElement.XPathSelectElement("Password").Value); dbLoginDic.Add("DefaultDb", dbLoginElement.XPathSelectElement("DefaultDb").Value); dbLoginDic.Add("ConnectionString", string.Format("Data Source={{{{ DbServer }}}}; Initial Catalog={0}; User ID={1}; Password={2};", dbLoginElement.XPathSelectElement("DefaultDb").Value, username, dbLoginElement.XPathSelectElement("Password").Value)); } else { dbLoginDic.Add("ConnectionString", dbLoginElement.XPathSelectElement("ConnectionString").Value); } dbLogins.Add(dbKey, dbLoginDic); } } }
private void LabelPropertiesFromXml(XDocument doc) { var labelledGroups = doc.XPathSelectElements("/Structure/PropertyGroups/PropertyGroup").Where(pg => pg.Elements().Select(e => e.Name).Contains("Label")); foreach (var labelledGroup in labelledGroups) { var labels = labelledGroup.Elements("Label").Select(e => e.Value); var identity = labelledGroup.Attribute("identity").Value; foreach (var label in labels) { SubTagDictionary labelDic; if (ContainsKey(label)) { labelDic = this[label] as SubTagDictionary; if (labelDic == null) { throw new InvalidDataException(string.Format("A label for a method group has been specified that clashes with a property name. The conflicting label is {0}", label)); } } else { labelDic = new SubTagDictionary(); Add(label, labelDic); } Dictionary <string, object> instanceDic; if (labelDic.ContainsKey(identity)) { instanceDic = labelDic[identity] as Dictionary <string, object>; } else { instanceDic = new Dictionary <string, object> { { "identity", identity } }; labelDic.Add(identity, instanceDic); } foreach (var prop in labelledGroup.XPathSelectElements("Properties/Property")) { var key = prop.Attribute("name").Value; var value = prop.Value.Trim(); instanceDic.AddOrDiscard(key, value); } } } }