| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System;
- using System.Collections;
- using System.Globalization;
- using System.IO;
- using System.Resources;
- namespace Muchinfo.MTPClient.Resources
- {
- public class MuchInfoResourceManager : ResourceManager
- {
- private const string _defaultFileName = "Muchinfo.Resource.zh-CN.dll";
- private const string _defaultCultureName = "zh-CN";
- private const string _unKnownResource = "UnKnownResource";
- private const string _unfindResource = "UnFindResource";
- private static ResourceManager resourceMan;
- /// <summary>
- /// 用户资源
- /// </summary>
- private Hashtable _usershtable;
- public static ResourceManager ResourceManager
- {
- get
- {
- if (object.ReferenceEquals(resourceMan, null))
- {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Client.Resources.Client.Resource", typeof(Client_Resource).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
- public MuchInfoResourceManager()
- {
- _usershtable = new Hashtable();
- var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _defaultFileName);
- try
- {
- LoadResourceFiles(filePath, _defaultCultureName);
- }
- catch (Exception) //读取不到文件使用系统默认的
- {
- }
- }
- public MuchInfoResourceManager(string resourceFilePath)
- {
- _usershtable = new Hashtable();
- try
- {
- LoadResourceFiles(resourceFilePath, _defaultCultureName);
- }
- catch (Exception) //读取不到文件使用系统默认的
- {
- }
- }
- public void LoadResourceFiles(string resourceFile, string cultureName)
- {
- var reader = new ResourceReader(resourceFile);
- var resourceSet = new ResourceSet(reader);
- this._usershtable[cultureName] = resourceSet;
- }
- public override string GetString(string name)
- {
- var culture = new CultureInfo(_defaultCultureName);
- return GetString(name, culture);
- }
- public override string GetString(string name, CultureInfo culture)
- {
- string rescourceString = string.Empty;
- if (this._usershtable != null && this._usershtable.Count > 0)
- {
- if (culture == null)
- {
- culture = new CultureInfo(_defaultCultureName);
- }
- if (this._usershtable.Contains(culture.Name))
- {
- var resourceSets = this._usershtable[culture.Name] as ResourceSet;
- if (resourceSets != null)
- {
- try
- {
- rescourceString= resourceSets.GetString(name);
- }
- catch
- {
- //return ResourceManager.GetString(name, culture); ///系统默认的资源
- }
- }
- }
- //else
- //{
- // return ResourceManager.GetString(name, culture); ///系统默认的资源
- //}
- }
- if (string.IsNullOrWhiteSpace(rescourceString))
- {
- rescourceString= ResourceManager.GetString(name, culture);
- }
- return rescourceString;
- }
- }
- public partial class Client_Resource
- {
- private static bool _resourceLoaded = false;
- public static bool ResourceLoaded
- {
- get
- {
- return _resourceLoaded;
- }
- }
- public static void Resource(ResourceManager manager)
- {
- resourceMan = manager;
- _resourceLoaded = true;
- }
- }
- }
|