Esempio n. 1
0
        /// <summary>
        /// 获取默认的附加项(“请选择”和“所有”)的配置数据,对应web.config中codeNamePair节点下的appendItems的对应语言的配置(根据当前线程获取LanguageCode)
        /// </summary>
        /// <param name="appendSelectItem">“请选择”附加项的配置数据</param>
        /// <param name="appendAllItem">“所有”附加项的配置数据</param>
        public static void GetDefaultAppendItem(out CodeNamePair appendSelectItem, out CodeNamePair appendAllItem)
        {
            Tuple <string, string> defaultAppendItem;

            CodeNamePairSection.GetSetting().AppendItems.TryGetValue(Thread.CurrentThread.CurrentCulture.Name.ToUpper(), out defaultAppendItem);

            if (defaultAppendItem != null && defaultAppendItem.Item1 != null && defaultAppendItem.Item1.Trim().Length > 0)
            {
                appendSelectItem = new CodeNamePair {
                    Code = null, Name = defaultAppendItem.Item1.Trim()
                };
            }
            else
            {
                appendSelectItem = null;
            }

            if (defaultAppendItem != null && defaultAppendItem.Item2 != null && defaultAppendItem.Item2.Trim().Length > 0)
            {
                appendAllItem = new CodeNamePair {
                    Code = null, Name = defaultAppendItem.Item2.Trim()
                };
            }
            else
            {
                appendAllItem = null;
            }
        }
Esempio n. 2
0
        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);
        }