private void listDisks_SelectedIndexChanged(object sender, EventArgs e) { DynamicDisk dynamicDisk = (DynamicDisk)listDisks.SelectedValue; PrivateHeader privateHeader = dynamicDisk.PrivateHeader; long publicRegionEndLBA = (long)(privateHeader.PublicRegionStartLBA + privateHeader.PublicRegionSizeLBA); numericDiskOffset.Minimum = (long)privateHeader.PublicRegionStartLBA * dynamicDisk.BytesPerSector; numericDiskOffset.Maximum = publicRegionEndLBA * dynamicDisk.BytesPerSector - m_extent.Size; if (dynamicDisk.Disk != m_extent.Disk) { DiskExtent allocation = DynamicDiskHelper.FindExtentAllocation(dynamicDisk, m_extent.Size); numericDiskOffset.Enabled = (allocation != null); btnOK.Enabled = (allocation != null); if (allocation != null) { numericDiskOffset.Value = allocation.FirstSector * allocation.BytesPerSector; m_previousSuffixIndex = 0; listSuffixes.SelectedIndex = 0; CompactNumericOffset(); } } else { numericDiskOffset.Enabled = true; btnOK.Enabled = true; numericDiskOffset.Value = m_extent.FirstSector * m_extent.Disk.BytesPerSector; m_previousSuffixIndex = 0; listSuffixes.SelectedIndex = 0; CompactNumericOffset(); } }
private void btnOK_Click(object sender, EventArgs e) { DynamicDisk targetDynamicDisk = (DynamicDisk)listDisks.SelectedValue; Raid5Volume raid5Volume = (Raid5Volume)m_volume; DiskExtent newExtent = DynamicDiskHelper.FindExtentAllocation(targetDynamicDisk, raid5Volume.ColumnSize); if (newExtent == null) { MessageBox.Show("The disk specified does not contain enough free space.", "Error"); return; } List <DynamicDisk> diskGroup = WindowsDynamicDiskHelper.GetPhysicalDynamicDisks(raid5Volume.DiskGroupGuid); DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(diskGroup, raid5Volume.DiskGroupGuid); if (database.AreDisksMissing) { DialogResult disksMissingResult = MessageBox.Show("Some of the disks in this disk group are missing, Continue anyway?", "Warning", MessageBoxButtons.YesNo); if (disksMissingResult != DialogResult.Yes) { return; } } DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { listDisks.Enabled = false; btnCancel.Enabled = false; btnOK.Enabled = false; progressBar.Visible = true; long bytesTotal = raid5Volume.Size; long bytesCopied = 0; Thread workerThread = new Thread(delegate() { m_isWorking = true; AddDiskToArrayHelper.AddDiskToRaid5Volume(database, raid5Volume, newExtent, ref bytesCopied); m_isWorking = false; }); workerThread.Start(); new Thread(delegate() { while (workerThread.IsAlive) { Thread.Sleep(250); int progress = (int)(100 * (double)bytesCopied / bytesTotal); this.Invoke((MethodInvoker) delegate() { progressBar.Value = progress; }); } this.Invoke((MethodInvoker) delegate() { DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); }); }).Start(); } }
private void btnOK_Click(object sender, EventArgs e) { int diskCount = listDisks.CheckedIndices.Count; if (rbSimple.Checked && diskCount != 1) { MessageBox.Show("You must select a single disk in order to create a simple volume.", "Error"); return; } if (rbRaid5.Checked) { if (chkDegraded.Checked && diskCount < 2) { MessageBox.Show("You must select at least 2 disks in order to create a degraded RAID-5 volume.", "Error"); return; } if (!chkDegraded.Checked && diskCount < 3) { MessageBox.Show("You must select at least 3 disks in order to create a RAID-5 volume.", "Error"); return; } } long extentSizeInBytes = (long)numericExtentSize.Value * 1024 * 1024; List <DiskExtent> extents = new List <DiskExtent>(); foreach (int checkedIndex in listDisks.CheckedIndices) { DynamicDisk dynamicDisk = m_diskGroup[checkedIndex]; DiskExtent extent = DynamicDiskHelper.FindExtentAllocation(dynamicDisk, extentSizeInBytes); if (extent == null) { MessageBox.Show("One of the disks does not contain enough free space", "Error"); return; } extents.Add(extent); } DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(m_diskGroup)[0]; if (rbSimple.Checked) { VolumeManagerDatabaseHelper.CreateSimpleVolume(database, extents[0]); } else { VolumeManagerDatabaseHelper.CreateRAID5Volume(database, extents, chkDegraded.Checked); } DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); } }