123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using DiskAccessLibrary;
- using DiskAccessLibrary.LogicalDiskManager;
- using Utilities;
- namespace ISCSIConsole
- {
- public partial class SelectPhysicalDiskForm : Form
- {
- private PhysicalDisk m_selectedDisk;
- public SelectPhysicalDiskForm()
- {
- InitializeComponent();
- }
- private void SelectPhysicalDiskForm_Load(object sender, EventArgs e)
- {
- List<PhysicalDisk> physicalDisks = PhysicalDiskHelper.GetPhysicalDisks();
- if (Environment.OSVersion.Version.Major >= 6)
- {
- listPhysicalDisks.Columns.Add("Status", 60);
- columnDescription.Width -= 60;
- }
- foreach (PhysicalDisk physicalDisk in physicalDisks)
- {
- string title = String.Format("Disk {0}", physicalDisk.PhysicalDiskIndex);
- string description = physicalDisk.Description;
- string serialNumber = physicalDisk.SerialNumber;
- string sizeString = FormattingHelper.GetStandardSizeString(physicalDisk.Size);
- ListViewItem item = new ListViewItem(title);
- item.SubItems.Add(description);
- item.SubItems.Add(serialNumber);
- item.SubItems.Add(sizeString);
- if (Environment.OSVersion.Version.Major >= 6)
- {
- bool isOnline = physicalDisk.GetOnlineStatus();
- string status = isOnline ? "Online" : "Offline";
- item.SubItems.Add(status);
- }
- item.Tag = physicalDisk;
- listPhysicalDisks.Items.Add(item);
- }
- }
- private void btnOK_Click(object sender, EventArgs e)
- {
- PhysicalDisk selectedDisk;
- if (listPhysicalDisks.SelectedItems.Count > 0)
- {
- selectedDisk = (PhysicalDisk)listPhysicalDisks.SelectedItems[0].Tag;
- }
- else
- {
- MessageBox.Show("No disk was selected", "Error");
- return;
- }
- if (!chkReadOnly.Checked)
- {
- if (Environment.OSVersion.Version.Major >= 6)
- {
- bool isDiskReadOnly;
- bool isOnline = selectedDisk.GetOnlineStatus(out isDiskReadOnly);
- if (isDiskReadOnly)
- {
- MessageBox.Show("The selected disk is set to readonly", "Error");
- return;
- }
- if (isOnline)
- {
- DialogResult result = MessageBox.Show("The selected disk will now be taken offline. OK?", String.Empty, MessageBoxButtons.OKCancel);
- if (result == DialogResult.OK)
- {
- bool success = selectedDisk.SetOnlineStatus(false);
- if (!success)
- {
- MessageBox.Show("Was not able to take the disk offline", "Error");
- return;
- }
- }
- else
- {
- return;
- }
- }
- }
- else
- {
- if (DynamicDisk.IsDynamicDisk(selectedDisk))
- {
-
-
-
- DialogResult result = MessageBox.Show("The dynamic disk database will likely be corrupted, Continue?", "Warning", MessageBoxButtons.YesNo);
- if (result != DialogResult.Yes)
- {
- return;
- }
- }
- else
- {
-
-
- LockStatus status = LockHelper.LockBasicDiskAndVolumesOrNone(selectedDisk);
- if (status == LockStatus.CannotLockDisk)
- {
- MessageBox.Show("Unable to lock the disk", "Error");
- return;
- }
- else if (status == LockStatus.CannotLockVolume)
- {
- MessageBox.Show("Unable to lock one of the volumes on the disk", "Error");
- return;
- }
- }
- }
- }
- if (chkReadOnly.Checked)
- {
- selectedDisk.IsReadOnly = true;
- }
- m_selectedDisk = selectedDisk;
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.Cancel;
- this.Close();
- }
- public PhysicalDisk SelectedDisk
- {
- get
- {
- return m_selectedDisk;
- }
- }
- private void listPhysicalDisks_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
- {
- e.NewWidth = ((ListView)sender).Columns[e.ColumnIndex].Width;
- e.Cancel = true;
- }
- }
- }
|