コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: CustomAction.cs プロジェクト: skt-tech/storj
        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)));
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: FileSystemHelper.cs プロジェクト: radtek/vhdnbom
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: radtek/vhdnbom
        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);
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
ファイル: DriveInfoMount.cs プロジェクト: zobe123/Lidarr
 public DriveInfoMount(IDriveInfo driveInfo, DriveType driveType = DriveType.Unknown, MountOptions mountOptions = null)
 {
     _driveInfo   = driveInfo;
     _driveType   = driveType;
     MountOptions = mountOptions;
 }
コード例 #14
0
 public SDataDirectoryInfo(ISDataClient client, bool formMode, IDriveInfo drive)
 {
     _client = client;
     _formMode = formMode;
     _drive = drive;
 }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: nicocrm/DotNetSDataClient
 private void AddDriveNode(TreeNodeCollection nodes, IDriveInfo drive)
 {
     nodes.Add(
         new TreeNode(drive.Name.TrimEnd('\\'))
             {
                 Tag = drive.RootDirectory,
                 ImageIndex = 0,
                 SelectedImageIndex = 0,
                 Nodes = {new TreeNode()}
             });
 }
コード例 #16
0
ファイル: DriveExtensionBase.cs プロジェクト: timbussmann/io
 public virtual void EndGetDrives(IDriveInfo[] result)
 {
 }
コード例 #17
0
 public void SetupBeforeEachTest()
 {
     _fakeDriveInfo = Substitute.For <IDriveInfo>();
     _issueReporter = Substitute.For <IIssueReporter>();
     _logger        = Substitute.For <IMonitorLogger>();
 }
コード例 #18
0
 public VolumeInfo(IDriveInfo driveInfo, string pLabel)
 {
     Label     = pLabel;
     TotalSize = driveInfo.TotalSize;
     FreeSize  = driveInfo.AvailableFreeSpace;
 }
コード例 #19
0
 public SDataDirectoryInfo(ISDataClient client, bool formMode, IDriveInfo drive)
 {
     _client   = client;
     _formMode = formMode;
     _drive    = drive;
 }
コード例 #20
0
 public DiskDirectoryInfo(IDriveInfo driveInfo, DirectoryInfo info)
     : base(driveInfo, info)
 {
 }
コード例 #21
0
        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;
        }
コード例 #22
0
 protected DiskFileSystemInfo(IDriveInfo driveInfo, T info)
 {
     _driveInfo = driveInfo;
     _info      = info;
 }
コード例 #23
0
 public DriveViewModel(IDriveInfo drive)
 {
     Drive = drive;
 }
コード例 #24
0
 public DiskFileInfo(IDriveInfo driveInfo, FileInfo info)
     : base(driveInfo, info)
 {
 }
コード例 #25
0
        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);
                    }
                }
            }
        }
コード例 #26
0
 public DiskSpaceManager(IDriveInfo driveInfo, IMonitorLogger logger, IIssueReporter issueReporter)
 {
     this.DriveInfo     = driveInfo;
     this.Logger        = logger;
     this.IssueReporter = issueReporter;
 }
コード例 #27
0
        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));
        }