ConstResxManager.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. //----------------------------------------------------------------
  8. //Module Name: $safeprojectname$
  9. //Purpose:
  10. //CopyRight: Muchinfo
  11. //History:
  12. //----------------------------------------------------------------
  13. //DateTime 2016/12/17 22:21:24
  14. //Author
  15. //Description Create
  16. //----------------------------------------------------------------
  17. using Muchinfo.PC.Common.Bosn;
  18. namespace Muchinfo.MTPClient.Resources
  19. {
  20. public class ConstResxManager
  21. {
  22. private const string _fileName = "ContResx.dll";
  23. public static CommonResx ConstResx { get; set; }
  24. /// <summary>
  25. /// 保存错误资源文件
  26. /// </summary>
  27. /// <param name="hastableResx"></param>
  28. /// <param name="ver"></param>
  29. public static void SaveCostResx(Hashtable hastableResx, ulong ver)
  30. {
  31. var resx = new CommonResx() {ResourceHashtable = hastableResx, Version = ver};
  32. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _fileName);
  33. JsonHelper.SaveData<CommonResx>(path, resx, null, true);
  34. }
  35. /// <summary>
  36. /// 获取 资源信息
  37. /// </summary>
  38. /// <returns></returns>
  39. public static CommonResx GetConstResx()
  40. {
  41. var resx = new CommonResx() {Version = 0};
  42. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _fileName);
  43. if (!File.Exists(path))
  44. return resx;
  45. return JsonHelper.LoadData<CommonResx>(path).FirstOrDefault();
  46. }
  47. public static string ConstDesc(string constKey)
  48. {
  49. if (ConstResx != null && ConstResx.ResourceHashtable != null &&
  50. ConstResx.ResourceHashtable.ContainsKey(constKey))
  51. {
  52. return ConstResx.ResourceHashtable[constKey] as string;
  53. }
  54. else
  55. {
  56. return Client_Resource.ResourceManager.GetString(constKey);
  57. }
  58. }
  59. /// <summary>
  60. /// 初始化错误资源
  61. /// </summary>
  62. public static void InitConstResx()
  63. {
  64. ConstResx = GetConstResx();
  65. }
  66. /// <summary>
  67. /// 保存并设置资源内容
  68. /// </summary>
  69. /// <param name="resxHashtable"></param>
  70. /// <param name="ver"></param>
  71. public static void ConstResxSaveRep(Hashtable resxHashtable, ulong ver)
  72. {
  73. ConstResx = new CommonResx() {ResourceHashtable = resxHashtable, Version = ver};
  74. SaveCostResx(resxHashtable, ver);
  75. }
  76. #region 数据存在UserData目录
  77. public static void InitConstResx(string filePath)
  78. {
  79. ConstResx = GetConstResx(filePath);
  80. }
  81. public static void ConstResxSaveRep(Hashtable resxHashtable, ulong ver, string filePath)
  82. {
  83. ConstResx = new CommonResx() { ResourceHashtable = resxHashtable, Version = ver };
  84. SaveCostResx(resxHashtable, ver, filePath);
  85. }
  86. private static void SaveCostResx(Hashtable hastableResx, ulong ver, string filePath)
  87. {
  88. string path = Path.Combine(filePath, _fileName);
  89. ResxManagerHelper.SaveData(hastableResx, ver, path);
  90. }
  91. private static CommonResx GetConstResx(string filePath)
  92. {
  93. string path = Path.Combine(filePath, _fileName);
  94. return ResxManagerHelper.GetData(path);
  95. }
  96. #endregion
  97. }
  98. }