using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Agent.Services { public class Drive { //드라이브 명 public string driveNm { get; set; } // 전체공간 public int totalSize { get; set; } // 사용가능한 공간 public int freeSize { get; set; } // 사용중인 공간 public int usingSize { get; set; } } public class DriveInfoService { public List drive { get { return _drive; } } private List _drive { get { DriveInfo[] driveInfos = DriveInfo.GetDrives(); List listDerive = new List(); foreach (DriveInfo info in driveInfos) { if (info.DriveType == DriveType.Fixed) { // 전체공간 int totalSize = Convert.ToInt32(info.TotalSize / Math.Pow(1024, 3)); // 사용가능한 공간 int freeSize = Convert.ToInt32(info.AvailableFreeSpace / Math.Pow(1024, 3)); // 사용중인 공간 int usingSize = (totalSize - freeSize); listDerive.Add(new Drive() { driveNm = info.Name, totalSize = totalSize, freeSize = freeSize, usingSize = usingSize }); } } return listDerive; } } public List TotalDrive { get { return _TotalDrive; } } private List _TotalDrive { get { DriveInfo[] driveInfos = DriveInfo.GetDrives(); List listDerive = new List(); int totalSize = 0; int usingSize = 0; int freeSize = 0; foreach (DriveInfo info in driveInfos) { if (info.DriveType == DriveType.Fixed) { // 전체 용량을 계산합니다. totalSize += Convert.ToInt32(info.TotalSize / Math.Pow(1024, 3)); // 전체 사용가능한 공간 freeSize += Convert.ToInt32(info.AvailableFreeSpace / Math.Pow(1024, 3)); // 사용중인 공간 usingSize += (totalSize - freeSize); } } listDerive.Add(new Drive() { driveNm = "ToTal", totalSize = totalSize, freeSize = freeSize, usingSize = usingSize }); return listDerive; } } } }