DriveInfoService.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Agent.Services
  7. {
  8. public class Drive
  9. {
  10. //드라이브 명
  11. public string driveNm { get; set; }
  12. // 전체공간
  13. public int totalSize { get; set; }
  14. // 사용가능한 공간
  15. public int freeSize { get; set; }
  16. // 사용중인 공간
  17. public int usingSize { get; set; }
  18. }
  19. public class DriveInfoService
  20. {
  21. public List<Drive> drive
  22. {
  23. get
  24. {
  25. return _drive;
  26. }
  27. }
  28. private List<Drive> _drive
  29. {
  30. get
  31. {
  32. DriveInfo[] driveInfos = DriveInfo.GetDrives();
  33. List<Drive> listDerive = new List<Drive>();
  34. foreach (DriveInfo info in driveInfos)
  35. {
  36. if (info.DriveType == DriveType.Fixed)
  37. {
  38. // 전체공간
  39. int totalSize = Convert.ToInt32(info.TotalSize / Math.Pow(1024, 3));
  40. // 사용가능한 공간
  41. int freeSize = Convert.ToInt32(info.AvailableFreeSpace / Math.Pow(1024, 3));
  42. // 사용중인 공간
  43. int usingSize = (totalSize - freeSize);
  44. listDerive.Add(new Drive() { driveNm = info.Name, totalSize = totalSize, freeSize = freeSize, usingSize = usingSize });
  45. }
  46. }
  47. return listDerive;
  48. }
  49. }
  50. public List<Drive> TotalDrive
  51. {
  52. get
  53. {
  54. return _TotalDrive;
  55. }
  56. }
  57. private List<Drive> _TotalDrive
  58. {
  59. get
  60. {
  61. DriveInfo[] driveInfos = DriveInfo.GetDrives();
  62. List<Drive> listDerive = new List<Drive>();
  63. int totalSize = 0;
  64. int usingSize = 0;
  65. int freeSize = 0;
  66. foreach (DriveInfo info in driveInfos)
  67. {
  68. if (info.DriveType == DriveType.Fixed)
  69. {
  70. // 전체 용량을 계산합니다.
  71. totalSize += Convert.ToInt32(info.TotalSize / Math.Pow(1024, 3));
  72. // 전체 사용가능한 공간
  73. freeSize += Convert.ToInt32(info.AvailableFreeSpace / Math.Pow(1024, 3));
  74. // 사용중인 공간
  75. usingSize += (totalSize - freeSize);
  76. }
  77. }
  78. listDerive.Add(new Drive() { driveNm = "ToTal", totalSize = totalSize, freeSize = freeSize, usingSize = usingSize });
  79. return listDerive;
  80. }
  81. }
  82. }
  83. }