Exemple #1
0
        private void LabelPropertiesFromXml(XDocument doc)
        {
            foreach (var propertyGroup in doc.XPathSelectElements("/Structure/PropertyGroups/PropertyGroup"))
            {
                var identity = propertyGroup.Attribute("identity").Value;

                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 with identity '{identity}' has no label attribute or nodes");
                }

                foreach (var label in labels)
                {
                    SubTagDictionary labelDic;
                    if (ContainsKey(label))
                    {
                        labelDic = this[label] as SubTagDictionary;
                        if (labelDic == null)
                        {
                            throw new InvalidDataException($"PropertyGroup with identity '{identity}' has a label specified that clashes with a property name. The conflicting label is {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);
                    }
                }
            }
        }
Exemple #2
0
        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);
                }
            }
        }