public AddDiscForm(ServiceProvider serviceProvider, Locality locality, string profileId, string discId, IDriveInfo drive, IDVDInfo parentProfile, IEnumerable <IDVDInfo> profiles, string formattedDiscId) { _serviceProvider = serviceProvider; _locality = locality; _profileId = profileId; _discId = discId; _drive = drive; _parentProfile = parentProfile; InitializeComponent(); Icon = Properties.Resources.DJDSOFT; Text = $"{Text}: {formattedDiscId} ({locality.Description})"; DialogResult = DialogResult.None; Load += (s, e) => OnAddDiscFormLoad(profiles); }
private void When_creating_directory_it_must_succeed() { // Arrange const string path = @"C:\some\folder\subtree"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .Build(); // Act fileSystem.Directory.CreateDirectory(path); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(4096); }
public void ValidateStorage(string storageStr, string storageDir) { if (string.IsNullOrEmpty(storageStr)) { throw new ArgumentException("The value cannot be empty."); } if (!double.TryParse(storageStr, NumberStyles.Number, CultureInfo.CreateSpecificCulture("en-US"), out double storage)) { throw new ArgumentException(string.Format("'{0}' is not a valid number.", storageStr)); } if (storage < 0.5) { throw new ArgumentException("The allocated disk space cannot be less than 0.5 TB."); } if (string.IsNullOrEmpty(storageDir)) { throw new ArgumentException("The storage directory cannot be empty"); } long storagePlusOverhead; try { storagePlusOverhead = Convert.ToInt64(storage * 1.1 * TB); } catch (OverflowException) { throw new ArgumentException(string.Format("{0} TB is too large value for allocated storage.", storage)); } IDirectoryInfo dir = fs.DirectoryInfo.FromDirectoryName(storageDir); IDriveInfo drive = fs.DriveInfo.FromDriveName(dir.Root.FullName); // TODO: Find a way to calculate the available free space + total size of existing pieces if (drive.TotalSize < storagePlusOverhead) { throw new ArgumentException(string.Format("The disk size ({0:0.##} TB) on the selected drive {1} is less than the allocated disk space plus the 10% overhead ({2:0.##} TB total).", decimal.Divide(drive.TotalSize, TB), drive.Name, decimal.Divide(storagePlusOverhead, TB))); } }
private void When_overwriting_file_it_must_succeed() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(path, BufferFactory.Create(1024)) .Build(); // Act fileSystem.File.WriteAllBytes(path, BufferFactory.Create(4000)); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(96); }
private void When_renaming_directory_it_must_succeed() { // Arrange IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(@"c:\source\src.txt", BufferFactory.Create(64)) .IncludingBinaryFile(@"c:\source\nested\src.txt", BufferFactory.Create(256)) .IncludingDirectory(@"c:\source\subfolder") .Build(); // Act fileSystem.Directory.Move(@"C:\source", @"C:\target"); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(3776); }
private void When_moving_file_to_same_drive_it_must_succeed() { // Arrange const string sourcePath = @"C:\src\source.txt"; const string targetPath = @"C:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .Build(); // Act fileSystem.File.Move(sourcePath, targetPath); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(3328); }
private void When_writing_to_new_file_with_DeleteOnClose_it_must_succeed() { // Arrange IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .Build(); // Act using (IFileStream stream = fileSystem.File.Create(@"C:\file.txt", options: FileOptions.DeleteOnClose)) { byte[] buffer = BufferFactory.Create(1024); stream.Write(buffer, 0, buffer.Length); } // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(4096); }
public string FindBestLocationForVhdTemporaryFolder() { IDriveInfo systemDriveInfo = GetSystemDriveInfo(); long systemDriveUsedSpace = systemDriveInfo.TotalSize - systemDriveInfo.TotalFreeSpace; var applicableDrives = fileSystem.DriveInfo.GetDrives() .Where(x => x.IsReady && x.AvailableFreeSpace > (systemDriveUsedSpace + (200 << 20)) && x.Name != systemDriveInfo.Name) .OrderByDescending(x => x.AvailableFreeSpace); if (!applicableDrives.Any()) { return(null); } string tempVhdLocation = $"{applicableDrives.First().Name}VHDNBOM_Temp"; return(tempVhdLocation); }
private void When_replacing_file_without_backup_it_must_succeed() { // Arrange const string sourcePath = @"C:\source.txt"; const string targetPath = @"C:\target.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(2112)) .IncludingBinaryFile(sourcePath, BufferFactory.Create(768)) .IncludingBinaryFile(targetPath, BufferFactory.Create(1280)) .Build(); // Act fileSystem.File.Replace(sourcePath, targetPath, null); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(1344); }
private void When_moving_position_past_end_of_file_it_must_not_allocate_disk_space() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(512)) .IncludingBinaryFile(path, BufferFactory.Create(32)) .Build(); using (IFileStream stream = fileSystem.File.Open(path, FileMode.Open)) { // Act stream.Position = 1024; // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(480); } }
private static MigrationFlowData BuildMigrationData(OperationModeEnum operationMode, IFileSystemHelper fileSystemHelper, bool addToBootManager) { MigrationFlowData migrationData = new MigrationFlowData(); IDriveInfo systemDriveInfo = fileSystemHelper.GetSystemDriveInfo(); migrationData.OperatingSystemDriveLetter = systemDriveInfo.Name.First(); migrationData.TemporaryVhdFileMaxSize = systemDriveInfo.TotalSize + (200 << 20) /*200MB*/; migrationData.VhdFileName = "VHDNBOM_System_Image.vhdx"; migrationData.VhdFileType = Logic.Models.Enums.VhdType.VhdxDynamic; migrationData.VhdFileTemporaryFolder = vhdTemporaryFolderPath ?? fileSystemHelper.FindBestLocationForVhdTemporaryFolder(); migrationData.AddVhdToBootManager = addToBootManager; if (operationMode == OperationModeEnum.MigrateCurrentOsToVhd) { migrationData.DeleteTemporaryVhdFile = true; migrationData.DestinationVhdMaxFileSize = (systemDriveInfo.AvailableFreeSpace - Constants.FiveGigs + Constants.OneGig) + (200 << 20); migrationData.DesiredTempVhdShrinkSize = (systemDriveInfo.TotalSize - (systemDriveInfo.AvailableFreeSpace - Constants.FiveGigs)); migrationData.VhdFileDestinationFolder = $"{migrationData.OperatingSystemDriveLetter}:\\VHD_Boot"; } return(migrationData); }
private void When_increasing_file_size_using_SetLength_it_must_succeed() { // Arrange const string path = @"C:\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingVolume("C:", new FakeVolumeInfoBuilder() .OfCapacity(8192) .WithFreeSpace(4096)) .IncludingBinaryFile(path, BufferFactory.Create(1024)) .Build(); using (IFileStream stream = fileSystem.File.OpenWrite(path)) { // Act stream.SetLength(1280); // Assert IDriveInfo driveInfo = fileSystem.ConstructDriveInfo("C:"); driveInfo.AvailableFreeSpace.Should().Be(2816); } }
public DriveInfoMount(IDriveInfo driveInfo, DriveType driveType = DriveType.Unknown, MountOptions mountOptions = null) { _driveInfo = driveInfo; _driveType = driveType; MountOptions = mountOptions; }
public SDataDirectoryInfo(ISDataClient client, bool formMode, IDriveInfo drive) { _client = client; _formMode = formMode; _drive = drive; }
private void AddDriveNode(TreeNodeCollection nodes, IDriveInfo drive) { nodes.Add( new TreeNode(drive.Name.TrimEnd('\\')) { Tag = drive.RootDirectory, ImageIndex = 0, SelectedImageIndex = 0, Nodes = {new TreeNode()} }); }
public virtual void EndGetDrives(IDriveInfo[] result) { }
public void SetupBeforeEachTest() { _fakeDriveInfo = Substitute.For <IDriveInfo>(); _issueReporter = Substitute.For <IIssueReporter>(); _logger = Substitute.For <IMonitorLogger>(); }
public VolumeInfo(IDriveInfo driveInfo, string pLabel) { Label = pLabel; TotalSize = driveInfo.TotalSize; FreeSize = driveInfo.AvailableFreeSpace; }
public DiskDirectoryInfo(IDriveInfo driveInfo, DirectoryInfo info) : base(driveInfo, info) { }
public VirtualCloneDriveWrapper(string unitLetter, string vcdMountPath, int triesBeforeError, int waitTime, IDriveInfo driveInfo, IFileProvider fileProvider, IProcessProvider processProvider) { _driveInfo = driveInfo; UnitLetter = unitLetter; TriesBeforeError = triesBeforeError; WaitTime = waitTime; VcdMountPath = vcdMountPath; _fileProvider = fileProvider; _processProvider = processProvider; }
protected DiskFileSystemInfo(IDriveInfo driveInfo, T info) { _driveInfo = driveInfo; _info = info; }
public DriveViewModel(IDriveInfo drive) { Drive = drive; }
public DiskFileInfo(IDriveInfo driveInfo, FileInfo info) : base(driveInfo, info) { }
private void TryAddDisc(IDriveInfo drive, Locality locality, Cursor previousCursor) { Cursor = Cursors.WaitCursor; Application.DoEvents(); string discId; try { discId = DvdDiscIdCalculator.Calculate(drive.DriveLetter); } catch { UIServices.ShowMessageBox(string.Format(MessageBoxTexts.DriveNotReady, drive.DriveLetter), MessageBoxTexts.WarningHeader, UI.Buttons.OK, UI.Icon.Warning); return; } var suffix = locality.ID > 0 ? $".{locality.ID}" : string.Empty; var profileId = $"I{discId}{suffix}"; var profileIds = ((object[])Api.GetAllProfileIDs()).Cast <string>().ToList(); var existingProfileId = profileIds.FirstOrDefault(id => profileId.Equals(id)); var formattedDiscId = FormatDiscId(discId); if (!string.IsNullOrEmpty(existingProfileId)) { Api.SelectDVDByProfileID(profileId); Cursor = previousCursor; UIServices.ShowMessageBox(string.Format(MessageBoxTexts.ProfileAlreadyExists, formattedDiscId, locality.Description), MessageBoxTexts.WarningHeader, UI.Buttons.OK, UI.Icon.Warning); } else { if (_allProfiles == null) { _allProfiles = profileIds.Select(id => { Api.DVDByProfileID(out var profile, id, 0, 0); return(profile); }).ToList(); } DefaultValues.DownloadProfile = UpdateFromOnlineDatabaseCheckBox.Checked; var parentProfile = AddAsChildCheckBox.Checked ? _parentProfile : null; Cursor = previousCursor; using (var form = new AddDiscForm(_serviceProvider, locality, profileId, discId, drive, parentProfile, _allProfiles, formattedDiscId)) { if (form.ShowDialog() == DialogResult.OK) { profileIds.Add(profileId); _allProfiles.Add(form.NewProfile); } } } }
public DiskSpaceManager(IDriveInfo driveInfo, IMonitorLogger logger, IIssueReporter issueReporter) { this.DriveInfo = driveInfo; this.Logger = logger; this.IssueReporter = issueReporter; }
public IEnumerable<BundleInfo> GetBundleInfosFromProject(IDriveInfo projectDrive) { var manifestsDir = projectDrive.RootDirectory.GetDirectories().FirstOrDefault(dir => dir.Name == "Bundle Manifests"); if (manifestsDir == null) return new List<BundleInfo>(); var manifests = manifestsDir.GetFiles("*.manifest.xml", SearchOption.AllDirectories); return manifests.Select(manifest => ExtractBundleInfoFromBundleManifest(manifest, null)); }