private void cmdOK_Click(object sender, EventArgs e) { XmlDocument config = new XmlDocument(); config.LoadXml("<config><drives></drives></config>"); XmlNode drivesListNode = config.SelectSingleNode("config/drives"); foreach (ListViewItem lvi in lvwDrives.Items) { DriveSpaceEntry dse = (DriveSpaceEntry)lvi.Tag; XmlNode driveXmlNode = config.CreateElement("drive"); driveXmlNode.Attributes.Append(config.CreateAttributeWithValue("name", dse.DriveLetter)); driveXmlNode.Attributes.Append(config.CreateAttributeWithValue("warningSizeLeftMB", dse.WarningSizeLeftMB)); driveXmlNode.Attributes.Append(config.CreateAttributeWithValue("errorSizeLeftMB", dse.ErrorSizeLeftMB)); driveXmlNode.Attributes.Append(config.CreateAttributeWithValue("warnOnNotReady", dse.WarnOnNotReady)); drivesListNode.AppendChild(driveXmlNode); } CustomConfig = config.OuterXml; DialogResult = DialogResult.OK; Close(); }
public DialogResult ShowConfig() { if (CustomConfig.Length > 0) { try { XmlDocument config = new XmlDocument(); config.LoadXml(CustomConfig); XmlElement root = config.DocumentElement; foreach (XmlElement drive in root.SelectNodes("drives/drive")) { DriveSpaceEntry driveSpaceEntry = new DriveSpaceEntry(); driveSpaceEntry.DriveLetter = drive.ReadXmlElementAttr("name", "c"); driveSpaceEntry.WarningSizeLeftMB = long.Parse(drive.ReadXmlElementAttr("warningSizeLeftMB", "500")); driveSpaceEntry.ErrorSizeLeftMB = long.Parse(drive.ReadXmlElementAttr("errorSizeLeftMB", "100")); driveSpaceEntry.WarnOnNotReady = bool.Parse(drive.ReadXmlElementAttr("warnOnNotReady", "False")); ListViewItem lvi = new ListViewItem(driveSpaceEntry.DriveLetter); lvi.SubItems.Add(driveSpaceEntry.WarningSizeLeftMB.ToString()); lvi.SubItems.Add(driveSpaceEntry.ErrorSizeLeftMB.ToString()); lvi.SubItems.Add(driveSpaceEntry.WarnOnNotReady.ToString()); lvi.Tag = driveSpaceEntry; lvwDrives.Items.Add(lvi); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(ShowDialog()); }
private void RefreshList() { foreach (ListViewItem lvi in lvwDrives.Items) { if (lvi.Tag != null && lvi.Tag is DriveSpaceEntry) { try { DriveSpaceEntry dse = (DriveSpaceEntry)lvi.Tag; DriveInfo di = new DriveInfo(dse.DriveLetter); if (di.IsReady) { lvi.SubItems[1].Text = (di.TotalFreeSpace / 1048576).ToString("N0"); lvi.SubItems[2].Text = di.DriveType.ToString(); } else { lvi.SubItems[1].Text = "N/A"; lvi.SubItems[2].Text = "Drive not available!"; } } catch (Exception ex) { lvi.SubItems[1].Text = "Err"; lvi.SubItems[2].Text = ex.Message; } } } }
public override void ReadConfiguration(XmlDocument config) { Drives = new List <DriveSpaceEntry>(); XmlElement root = config.DocumentElement; foreach (XmlElement drive in root.SelectNodes("drives/drive")) { DriveSpaceEntry driveSpaceEntry = new DriveSpaceEntry(); driveSpaceEntry.DriveLetter = drive.ReadXmlElementAttr("name", "c"); driveSpaceEntry.WarningSizeLeftMB = long.Parse(drive.ReadXmlElementAttr("warningSizeLeftMB", "500")); driveSpaceEntry.ErrorSizeLeftMB = long.Parse(drive.ReadXmlElementAttr("errorSizeLeftMB", "100")); driveSpaceEntry.WarnOnNotReady = bool.Parse(drive.ReadXmlElementAttr("warnOnNotReady", "False")); Drives.Add(driveSpaceEntry); } }