Example #1
0
        private void ResumeMove(MoveExtentOperationResumeRecord resumeRecord)
        {
            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)
            {
                int extentIndex = DynamicDiskExtentHelper.GetIndexOfExtentID(m_volume.DynamicExtents, (resumeRecord).ExtentID);
                DynamicDiskExtent sourceExtent = m_volume.DynamicExtents[extentIndex];

                long   bytesTotal   = sourceExtent.Size;
                long   bytesCopied  = 0;
                Thread workerThread = new Thread(delegate()
                {
                    m_isWorking = true;
                    List <DynamicDisk> diskGroup = WindowsDynamicDiskHelper.GetPhysicalDynamicDisks(m_volume.DiskGroupGuid);
                    DiskGroupDatabase database   = DiskGroupDatabase.ReadFromDisks(diskGroup, m_volume.DiskGroupGuid);
                    MoveExtentHelper.ResumeMoveExtent(database, m_volume, resumeRecord, 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();
            }
        }
Example #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            DynamicDisk targetDisk = (DynamicDisk)listDisks.SelectedValue;
            long        offset     = GetDiskOffset();
            bool        isSameDisk = (targetDisk.Disk == m_extent.Disk);

            if (!DynamicDiskHelper.IsMoveLocationValid(m_extent, targetDisk, offset))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("Invalid offset specified.");
                builder.AppendLine();
                builder.AppendLine("The following conditions must be met:");
                builder.AppendLine("1. The destination must reside inside the data portion of the disk.");
                builder.AppendLine("2. The destination must not be used by any other extents.");
                builder.AppendLine("3. The offset must be aligned to sector size.");
                builder.AppendLine("4. Source and destination disk must have the same sector size.");
                MessageBox.Show(builder.ToString(), "Error");
                return;
            }

            if (isSameDisk && offset == m_extent.FirstSector * m_extent.BytesPerSector)
            {
                MessageBox.Show("Source and destination are the same.", "Error");
                return;
            }

            DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(m_diskGroup, targetDisk.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;
                numericDiskOffset.Enabled = false;
                listSuffixes.Enabled      = false;
                btnCancel.Enabled         = false;
                btnOK.Enabled             = false;
                progressBar.Visible       = true;

                long       firstSector  = offset / targetDisk.BytesPerSector;
                DiskExtent targetExtent = new DiskExtent(targetDisk.Disk, firstSector, m_extent.Size);
                long       bytesTotal   = m_extent.Size;
                long       bytesCopied  = 0;
                Thread     workerThread = new Thread(delegate()
                {
                    m_isWorking = true;
                    if (isSameDisk)
                    {
                        MoveExtentHelper.MoveExtentWithinSameDisk(database, m_volume, m_extent, targetExtent, ref bytesCopied);
                    }
                    else
                    {
                        MoveExtentHelper.MoveExtentToAnotherDisk(database, m_volume, m_extent, targetExtent, 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();
            }
        }