⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcemanager.cs

📁 Freetextbox是优秀的在线编辑器
💻 CS
字号:
namespace FreeTextBoxControls.Support
{
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.IO;
    using System.Web;
    using System.Web.Caching;
    using System.Xml;

    public class ResourceManager
    {
        public ResourceManager() : this("en-US", "~/aspnet_client/FreeTextBox/Languages/")
        {
        }

        public ResourceManager(string language, string path)
        {
            this.resourceFailures = 0;
            this.language = language;
            this.path = path.Replace("/", @"\");
        }

        private Hashtable GetResources()
        {
            string text1 = "en-US";
            string text2 = this.language;
            string text3 = "FreeTextBox-" + text1 + "-" + text2;
            if (text2 == "")
            {
                text2 = text1;
            }
            if (HttpContext.Current.Cache[text3] == null)
            {
                Hashtable hashtable1 = new Hashtable();
                this.LoadResource(hashtable1, text1, text3);
                if (text1 != text2)
                {
                    this.LoadResource(hashtable1, text2, text3);
                }
            }
            return (Hashtable) HttpContext.Current.Cache[text3];
        }

        public string GetString(string name)
        {
            Hashtable hashtable1 = this.GetResources();
            if (hashtable1 == null)
            {
                if (this.resourceFailures >= 2)
                {
                    throw new Exception("The resources have failed.");
                }
                return this.GetString(name);
            }
            if (hashtable1[name] == null)
            {
                throw new Exception("Value not found in original en-US.xml for: " + name);
            }
            return (string) hashtable1[name];
        }

        public NameValueCollection GetSupportedLanguages()
        {
            string text1 = "FreeTextBoxControls.Resources.Languages.Languages.xml";
            NameValueCollection collection1 = new NameValueCollection();
            Stream stream1 = base.GetType().Assembly.GetManifestResourceStream(text1);
            XmlDocument document1 = new XmlDocument();
            document1.Load(stream1);
            foreach (XmlNode node1 in document1.SelectSingleNode("root").ChildNodes)
            {
                if (node1.NodeType != XmlNodeType.Comment)
                {
                    collection1.Add(node1.Attributes["name"].Value, node1.Attributes["key"].Value);
                }
            }
            return collection1;
        }

        private void LoadResource(Hashtable target, string language, string cacheKey)
        {
            XmlDocument document1 = new XmlDocument();
            CacheDependency dependency1 = null;
            string text1 = "FreeTextBoxControls.Resources.Languages." + language + ".xml";
            if ((language.ToLower() != "en-us") || (target.Count > 0))
            {
                try
                {
                    string text2 = HttpContext.Current.Server.MapPath(this.path + language + ".xml");
                    document1.Load(text2);
                    dependency1 = new CacheDependency(text2);
                }
                catch (Exception)
                {
                }
            }
            if ((document1 == null) || (document1.SelectSingleNode("root") == null))
            {
                Stream stream1 = base.GetType().Assembly.GetManifestResourceStream(text1);
                if (stream1 != null)
                {
                    document1.Load(stream1);
                }
                stream1.Close();
            }
            if ((document1 != null) && (document1.SelectSingleNode("root") != null))
            {
                try
                {
                    foreach (XmlNode node1 in document1.SelectSingleNode("root").ChildNodes)
                    {
                        if (node1.NodeType != XmlNodeType.Comment)
                        {
                            if (target[node1.Attributes["name"].Value] == null)
                            {
                                target.Add(node1.Attributes["name"].Value, node1.InnerText);
                            }
                            else
                            {
                                target[node1.Attributes["name"].Value] = node1.InnerText;
                            }
                        }
                    }
                }
                catch
                {
                    throw new Exception("FTB cannot load the resource: " + language + ". File exists: " + this.path + language + ".xml. Resource: " + text1);
                }
                if (dependency1 != null)
                {
                    HttpContext.Current.Cache.Insert(cacheKey, target, dependency1, DateTime.MaxValue, TimeSpan.Zero);
                }
                else
                {
                    HttpContext.Current.Cache.Insert(cacheKey, target, null, DateTime.MaxValue, new TimeSpan(1, 0, 0, 0, 0));
                }
            }
        }


        public string Language
        {
            get
            {
                return this.language;
            }
            set
            {
                this.language = value;
            }
        }

        public string Path
        {
            get
            {
                return this.path;
            }
            set
            {
                this.path = value;
            }
        }


        private string language;
        private string path;
        private int resourceFailures;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -