Exemple #1
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml("<config><directoryList></directoryList></config>");
            XmlNode directoryList = config.SelectSingleNode("config/directoryList");

            foreach (ListViewItem lvi in lvwDirectories.Items)
            {
                DirectoryFilterEntry de  = (DirectoryFilterEntry)lvi.Tag;
                XmlNode directoryXmlNode = config.CreateElement("directory");

                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("directoryPathFilter", de.FilterFullPath));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("testDirectoryExistOnly", de.DirectoryExistOnly));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("warningFileCountMax", de.CountWarningIndicator));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("errorFileCountMax", de.CountErrorIndicator));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("warningFileSizeMaxKB", de.SizeKBWarningIndicator));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("errorFileSizeMaxKB", de.SizeKBErrorIndicator));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("fileMinAgeSec", de.FileMinAgeSec));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("fileMaxAgeSec", de.FileMaxAgeSec));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("fileMinSizeKB", de.FileMinSizeKB));
                directoryXmlNode.Attributes.Append(config.CreateAttributeWithValue("fileMaxSizeKB", de.FileMaxSizeKB));

                directoryList.AppendChild(directoryXmlNode);
            }

            CustomConfig = config.OuterXml;
            DialogResult = DialogResult.OK;
            Close();
        }
Exemple #2
0
        private List <DirectoryFilterEntry> ReadConfig()
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(CustomConfig);
            List <DirectoryFilterEntry> directorieFilters = new List <DirectoryFilterEntry>();

            System.Xml.XmlElement root = config.DocumentElement;
            foreach (XmlElement host in root.SelectNodes("directoryList/directory"))
            {
                DirectoryFilterEntry directoryFilterEntry = new DirectoryFilterEntry();
                directoryFilterEntry.FilterFullPath     = host.Attributes.GetNamedItem("directoryPathFilter").Value;
                directoryFilterEntry.DirectoryExistOnly = bool.Parse(host.ReadXmlElementAttr("testDirectoryExistOnly", "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;
                }

                directorieFilters.Add(directoryFilterEntry);
            }
            return(directorieFilters);
        }
Exemple #3
0
        private DirectoryFileInfo GetDirFileInfo(DirectoryFilterEntry directoryFilterEntry)
        {
            DirectoryFileInfo fileInfo;

            fileInfo.Exists    = false;
            fileInfo.FileCount = 0;
            fileInfo.FileSize  = 0;
            fileInfo.FileInfos = new List <FileInfo>();
            try
            {
                if (Directory.Exists(directoryFilterEntry.DirectoryPath))
                {
                    fileInfo.Exists = true;
                    if (!directoryFilterEntry.DirectoryExistOnly)
                    {
                        foreach (string filePath in System.IO.Directory.GetFiles(directoryFilterEntry.DirectoryPath, directoryFilterEntry.FileFilter))
                        {
                            System.IO.FileInfo fi = new System.IO.FileInfo(filePath);

                            if ((directoryFilterEntry.FileMaxAgeSec == 0 || fi.LastWriteTime.AddSeconds(directoryFilterEntry.FileMaxAgeSec) > DateTime.Now) &&
                                (directoryFilterEntry.FileMinAgeSec == 0 || fi.LastWriteTime.AddSeconds(directoryFilterEntry.FileMinAgeSec) < DateTime.Now) &&
                                (directoryFilterEntry.FileMaxSizeKB == 0 || fi.Length <= (directoryFilterEntry.FileMaxSizeKB * 1024)) &&
                                (directoryFilterEntry.FileMinSizeKB == 0 || fi.Length >= (directoryFilterEntry.FileMinSizeKB * 1024))
                                )
                            {
                                fileInfo.FileSize  += fi.Length;
                                fileInfo.FileCount += 1;
                                fileInfo.FileInfos.Add(fi);
                            }
                        }
                    }
                }
                else
                {
                    fileInfo.Exists    = false;
                    LastErrorMsg       = "Directory '" + directoryFilterEntry.DirectoryPath + "' does not exist!";
                    fileInfo.FileCount = -1;
                    fileInfo.FileSize  = -1;
                }
            }
            catch (Exception ex)
            {
                LastErrorMsg       = ex.ToString();
                fileInfo.FileCount = -1;
                fileInfo.FileSize  = -1;
            }
            return(fileInfo);
        }
Exemple #4
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (txtFilter.Text.Length == 0)
            {
                txtFilter.Text = "*.*";
            }
            if (txtDirectory.Text.Contains("*"))
            {
                txtFilter.Text    = DirectoryFilterEntry.GetFilterFromPath(txtDirectory.Text);
                txtDirectory.Text = DirectoryFilterEntry.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 && 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 && numericUpDownSizeWarningIndicator.Value > numericUpDownSizeErrorIndicator.Value)
            {
                MessageBox.Show("Error file size cannot be less than warning file size!", "Warnings/Errors", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                SelectedDirectoryFilterEntry.DirectoryPath          = txtDirectory.Text;
                SelectedDirectoryFilterEntry.FileFilter             = txtFilter.Text;
                SelectedDirectoryFilterEntry.CountWarningIndicator  = Convert.ToInt32(numericUpDownCountWarningIndicator.Value);
                SelectedDirectoryFilterEntry.CountErrorIndicator    = Convert.ToInt32(numericUpDownCountErrorIndicator.Value);
                SelectedDirectoryFilterEntry.SizeKBWarningIndicator = (int)numericUpDownSizeWarningIndicator.Value;
                SelectedDirectoryFilterEntry.SizeKBErrorIndicator   = (int)numericUpDownSizeErrorIndicator.Value;
                SelectedDirectoryFilterEntry.FileMinAgeSec          = (int)numericUpDownFileAgeMin.Value;
                SelectedDirectoryFilterEntry.FileMaxAgeSec          = (int)numericUpDownFileAgeMax.Value;
                SelectedDirectoryFilterEntry.FileMinSizeKB          = (int)numericUpDownFileSizeMin.Value;
                SelectedDirectoryFilterEntry.FileMaxSizeKB          = (int)numericUpDownFileSizeMax.Value;
                SelectedDirectoryFilterEntry.DirectoryExistOnly     = chkDirectoryExistOnly.Checked;

                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemple #5
0
        private void LoadDirInfo(ListViewItem itm)
        {
            //int count = 0;
            string countString = "-";
            string oldValue    = "-";

            try
            {
                DirectoryFilterEntry filterEntry  = (DirectoryFilterEntry)itm.Tag;
                DirectoryFileInfo    fileInfo     = filterEntry.GetDirFileInfo();
                MonitorStates        currentState = filterEntry.GetState(fileInfo);

                oldValue = itm.SubItems[1].Text;
                if (!fileInfo.Exists)
                {
                    countString = "N/A";
                }
                else
                {
                    countString = fileInfo.FileCount.ToString();
                }
                if (fileInfo.FileSize >= 0)
                {
                    itm.SubItems[2].Text = fileInfo.FileSize.ToString();
                }
                else
                {
                    itm.SubItems[2].Text = "N/A";
                }
                if (currentState == MonitorStates.Good)
                {
                    itm.BackColor = SystemColors.Window;
                }
                else if (currentState == MonitorStates.Warning)
                {
                    itm.BackColor = Color.SandyBrown;
                }
                else
                {
                    itm.BackColor = Color.Salmon;
                }

                //count = GetDirFileCount(itm);
                //if (count == -1)
                //{
                //    countString = "N/A";
                //}
                //else
                //{
                //    countString = count.ToString();
                //}
            }
            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));
            }
        }
Exemple #6
0
 public EditDirectory()
 {
     InitializeComponent();
     SelectedDirectoryFilterEntry            = new DirectoryFilterEntry();
     SelectedDirectoryFilterEntry.FileFilter = "*.*";
 }