public Task ValidateAsync(DiskDriveConfig.Partition partition)
 {
     if (partition == null)
     {
         throw new ArgumentNullException(nameof(partition));
     }
     if (string.IsNullOrWhiteSpace(partition.Path))
     {
         throw new ArgumentNullException(nameof(partition.Path));
     }
     if (partition.MaxPercentageUsage < AppConsts.PERCENT_MIN)
     {
         throw new ArgumentOutOfRangeException(nameof(partition.MaxPercentageUsage), $"Minimum value is {AppConsts.PERCENT_MIN}");
     }
     if (partition.MaxPercentageUsage > AppConsts.PERCENT_MAX)
     {
         throw new ArgumentOutOfRangeException(nameof(partition.MaxPercentageUsage), $"Maximum value is {AppConsts.PERCENT_MAX}");
     }
     return(Task.CompletedTask);
 }
Esempio n. 2
0
        public Task <DiskDriveMetrics> GetDiskDriveMetricsAsync(DiskDriveConfig.Partition partition)
        {
            if (partition == null)
            {
                throw new NullReferenceException(nameof(partition));
            }

            DriveInfo di = new DriveInfo(partition.Path);

            var metrics = new DiskDriveMetrics()
            {
                IsReady = di.IsReady,
                Path    = partition.Path
            };

            if (metrics.IsReady)
            {
                metrics.Total = di.TotalSize;
                metrics.Free  = di.AvailableFreeSpace;
            }

            return(Task.FromResult(metrics));
        }