public static void PrintRemainingSpace(Options opts, Win32Volume volume, bool enoughSpace) { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Machine name : " + opts.MachineName); stringBuilder.AppendLine("Drive name : " + volume.Name); stringBuilder.AppendLine("Total space : " + volume.Capacity.ToPrettySize()); stringBuilder.AppendLine("Available space : " + volume.FreeSpace.ToPrettySize()); var asBytes = SizeUnitHelper.AsBytes(opts.Unit, opts.Size); stringBuilder.AppendLine("Wanted space : " + asBytes.ToPrettySize()); var enough = enoughSpace ? "yes" : "no"; stringBuilder.AppendLine("Enough space : " + enough); var testCase = new TestCase { Name = "CheckSpace_" + volume.DriveLetter, Time = 1, SystemOut = stringBuilder.ToString() }; if (!enoughSpace) { testCase.NunitError = new NunitError { Message = "Not enough space remaining" }; } OutputAsFile(opts, testCase); }
public static void PrintRemainingSpace(Options opts, Win32Volume volume, bool enoughSpace) { Console.Out.WriteLine("Machine name : " + opts.MachineName); Console.Out.WriteLine("Drive name : " + volume.Name); Console.Out.WriteLine("Total space : " + volume.Capacity.ToPrettySize()); Console.Out.WriteLine("Available space : " + volume.FreeSpace.ToPrettySize()); var asBytes = SizeUnitHelper.AsBytes(opts.Unit, opts.Size); Console.Out.WriteLine("Wanted space : " + asBytes.ToPrettySize()); var enough = enoughSpace ? "yes" : "no"; Console.Out.WriteLine("Enough space : " + enough); }
public static void RunOptionsUnsafe(Options opts) { var options = new ConnectionOptions(); options.Impersonation = ImpersonationLevel.Impersonate; var scope = new ManagementScope($"\\\\{opts.MachineName}\\root\\cimv2", options); try { scope.Connect(); } catch (Exception ex) { throw new ConnectionError(ex); } var query = new ObjectQuery($"SELECT * from Win32_Volume WHERE DriveLetter = '{opts.DriveName}:'"); Win32Volume volumeInfo; using (var searcher = new ManagementObjectSearcher(scope, query)) { var results = new List <ManagementBaseObject>(); foreach (var managementBaseObject in searcher.Get()) { results.Add(managementBaseObject); } if (results.Count != 1) { throw new DriveNotFoundException(opts.DriveName); } volumeInfo = new Win32Volume(results[0]); } var enoughSpace = EnoughRemaining(opts, volumeInfo); ConsoleReporter.PrintRemainingSpace(opts, volumeInfo, enoughSpace); NunitReporter.PrintRemainingSpace(opts, volumeInfo, enoughSpace); if (!enoughSpace) { Environment.Exit(1); } }
public static bool EnoughRemaining(Options opts, Win32Volume volume) { var wantedSize = SizeUnitHelper.AsBytes(opts.Unit, opts.Size); return(wantedSize < volume.FreeSpace); }