Beispiel #1
0
        public DialogResult ShowConfig()
        {
            if (CustomConfig.Length > 0)
            {
                try
                {
                    XmlDocument config = new XmlDocument();
                    config.LoadXml(CustomConfig);

                    XmlNodeList hostListNodes = config.GetElementsByTagName("host");
                    foreach (XmlNode hostXmlNode in hostListNodes)
                    {
                        HostEntry hostEntry = new HostEntry();
                        hostEntry.HostName    = hostXmlNode.Attributes.GetNamedItem("hostName").Value;
                        hostEntry.Description = hostXmlNode.Attributes.GetNamedItem("description").Value;
                        hostEntry.MaxTime     = int.Parse(hostXmlNode.Attributes.GetNamedItem("maxTime").Value);
                        hostEntry.TimeOut     = int.Parse(hostXmlNode.Attributes.GetNamedItem("timeOut").Value);

                        ListViewItem lvi = new ListViewItem(hostEntry.HostName);
                        lvi.SubItems.Add(hostEntry.MaxTime.ToString());
                        lvi.SubItems.Add(hostEntry.TimeOut.ToString());
                        lvi.SubItems.Add(hostEntry.Description);
                        lvi.Tag = hostEntry;
                        lvwHosts.Items.Add(lvi);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return(ShowDialog());
        }
Beispiel #2
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml("<config><hosts></hosts></config>");

            XmlNode hostsListNode = config.SelectSingleNode("config/hosts");

            foreach (ListViewItem lvi in lvwHosts.Items)
            {
                HostEntry hostEntry = (HostEntry)lvi.Tag;

                XmlNode      hostXmlNode          = config.CreateElement("host");
                XmlAttribute hostNameXmlAttribute = config.CreateAttribute("hostName");
                hostNameXmlAttribute.Value = hostEntry.HostName;
                hostXmlNode.Attributes.Append(hostNameXmlAttribute);
                XmlAttribute descriptionXmlAttribute = config.CreateAttribute("description");
                descriptionXmlAttribute.Value = hostEntry.Description;
                hostXmlNode.Attributes.Append(descriptionXmlAttribute);
                XmlAttribute maxTimeXmlAttribute = config.CreateAttribute("maxTime");
                maxTimeXmlAttribute.Value = hostEntry.MaxTime.ToString();
                hostXmlNode.Attributes.Append(maxTimeXmlAttribute);
                XmlAttribute timeOutXmlAttribute = config.CreateAttribute("timeOut");
                timeOutXmlAttribute.Value = hostEntry.TimeOut.ToString();
                hostXmlNode.Attributes.Append(timeOutXmlAttribute);

                hostsListNode.AppendChild(hostXmlNode);
            }

            CustomConfig = config.OuterXml;
            DialogResult = DialogResult.OK;
            Close();
        }
Beispiel #3
0
 private void RefreshList()
 {
     System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
     lvwHosts.BeginUpdate();
     foreach (ListViewItem itmX in lvwHosts.Items)
     {
         HostEntry host = (HostEntry)itmX.Tag;
         try
         {
             PingResult    pingResult = host.Ping();
             MonitorStates result     = host.GetState(pingResult);
             if (pingResult.Success)
             {
                 itmX.SubItems[1].Text = pingResult.PingTime.ToString();
                 itmX.SubItems[2].Text = pingResult.LastErrorMsg;
                 if (result == MonitorStates.Good)
                 {
                     itmX.ImageIndex = 0;
                     itmX.BackColor  = SystemColors.Window;
                 }
                 else if (result == MonitorStates.Warning)
                 {
                     itmX.ImageIndex = 1;
                     itmX.BackColor  = Color.SandyBrown;
                 }
                 else
                 {
                     itmX.ImageIndex = 2;
                     itmX.BackColor  = Color.Salmon;
                 }
             }
             else
             {
                 itmX.ImageIndex       = 2;
                 itmX.BackColor        = Color.Salmon;
                 itmX.SubItems[1].Text = "Err";
                 itmX.SubItems[2].Text = pingResult.LastErrorMsg;
             }
         }
         catch (Exception ex)
         {
             itmX.ImageIndex       = 2;
             itmX.SubItems[1].Text = "Err";
             itmX.SubItems[2].Text = ex.Message;
             itmX.BackColor        = Color.Salmon;
         }
     }
     lvwHosts.EndUpdate();
     System.Windows.Forms.Cursor.Current = Cursors.Default;
     toolStripStatusLabel1.Text          = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
 }
Beispiel #4
0
        public override void ReadConfiguration(XmlDocument config)
        {
            HostEntries = new List <HostEntry>();
            XmlElement root = config.DocumentElement;

            foreach (XmlElement host in root.SelectNodes("hosts/host"))
            {
                HostEntry hostEntry = new HostEntry();
                hostEntry.HostName    = host.Attributes.GetNamedItem("hostName").Value;
                hostEntry.Description = host.Attributes.GetNamedItem("description").Value;
                int tmp = 0;
                if (int.TryParse(host.Attributes.GetNamedItem("maxTime").Value, out tmp))
                {
                    hostEntry.MaxTime = tmp;
                }
                if (int.TryParse(host.Attributes.GetNamedItem("timeOut").Value, out tmp))
                {
                    hostEntry.TimeOut = tmp;
                }
                HostEntries.Add(hostEntry);
            }
        }