private void MergeDriveInfo(ref ServerDTO serverDTO, DriveInfo[] arrDriveInfo) { if (arrDriveInfo != null) { serverDTO.Drives = new List <DriveDTO>(); DriveDTO drv = null; foreach (DriveInfo di in arrDriveInfo) { drv = new DriveDTO(); drv.DriveName = di.Name; drv.IsReady = di.IsReady; if (drv.IsReady) { drv.DriveID = di.VolumeLabel; drv.DriveCapacity = di.TotalSize; drv.DriveFreeSpace = di.TotalFreeSpace; drv.ConsumedSpace = di.TotalSize - di.TotalFreeSpace; } else { drv.DriveMessage = "Device is not ready"; } serverDTO.Drives.Add(drv); } drv = null; } arrDriveInfo = null; }
// GET api/<controller> public DriveDTO Get([FromUri] string name = "") { List <String> FolderList = new List <string>(); RDirectoryItem CurrentFolder = new RDirectoryItem(); string FolderPath = string.Empty; Member CurrentUser = db.Members.FirstOrDefault(d => d.Email == User.Identity.Name); DriveManager DM = new DriveManager(CurrentUser, System.Web.Hosting.HostingEnvironment.MapPath(Utility.SiteDriveFolderPath), string.Format("{0}/{1}", Utility.SiteURL, Utility.SiteDriveFolderName)); DM.ItemDeletable = true; if (!string.IsNullOrEmpty(name)) { FolderPath = name; } FolderList = FolderPath.Split('/').ToList <string>(); CurrentFolder = DM.GetFolderName(FolderPath); DriveDTO result = new DriveDTO(); result.Crumbs.AddRange(DM.GetCrumbs(FolderPath)); result.Directories.AddRange(DM.GetDirectoryItemList(FolderPath)); result.Files.AddRange(DM.GetFileItemList(FolderPath)); return(result); }
public IHttpActionResult AddDrive(DriveDTO drive) { var p = DriveBLL.AddDrive(drive); if (p == null) { return(NotFound()); } return(Ok(p)); }
private List <DriveDTO> GetDriveStatus() { // Run command to get drive info string commandResult = ""; try { commandResult = ScriptRunner.RunCommand("wmic logicaldisk get caption, volumename, size, freespace /format:csv"); } catch (Exception e) { throw new Exception("Failed to run command. Details: " + e.Message); } var driveArray = StringDigest.ParseCSVTo2DArray(commandResult, ",", "\r\r\n"); // Parse info and fill result object List <DriveDTO> driveList = new List <DriveDTO>(); for (int i = 1; i < driveArray.GetLength(0); i++) { var drive = new DriveDTO(); drive.letter = driveArray[i, 1]; drive.name = driveArray[i, 4]; if (String.IsNullOrWhiteSpace(driveArray[i, 3]) || String.IsNullOrWhiteSpace(driveArray[i, 2])) { // Missing drive size, skip continue; } drive.sizeGbytes = float.Parse(driveArray[i, 3]) / 1073741824; drive.freeGbytes = float.Parse(driveArray[i, 2]) / 1073741824; driveList.Add(drive); } return(driveList); }