ResourceManagerWrapper.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //------------------------------------------------------------
  2. // All Rights Reserved , Copyright (C) 2010 , Jirisoft , Ltd.
  3. //------------------------------------------------------------
  4. using System;
  5. using System.Collections;
  6. namespace Ant.Service.Utilities
  7. {
  8. /// <summary>
  9. /// ResourceManagerWrapper
  10. /// 资源管理器
  11. ///
  12. /// 修改纪录
  13. /// 2007.05.16 版本:1.0 JiRiGaLa 重新调整代码的规范化。
  14. ///
  15. /// 版本:1.0
  16. ///
  17. /// <author>
  18. /// <name>JiRiGaLa</name>
  19. /// <date>2007.05.16</date>
  20. /// </author>
  21. /// </summary>
  22. public class ResourceManagerWrapper
  23. {
  24. private volatile static ResourceManagerWrapper instance = null;
  25. private static object locker = new Object();
  26. private static string CurrentLanguage = "en-us";
  27. public static ResourceManagerWrapper Instance
  28. {
  29. get
  30. {
  31. if (instance == null)
  32. {
  33. lock (locker)
  34. {
  35. if (instance == null)
  36. {
  37. instance = new ResourceManagerWrapper();
  38. }
  39. }
  40. }
  41. return instance;
  42. }
  43. }
  44. private ResourceManager ResourceManager;
  45. public ResourceManagerWrapper()
  46. {
  47. }
  48. public void LoadResources(string path)
  49. {
  50. ResourceManager = ResourceManager.Instance;
  51. ResourceManager.Init(path);
  52. }
  53. public string Get(string key)
  54. {
  55. return ResourceManager.Get(CurrentLanguage, key);
  56. }
  57. public string Get(string lanauage, string key)
  58. {
  59. return ResourceManager.Get(lanauage, key);
  60. }
  61. public Hashtable GetLanguages()
  62. {
  63. return ResourceManager.GetLanguages();
  64. }
  65. public Hashtable GetLanguages(string path)
  66. {
  67. return ResourceManager.GetLanguages(path);
  68. }
  69. public void Serialize(string path, string language, string key, string value)
  70. {
  71. Resources Resources = this.GetResources(path, language);
  72. Resources.Set(key, value);
  73. string filePath = path + "\\" + language + ".xml";
  74. ResourceManager.Serialize(Resources, filePath);
  75. }
  76. public Resources GetResources(string path, string language)
  77. {
  78. string filePath = path + "\\" + language + ".xml";
  79. return ResourceManager.GetResources(filePath);
  80. }
  81. public Resources GetResources(string language)
  82. {
  83. return ResourceManager.LanguageResources[language];
  84. }
  85. }
  86. }