DeliveryResxManager.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. using Muchinfo.PC.Common.Bosn;
  8. namespace Muchinfo.MTPClient.Resources
  9. {
  10. public class DeliveryResxManager
  11. {
  12. private const string _fileName = "DeliveryResx.dll";
  13. public static CommonResx DeliveryResx { get; set; }
  14. /// <summary>
  15. /// 保存错误资源文件
  16. /// </summary>
  17. /// <param name="hastableResx"></param>
  18. /// <param name="ver"></param>
  19. public static void SaveDeliveryResx(Hashtable hastableResx, ulong ver)
  20. {
  21. var resx = new CommonResx() { ResourceHashtable = hastableResx, Version = ver };
  22. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _fileName);
  23. JsonHelper.SaveData<CommonResx>(path, resx, null, true);
  24. }
  25. /// <summary>
  26. /// 获取 资源信息
  27. /// </summary>
  28. /// <returns></returns>
  29. public static CommonResx GetDeliveryResx()
  30. {
  31. var resx = new CommonResx() { Version = 0 };
  32. string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _fileName);
  33. if (!File.Exists(path))
  34. return resx;
  35. return JsonHelper.LoadData<CommonResx>(path).FirstOrDefault();
  36. }
  37. public static string DeliveryDesc(string constKey)
  38. {
  39. if (DeliveryResx != null && DeliveryResx.ResourceHashtable != null &&
  40. DeliveryResx.ResourceHashtable.ContainsKey(constKey))
  41. {
  42. return DeliveryResx.ResourceHashtable[constKey] as string;
  43. }
  44. else
  45. {
  46. return Client_Resource.ResourceManager.GetString(constKey);
  47. }
  48. }
  49. /// <summary>
  50. /// 初始化错误资源
  51. /// </summary>
  52. public static void InitDeliveryResx()
  53. {
  54. DeliveryResx = GetDeliveryResx();
  55. }
  56. /// <summary>
  57. /// 保存并设置资源内容
  58. /// </summary>
  59. /// <param name="resxHashtable"></param>
  60. /// <param name="ver"></param>
  61. public static void ConstResxSaveRep(Hashtable resxHashtable, ulong ver)
  62. {
  63. DeliveryResx = new CommonResx() { ResourceHashtable = resxHashtable, Version = ver };
  64. SaveDeliveryResx(resxHashtable, ver);
  65. }
  66. #region 数据存在UserData目录
  67. public static void InitDeliveryResx(string filePath)
  68. {
  69. DeliveryResx = GetDeliveryResx(filePath);
  70. }
  71. public static void SaveDeliveryResx(Hashtable hastableResx, ulong ver, string filePath)
  72. {
  73. string path = Path.Combine(filePath, _fileName);
  74. ResxManagerHelper.SaveData(hastableResx, ver, path);
  75. }
  76. private static CommonResx GetDeliveryResx(string filePath)
  77. {
  78. string path = Path.Combine(filePath, _fileName);
  79. return ResxManagerHelper.GetData(path);
  80. }
  81. #endregion
  82. }
  83. }