CacheTable.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Muchinfo.PC.Common.Helpers;
  2. using Muchinfo.MTPClient.Infrastructure.Enums;
  3. using System;
  4. using System.Data;
  5. namespace Muchinfo.MTPClient.Infrastructure.Cache
  6. {
  7. /// <summary>
  8. /// 缓存数据表类
  9. /// </summary>
  10. public class CacheTable : DataTable
  11. {
  12. /// <summary>
  13. /// 缓存数据时间的键
  14. /// </summary>
  15. private const string CacheTimeName = "CacheTime";
  16. /// <summary>
  17. /// 缓存数据权限的键
  18. /// </summary>
  19. private const string PremissionName = "Premission";
  20. private CacheType _type;
  21. /// <summary>
  22. /// 获取或设置缓存表类型
  23. /// </summary>
  24. public CacheType Type
  25. {
  26. get { return this._type; }
  27. }
  28. private DateTime _cacheTime;
  29. /// <summary>
  30. /// 获取或设置最后请求缓存数据的时间
  31. /// </summary>
  32. public DateTime CacheTime
  33. {
  34. get
  35. {
  36. return this._cacheTime;
  37. }
  38. set
  39. {
  40. this._cacheTime = value;
  41. string cacheTime = value.ToString(FormatHelper.DateTimeFormat2);
  42. if (this.ExtendedProperties.Contains(CacheTable.CacheTimeName))
  43. {
  44. ExtendedProperties[CacheTable.CacheTimeName] = cacheTime;
  45. }
  46. else
  47. {
  48. ExtendedProperties.Add(CacheTable.CacheTimeName, cacheTime);
  49. }
  50. }
  51. }
  52. private string m_Premission;
  53. /// <summary>
  54. /// 获取或设置请求缓存使用的权限
  55. /// </summary>
  56. public string Premission
  57. {
  58. get
  59. {
  60. return m_Premission;
  61. }
  62. set
  63. {
  64. m_Premission = value;
  65. if (this.ExtendedProperties.Contains(CacheTable.PremissionName))
  66. {
  67. ExtendedProperties[CacheTable.PremissionName] = value;
  68. }
  69. else
  70. {
  71. ExtendedProperties.Add(CacheTable.PremissionName, value);
  72. }
  73. }
  74. }
  75. /// <summary>
  76. /// Initializes a new instance of the <see cref="CacheTable"/> class.
  77. /// </summary>
  78. /// <param name="type">缓存数据类型</param>
  79. public CacheTable(CacheType type)
  80. {
  81. this._type = type;
  82. this.TableName = type.ToString();
  83. }
  84. internal void InitExtentProperties()
  85. {
  86. this._type = (CacheType)Enum.Parse(typeof(CacheType), TableName);
  87. if (this.ExtendedProperties.Contains(CacheTable.CacheTimeName))
  88. {
  89. DateTime.TryParse(string.Empty + ExtendedProperties[CacheTable.CacheTimeName], out _cacheTime);
  90. }
  91. if (this.ExtendedProperties.Contains(CacheTable.PremissionName))
  92. {
  93. this.m_Premission = string.Empty + ExtendedProperties[CacheTable.PremissionName];
  94. }
  95. }
  96. }
  97. }