//public List<FileSystemDirectoryFilterEntry> Entries = new List<FileSystemDirectoryFilterEntry>(); #region IAgentConfig Members public void ReadConfiguration(string configurationString) { XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); Entries.Clear(); System.Xml.XmlElement root = config.DocumentElement; foreach (System.Xml.XmlElement host in root.SelectNodes("directoryList/directory")) { FileSystemDirectoryFilterEntry directoryFilterEntry = new FileSystemDirectoryFilterEntry(); directoryFilterEntry.FilterFullPath = host.Attributes.GetNamedItem("directoryPathFilter").Value; directoryFilterEntry.DirectoryExistOnly = bool.Parse(host.ReadXmlElementAttr("testDirectoryExistOnly", "False")); directoryFilterEntry.FilesExistOnly = bool.Parse(host.ReadXmlElementAttr("testFilesExistOnly", "False")); directoryFilterEntry.ErrorOnFilesExist = bool.Parse(host.ReadXmlElementAttr("errorOnFilesExist", "False")); directoryFilterEntry.ContainsText = host.ReadXmlElementAttr("containsText", ""); directoryFilterEntry.UseRegEx = host.ReadXmlElementAttr("useRegEx", false); int tmp = 0; if (int.TryParse(host.ReadXmlElementAttr("warningFileCountMax", "0"), out tmp)) { directoryFilterEntry.CountWarningIndicator = tmp; } if (int.TryParse(host.ReadXmlElementAttr("errorFileCountMax", "0"), out tmp)) { directoryFilterEntry.CountErrorIndicator = tmp; } long tmpl; if (long.TryParse(host.ReadXmlElementAttr("warningFileSizeMaxKB", "0"), out tmpl)) { directoryFilterEntry.SizeKBWarningIndicator = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("errorFileSizeMaxKB", "0"), out tmpl)) { directoryFilterEntry.SizeKBErrorIndicator = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("fileMaxAgeSec", "0"), out tmpl)) { directoryFilterEntry.FileMaxAgeSec = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("fileMinAgeSec", "0"), out tmpl)) { directoryFilterEntry.FileMinAgeSec = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("fileMinSizeKB", "0"), out tmpl)) { directoryFilterEntry.FileMinSizeKB = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("fileMaxSizeKB", "0"), out tmpl)) { directoryFilterEntry.FileMaxSizeKB = tmpl; } Entries.Add(directoryFilterEntry); } }
private void lvwEntries_DoubleClick(object sender, EventArgs e) { if (lvwEntries.SelectedItems.Count == 1) { FileSystemDirectoryFilterEntry filterEntry = (FileSystemDirectoryFilterEntry)lvwEntries.SelectedItems[0].Tag; if (System.IO.Directory.Exists(filterEntry.DirectoryPath)) { System.Diagnostics.Process.Start("Explorer.exe", filterEntry.DirectoryPath.Replace("'", "''")); } } }
public override void OKClicked() { if (SelectedConfig != null) { SelectedConfig = new FileSystemCollectorConfig(); } FileSystemCollectorConfig fscc = (FileSystemCollectorConfig)SelectedConfig; fscc.Entries.Clear(); foreach (ListViewItem lvi in lvwEntries.Items) { FileSystemDirectoryFilterEntry de = (FileSystemDirectoryFilterEntry)lvi.Tag; fscc.Entries.Add(de); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
private void cmdTest_Click(object sender, EventArgs e) { try { FileSystemDirectoryFilterEntry testEntry = new FileSystemDirectoryFilterEntry(); testEntry.DirectoryPath = txtDirectory.Text; testEntry.DirectoryExistOnly = optDirectoryExistOnly.Checked; testEntry.FileFilter = txtFilter.Text; testEntry.IncludeSubDirectories = chkIncludeSubDirs.Checked; testEntry.FilesExistOnly = optCheckIfFilesExistOnly.Checked; testEntry.ErrorOnFilesExist = optErrorOnFilesExist.Checked; testEntry.ContainsText = txtContains.Text; testEntry.UseRegEx = chkUseRegEx.Checked; testEntry.CountWarningIndicator = Convert.ToInt32(numericUpDownCountWarningIndicator.Value); testEntry.CountErrorIndicator = Convert.ToInt32(numericUpDownCountErrorIndicator.Value); testEntry.FileSizeIndicatorUnit = (FileSizeUnits)cboFileSizeIndicatorUnit.SelectedIndex; testEntry.SizeWarningIndicator = (int)numericUpDownSizeWarningIndicator.Value; testEntry.SizeErrorIndicator = (int)numericUpDownSizeErrorIndicator.Value; testEntry.FileAgeUnit = (TimeUnits)cboFileAgeUnit.SelectedIndex; testEntry.FileMinAge = (int)numericUpDownFileAgeMin.Value; testEntry.FileMaxAge = (int)numericUpDownFileAgeMax.Value; testEntry.FileSizeUnit = (FileSizeUnits)cboFileSizeUnit.SelectedIndex; testEntry.FileMinSize = (int)numericUpDownFileSizeMin.Value; testEntry.FileMaxSize = (int)numericUpDownFileSizeMax.Value; testEntry.ShowFilenamesInDetails = chkShowFilenamesInDetails.Checked; DirectoryFileInfo directoryFileInfo = testEntry.GetFileListByFilters(); CollectorState currentState = testEntry.GetState(directoryFileInfo); MessageBox.Show(string.Format("State: {0}\r\nDetails: {1} file(s), {2}", currentState, directoryFileInfo.FileCount, FormatUtils.FormatFileSize(directoryFileInfo.TotalFileSize)), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmdOK_Click(object sender, EventArgs e) { if (txtFilter.Text.Length == 0) { txtFilter.Text = "*.*"; } if (txtDirectory.Text.Contains("*")) { txtFilter.Text = FileSystemDirectoryFilterEntry.GetFilterFromPath(txtDirectory.Text); txtDirectory.Text = FileSystemDirectoryFilterEntry.GetDirectoryFromPath(txtDirectory.Text); } // if (!Directory.Exists((txtDirectory.Text.Length > 0 && txtDirectory.Text.Contains('%')) ? Environment.ExpandEnvironmentVariables(txtDirectory.Text) : txtDirectory.Text)) // { // MessageBox.Show("Directory must exist and be accessible!", "Directory", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // } //else if (optCounts.Checked && numericUpDownCountWarningIndicator.Value == numericUpDownCountErrorIndicator.Value && numericUpDownCountWarningIndicator.Value > 0) { MessageBox.Show("Error and warning file count values cannot the same!", "Warnings/Errors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (optCounts.Checked && numericUpDownSizeWarningIndicator.Value == numericUpDownSizeErrorIndicator.Value && numericUpDownSizeWarningIndicator.Value > 0) { MessageBox.Show("Error and warning file size values cannot be the same!", "Warnings/Errors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (!optDirectoryExistOnly.Checked && numericUpDownFileAgeMin.Value > numericUpDownFileAgeMax.Value && numericUpDownFileAgeMax.Value > 0) { MessageBox.Show("File age warning filter value cannot be more than the error value!", "Filters", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (!optDirectoryExistOnly.Checked && numericUpDownFileSizeMin.Value > numericUpDownFileSizeMax.Value && numericUpDownFileSizeMax.Value > 0) { MessageBox.Show("File size warning filter value cannot be more than the error value!", "Filters", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { FileSystemDirectoryFilterEntry selectedEntry; if (SelectedEntry == null) { SelectedEntry = new FileSystemDirectoryFilterEntry(); } selectedEntry = (FileSystemDirectoryFilterEntry)SelectedEntry; selectedEntry.DirectoryPath = txtDirectory.Text; selectedEntry.DirectoryExistOnly = optDirectoryExistOnly.Checked; selectedEntry.FileFilter = txtFilter.Text; selectedEntry.IncludeSubDirectories = chkIncludeSubDirs.Checked; selectedEntry.FilesExistOnly = optCheckIfFilesExistOnly.Checked; selectedEntry.ErrorOnFilesExist = optErrorOnFilesExist.Checked; selectedEntry.ContainsText = txtContains.Text; selectedEntry.UseRegEx = chkUseRegEx.Checked; selectedEntry.CountWarningIndicator = Convert.ToInt32(numericUpDownCountWarningIndicator.Value); selectedEntry.CountErrorIndicator = Convert.ToInt32(numericUpDownCountErrorIndicator.Value); selectedEntry.FileSizeIndicatorUnit = (FileSizeUnits)cboFileSizeIndicatorUnit.SelectedIndex; selectedEntry.SizeWarningIndicator = (int)numericUpDownSizeWarningIndicator.Value; selectedEntry.SizeErrorIndicator = (int)numericUpDownSizeErrorIndicator.Value; selectedEntry.FileAgeUnit = (TimeUnits)cboFileAgeUnit.SelectedIndex; selectedEntry.FileMinAge = (int)numericUpDownFileAgeMin.Value; selectedEntry.FileMaxAge = (int)numericUpDownFileAgeMax.Value; selectedEntry.FileSizeUnit = (FileSizeUnits)cboFileSizeUnit.SelectedIndex; selectedEntry.FileMinSize = (int)numericUpDownFileSizeMin.Value; selectedEntry.FileMaxSize = (int)numericUpDownFileSizeMax.Value; selectedEntry.ShowFilenamesInDetails = chkShowFilenamesInDetails.Checked; SelectedEntry = selectedEntry; DialogResult = DialogResult.OK; Close(); } }
private void LoadDirInfo(ListViewItem itm) { //int count = 0; string countString = "-"; string oldValue = "-"; try { FileSystemDirectoryFilterEntry filterEntry = (FileSystemDirectoryFilterEntry)itm.Tag; DirectoryFileInfo fileInfo = filterEntry.GetDirFileInfo(); CollectorState currentState = filterEntry.GetState(fileInfo); oldValue = itm.SubItems[1].Text; if (!fileInfo.Exists) { if (filterEntry.DirectoryExistOnly) { countString = "No"; } else { countString = "N/A"; } } else { if (filterEntry.DirectoryExistOnly) { countString = "Yes"; } else { countString = fileInfo.FileCount.ToString(); } } if (!filterEntry.DirectoryExistOnly && fileInfo.FileSize >= 0) { itm.SubItems[2].Text = (fileInfo.FileSize / 1024).ToString(); } else { itm.SubItems[2].Text = "N/A"; } if (currentState == CollectorState.Good) { itm.BackColor = SystemColors.Window; } else if (currentState == CollectorState.Warning) { itm.BackColor = Color.SandyBrown; } else { itm.BackColor = Color.Salmon; } } catch (Exception anyex) { itm.SubItems[1].Text = "err:" + anyex.Message; } //string oldValue = itm.SubItems[1].Text; itm.SubItems[1].Text = countString; if ((oldValue != "-") && (oldValue != countString)) { UpdateFont(itm, new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Bold)); } else { UpdateFont(itm, new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular)); } }
public FileSystemCollectorEditFilterEntry() { InitializeComponent(); SelectedFilterEntry = new FileSystemDirectoryFilterEntry(); SelectedFilterEntry.FileFilter = "*.*"; }
private void cmdOK_Click(object sender, EventArgs e) { if (txtFilter.Text.Length == 0) { txtFilter.Text = "*.*"; } if (txtDirectory.Text.Contains("*")) { txtFilter.Text = FileSystemDirectoryFilterEntry.GetFilterFromPath(txtDirectory.Text); txtDirectory.Text = FileSystemDirectoryFilterEntry.GetDirectoryFromPath(txtDirectory.Text); } if (!Directory.Exists(txtDirectory.Text)) { MessageBox.Show("Directory must exist and be accessible!", "Directory", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (!chkDirectoryExistOnly.Checked && !chkCheckIfFilesExistOnly.Checked && !chkErrorOnFilesExist.Checked && numericUpDownCountWarningIndicator.Value > numericUpDownCountErrorIndicator.Value) { MessageBox.Show("Error file count cannot be less than warning file count!", "Warnings/Errors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (!chkDirectoryExistOnly.Checked && !chkCheckIfFilesExistOnly.Checked && !chkErrorOnFilesExist.Checked && numericUpDownSizeWarningIndicator.Value > numericUpDownSizeErrorIndicator.Value) { MessageBox.Show("Error file size cannot be less than warning file size!", "Warnings/Errors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { FileSystemDirectoryFilterEntry selectedEntry; if (SelectedEntry != null) { selectedEntry = (FileSystemDirectoryFilterEntry)SelectedEntry; } else if (SelectedFilterEntry != null) { selectedEntry = (FileSystemDirectoryFilterEntry)SelectedFilterEntry; } else { selectedEntry = new FileSystemDirectoryFilterEntry(); } selectedEntry.DirectoryPath = txtDirectory.Text; selectedEntry.DirectoryExistOnly = chkDirectoryExistOnly.Checked; selectedEntry.FileFilter = txtFilter.Text; selectedEntry.FilesExistOnly = chkCheckIfFilesExistOnly.Checked; selectedEntry.ErrorOnFilesExist = chkErrorOnFilesExist.Checked; selectedEntry.ContainsText = txtContains.Text; selectedEntry.UseRegEx = chkUseRegEx.Checked; selectedEntry.CountWarningIndicator = Convert.ToInt32(numericUpDownCountWarningIndicator.Value); selectedEntry.CountErrorIndicator = Convert.ToInt32(numericUpDownCountErrorIndicator.Value); selectedEntry.SizeKBWarningIndicator = (int)numericUpDownSizeWarningIndicator.Value; selectedEntry.SizeKBErrorIndicator = (int)numericUpDownSizeErrorIndicator.Value; selectedEntry.FileMinAgeSec = (int)numericUpDownFileAgeMin.Value; selectedEntry.FileMaxAgeSec = (int)numericUpDownFileAgeMax.Value; selectedEntry.FileMinSizeKB = (int)numericUpDownFileSizeMin.Value; selectedEntry.FileMaxSizeKB = (int)numericUpDownFileSizeMax.Value; SelectedEntry = selectedEntry; DialogResult = DialogResult.OK; Close(); } }
public void FromXml(string configurationString) { XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); Entries.Clear(); System.Xml.XmlElement root = config.DocumentElement; foreach (System.Xml.XmlElement host in root.SelectNodes("directoryList/directory")) { FileSystemDirectoryFilterEntry directoryFilterEntry = new FileSystemDirectoryFilterEntry(); directoryFilterEntry.FilterFullPath = host.Attributes.GetNamedItem("directoryPathFilter").Value; directoryFilterEntry.DirectoryExistOnly = bool.Parse(host.ReadXmlElementAttr("testDirectoryExistOnly", "False")); directoryFilterEntry.FilesExistOnly = bool.Parse(host.ReadXmlElementAttr("testFilesExistOnly", "False")); directoryFilterEntry.ErrorOnFilesExist = bool.Parse(host.ReadXmlElementAttr("errorOnFilesExist", "False")); directoryFilterEntry.IncludeSubDirectories = bool.Parse(host.ReadXmlElementAttr("includeSubDirs", "False")); directoryFilterEntry.ContainsText = host.ReadXmlElementAttr("containsText", ""); directoryFilterEntry.UseRegEx = host.ReadXmlElementAttr("useRegEx", false); int tmp = 0; if (int.TryParse(host.ReadXmlElementAttr("warningFileCountMax", "0"), out tmp)) { directoryFilterEntry.CountWarningIndicator = tmp; } if (int.TryParse(host.ReadXmlElementAttr("errorFileCountMax", "0"), out tmp)) { directoryFilterEntry.CountErrorIndicator = tmp; } long tmpl; directoryFilterEntry.FileSizeIndicatorUnit = (FileSizeUnits)Enum.Parse(typeof(FileSizeUnits), host.ReadXmlElementAttr("fileSizeIndicatorUnit", "KB")); if (long.TryParse(host.ReadXmlElementAttr("warningFileSizeMax", "0"), out tmpl)) { directoryFilterEntry.SizeWarningIndicator = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("errorFileSizeMax", "0"), out tmpl)) { directoryFilterEntry.SizeErrorIndicator = tmpl; } directoryFilterEntry.FileAgeUnit = (TimeUnits)Enum.Parse(typeof(TimeUnits), host.ReadXmlElementAttr("fileAgeUnit", "Minute")); if (long.TryParse(host.ReadXmlElementAttr("fileMinAge", "0"), out tmpl)) { directoryFilterEntry.FileMinAge = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("fileMaxAge", "0"), out tmpl)) { directoryFilterEntry.FileMaxAge = tmpl; } directoryFilterEntry.FileSizeUnit = (FileSizeUnits)Enum.Parse(typeof(FileSizeUnits), host.ReadXmlElementAttr("fileSizeUnit", "KB")); if (long.TryParse(host.ReadXmlElementAttr("fileMinSize", "0"), out tmpl)) { directoryFilterEntry.FileMinSize = tmpl; } if (long.TryParse(host.ReadXmlElementAttr("fileMaxSize", "0"), out tmpl)) { directoryFilterEntry.FileMaxSize = tmpl; } directoryFilterEntry.ShowFilenamesInDetails = host.ReadXmlElementAttr("showFilenamesInDetails", false); directoryFilterEntry.ShowFileCountInOutputValue = host.ReadXmlElementAttr("showFileCountInOutputValue", true); directoryFilterEntry.ShowFileSizeInOutputValue = host.ReadXmlElementAttr("showFileSizeInOutputValue", false); directoryFilterEntry.PrimaryUIValue = host.ReadXmlElementAttr("primaryUIValue", false); Entries.Add(directoryFilterEntry); } }