HvHdConfig.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using static QuickNV.HikvisionNetSDK.Defines;
  5. namespace QuickNV.HikvisionNetSDK.Api
  6. {
  7. public class HvHdConfig
  8. {
  9. public HvHdConfig() { }
  10. internal HvHdConfig(NET_DVR_SINGLE_HD hd)
  11. {
  12. Capacity = hd.dwCapacity;
  13. FreeSpace = hd.dwFreeSpace;
  14. HdStatus = hd.dwHdStatus;
  15. HDAttr = hd.byHDAttr;
  16. HDType = hd.byHDType;
  17. Recycling = hd.byRecycling;
  18. PictureCapacity = hd.dwPictureCapacity;
  19. FreePictureSpace = hd.dwFreePictureSpace;
  20. }
  21. public bool IsErrorStatus => HdStatus == 2;
  22. public uint Capacity { get; set; }
  23. public uint FreeSpace { get; set; }
  24. public uint HdStatus { get; set; }
  25. public byte HDAttr { get; set; }
  26. public byte HDType { get; set; }
  27. public byte Recycling { get; set; }
  28. public uint PictureCapacity { get; set; }
  29. public uint FreePictureSpace { get; set; }
  30. public override string ToString()
  31. {
  32. StringBuilder sb = new StringBuilder();
  33. sb.AppendLine();
  34. sb.AppendLine(GetRow(nameof(Capacity), ToGB(Capacity)));
  35. sb.AppendLine(GetRow(nameof(FreeSpace), ToGB(FreeSpace)));
  36. sb.AppendLine(GetRow(nameof(PictureCapacity), ToGB(PictureCapacity)));
  37. sb.AppendLine(GetRow(nameof(FreePictureSpace), ToGB(FreePictureSpace)));
  38. sb.AppendLine(GetRow(nameof(HdStatus), HdStatuses.TryGetValue(HdStatus, out var status) ? status : "unknown"));
  39. sb.AppendLine(GetRow(nameof(HDAttr), HdAttributes.TryGetValue(HDAttr, out var atr) ? atr : "unknown"));
  40. sb.AppendLine(GetRow(nameof(HDType), HdTypes.TryGetValue(HDType, out var hdType) ? hdType : "unknown"));
  41. sb.AppendLine(GetRow(nameof(Recycling), Convert.ToString(Recycling)));
  42. return sb.ToString();
  43. }
  44. private static readonly Dictionary<uint, string> HdStatuses = new Dictionary<uint, string>
  45. {
  46. {0, "normal"},
  47. {1, "unformatted"},
  48. {2, "error"},
  49. {3, "S.M.A.R.T state"},
  50. {4, "not match"},
  51. {5, "sleeping"},
  52. {6, "unconnected(network disk)"},
  53. {7, "virtual disk is normal and supports expansion"},
  54. {10, "hard disk is being restored"},
  55. {11, "hard disk is being formatted"},
  56. {12, "hard disk is waiting formatted"},
  57. {13, "the hard disk has been uninstalled"},
  58. {14, "local hard disk does not exist"},
  59. {15, "it is deleting the network disk"},
  60. {16, "locked"}
  61. };
  62. private static readonly Dictionary<uint, string> HdAttributes = new Dictionary<uint, string>
  63. {
  64. {0, "default"},
  65. {1, "redundancy (back up important data)"},
  66. {2, "read only"},
  67. {3, "Archiving"},
  68. {4, "Cannot be read/read"}
  69. };
  70. private static readonly Dictionary<uint, string> HdTypes = new Dictionary<uint, string>
  71. {
  72. {0, "local disk"},
  73. {1, "eSATA disk"},
  74. {2, "NFS disk"},
  75. {3, "iSCSI disk"},
  76. {4, "RAID virtual disk"},
  77. {5, "SD card"},
  78. {6, "miniSAS"}
  79. };
  80. private string ToGB(uint mb)
  81. {
  82. return $"{mb / 1024.0:0.00} GB ({mb} Mb)";
  83. }
  84. private string GetRow(string field, string value)
  85. {
  86. return $"{field,-24}: {value}";
  87. }
  88. }
  89. }