private static Dictionary <string, string> LoadSettings(string domainName) { string filePath = Path.Combine(s_BaseFolderPath, domainName + ".config"); if (!File.Exists(filePath)) { throw new FileNotFoundException("Can't find the AppSettings config file: " + filePath + "!"); } domainName = domainName.ToUpper(); Dictionary <string, string> rst = new Dictionary <string, string>(); XElement doc = XElement.Load(filePath); foreach (var x in doc.Descendants("add")) { if (x.Attribute("key") == null || x.Attribute("key").Value == null || x.Attribute("key").Value.Trim().Length <= 0) { throw new ApplicationException("There are some 'add' node without attribute 'key' in the AppSettings config file: " + filePath + ", please check it!"); } string key = x.Attribute("key").Value.Trim().ToUpper(); if (rst.ContainsKey(key)) { throw new ApplicationException("Duplicated value '" + x.Attribute("key").Value.Trim() + "' of attribute 'key' in 'add' node in the AppSettings config file: " + filePath + ", please check it (ex: ignore case)!"); } string value = x.Attribute("value") == null ? null : (x.Attribute("value").Value == null ? null : x.Attribute("value").Value.Trim()); value = value ?? x.Value; rst.Add(key, EnvironmentVariableManager.ReplaceVariable(value)); } return(rst); }
private static Dictionary <string, CodeNamePairList> LoadConfigFile(string domainName, string languageCode) { string getFullConfigPath = Path.Combine(CodeNamePairSection.GetSetting().BaseAbsoluteFolder, domainName + "." + languageCode + ".config"); if (!File.Exists(getFullConfigPath)) { throw new FileNotFoundException("Can't find the CodeNamePair config file: " + getFullConfigPath + "!"); } Tuple <string, string> defaultAppendItem; CodeNamePairSection.GetSetting().AppendItems.TryGetValue(languageCode.ToUpper(), out defaultAppendItem); Dictionary <string, CodeNamePairList> rst = new Dictionary <string, CodeNamePairList>(); XElement doc = XElement.Load(getFullConfigPath); foreach (var x in doc.Descendants("codeNamePair")) { if (x.Attribute("key") == null || x.Attribute("key").Value == null || x.Attribute("key").Value.Trim().Length <= 0) { throw new ApplicationException("There are some 'codeNamePair' node without attribute 'key' in the CodeNamePair config file: " + getFullConfigPath + ", please check it!"); } string key = x.Attribute("key").Value.Trim().ToUpper(); if (rst.ContainsKey(key)) { throw new ApplicationException("Duplicated value '" + x.Attribute("key").Value.Trim() + "' of attribute 'key' in 'codeNamePair' node in the CodeNamePair config file: " + getFullConfigPath + ", please check it (ex: ignore case)!"); } CodeNamePairList v = new CodeNamePairList(); foreach (var listItem in x.Descendants("item")) { if (listItem.Attribute("code") != null && listItem.Attribute("code").Value != null && listItem.Attribute("code").Value.Trim().Length > 0) { string itemKey = listItem.Attribute("code").Value.Trim(); string itemText = listItem.Attribute("name") == null ? null : (listItem.Attribute("name").Value == null ? null : listItem.Attribute("name").Value.Trim()); v.Add(new KeyValuePair <string, string>(itemKey, EnvironmentVariableManager.ReplaceVariable(itemText))); } } var getCustomeAppendItem_SELECT = x.Attribute("selectAppendItem"); var getCustomeAppendItem_ALL = x.Attribute("allAppendItem"); if (null != getCustomeAppendItem_SELECT && getCustomeAppendItem_SELECT.Value != null && getCustomeAppendItem_SELECT.Value.Trim().Length > 0) { v.SelectAppendItem = getCustomeAppendItem_SELECT.Value.Trim(); } else if (defaultAppendItem != null && defaultAppendItem.Item1 != null && defaultAppendItem.Item1.Trim().Length > 0) { v.SelectAppendItem = defaultAppendItem.Item1.Trim(); } if (null != getCustomeAppendItem_ALL && getCustomeAppendItem_ALL.Value != null && getCustomeAppendItem_ALL.Value.Trim().Length > 0) { v.AllAppendItem = getCustomeAppendItem_ALL.Value; } else if (defaultAppendItem != null && defaultAppendItem.Item2 != null && defaultAppendItem.Item2.Trim().Length > 0) { v.AllAppendItem = defaultAppendItem.Item2.Trim(); } rst.Add(key, v); } return(rst); }