Example #1
0
        /// <summary>
        /// 从语言声明文件中获取支持的所有语言
        /// </summary>
        /// <returns>支持的所有语言的名称-值对</returns>
        public static NameValueCollection GetSupportedLanguages()
        {
            //CSContext csContext = CSContext.Current;
            HttpContext csContext = HttpContext.Current;
            string      cacheKey  = "SupportedLanguages";

            NameValueCollection supportedLanguages = CustomCache.Get(cacheKey) as NameValueCollection;

            if (supportedLanguages == null)
            {
                string          filePath = csContext.Server.MapPath("~/Languages/languages.xml");
                CacheDependency dp       = new CacheDependency(filePath);
                supportedLanguages = new NameValueCollection();

                XmlDocument d = new XmlDocument();
                d.Load(filePath);

                foreach (XmlNode n in d.SelectSingleNode("root").ChildNodes)
                {
                    if (n.NodeType != XmlNodeType.Comment)
                    {
                        supportedLanguages.Add(n.Attributes["key"].Value, n.Attributes["name"].Value);
                    }
                }
                CustomCache.Max(cacheKey, supportedLanguages, dp);
            }
            return(supportedLanguages);
        }
Example #2
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <param name="resourceType"></param>
        /// <param name="target"></param>
        /// <param name="language"></param>
        /// <param name="cacheKey"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private static Hashtable LoadResource(ResourceManagerType resourceType, Hashtable target, string language, string cacheKey, string fileName)
        {
            HttpContext csContext = HttpContext.Current;

            string filePath = csContext.Server.MapPath("~/Languages/" + language + "/" + fileName);

            //switch (resourceType)
            //{
            //    case ResourceManagerType.ErrorMessage:
            //        filePath = string.Format(filePath, "Messages.xml");
            //        break;

            //    default:
            //        filePath = string.Format(filePath, "Resources.xml");
            //        break;
            //}

            CacheDependency dp = new CacheDependency(filePath);

            XmlDocument d = new XmlDocument();

            try
            {
                d.Load(filePath);
            }
            catch
            {
                return(target);
            }
            foreach (XmlNode n in d.SelectSingleNode("root").ChildNodes)
            {
                if (n.NodeType != XmlNodeType.Comment)
                {
                    if (target[n.Attributes["name"].Value] == null)
                    {
                        target.Add(n.Attributes["name"].Value, n.InnerText);
                    }
                    else
                    {
                        target[n.Attributes["name"].Value] = n.InnerText;
                    }
                }
            }
            if (language == ResourceManager.defaultLanguage)
            {
                CustomCache.Max(cacheKey, target, dp);
            }
            else
            {
                CustomCache.Insert(cacheKey, target, dp, CustomCache.MinuteFactor * 5);
            }
            return(target);
        }
Example #3
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <param name="target"></param>
        /// <param name="cacheKey"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private static Hashtable LoadResource(Hashtable target, string cacheKey, string fileName)
        {
            HttpContext csContext = HttpContext.Current;

            string filePath = csContext.Server.MapPath("~/" + fileName);

            CacheDependency dp = new CacheDependency(filePath);

            Xd = new XmlDocument();
            try
            {
                Xd.Load(filePath);
            }
            catch
            {
                return(target);
            }
            target = getRuleDateInfo(Xd);
            CustomCache.Max(cacheKey, target, dp);
            return(target);
        }
Example #4
0
        /// <summary>
        /// 获取语言字符集
        /// </summary>
        /// <returns></returns>
        public static NameValueCollection GetLanguageCharsets()
        {
            HttpContext csContext = HttpContext.Current;
            string      cacheKey  = "LanguageCharsets";

            NameValueCollection languageCharsets = CustomCache.Get(cacheKey) as NameValueCollection;

            if (languageCharsets == null)
            {
                string          filePath = csContext.Server.MapPath("~/Languages/languages.xml");
                CacheDependency dp       = new CacheDependency(filePath);
                languageCharsets = new NameValueCollection();

                XmlDocument d = new XmlDocument();
                d.Load(filePath);

                foreach (XmlNode n in d.SelectSingleNode("root").ChildNodes)
                {
                    if (n.NodeType != XmlNodeType.Comment)
                    {
                        if (n.Attributes["emailCharset"] == null)
                        {
                            continue;
                        }
                        string codepage = n.Attributes["emailCharset"].Value;
                        if (n.Attributes["emailSubjectCharset"] != null)
                        {
                            codepage += "," + n.Attributes["emailSubjectCharset"].Value;
                        }

                        languageCharsets.Add(n.Attributes["key"].Value, codepage);
                    }
                }
                CustomCache.Max(cacheKey, languageCharsets, dp);
            }
            return(languageCharsets);
        }