Example #1
0
        public MainForm()
        {
            InitializeComponent();

            m = new Main();
            settings = new Settings(m);

            #region Get Targets

            XmlDocument xmlTargets = settings.GetTargets();
            foreach (XmlNode node in xmlTargets.SelectNodes("/PingInstanceList/PingInstance"))
            {
                var target = IPAddress.Parse(node.Attributes["target"].Value);
                int interval = int.Parse(node.Attributes["interval"].Value);
                int timeout = int.Parse(node.Attributes["timeout"].Value);
                int bufferSize = int.Parse(node.Attributes["bufferSize"].Value);
                string name = node.Attributes["name"].Value.ToString();
                string id = node.Attributes["id"].Value;
                bool autostart = node.Attributes["autostart"].Value.Equals("true", StringComparison.InvariantCultureIgnoreCase);

                int intId = 0;
                if (int.TryParse(id, out intId))
                {
                    if (intId > maxPingInstanceId)
                    {
                        maxPingInstanceId = intId;
                    }
                }
                else
                {
                    // TODO
                }

                PingInstance pi = new PingInstance(pingObject)
                {
                    Target = target,
                    Interval = interval,
                    Timeout = timeout,
                    BufferSize = bufferSize,
                    Name = name,
                    Id = id,
                    Autostart = autostart,
                    Status = PingResultStatus.Idle
                };

                pi.PingReceived += pi_PingReceived;
                pi.Uc = new ucPingInstance(pi);
                m.PingInstances.Add(pi);
            }

            #endregion

            #region Get Nodes

            var xmlNodes = settings.GetNodes();

            foreach (XmlNode node in xmlNodes.SelectNodes("/NodeList/Node"))
            {
                string id = node.Attributes["id"].Value;
                string parentId = node.Attributes["parentNodeId"].Value;
                string name = node.Attributes["name"].Value;

                int intId = 0;
                if (int.TryParse(id, out intId))
                {
                    if (intId > maxNodeId)
                    {
                        maxNodeId = intId;
                    }
                }
                else
                {
                    // TODO
                }

                Location l = new Location()
                {
                    Id = id,
                    ParentId = parentId,
                    Name = name
                };

                m.Locations.Add(l);
            }

            #endregion

            #region Get Ping Instance Locations

            var xmlPingInstanceLocations = settings.GetPingInstanceLocations();

            foreach (XmlNode loc in xmlPingInstanceLocations.SelectNodes("/PingInstanceLocations/PingInstanceLocation"))
            {
                string nodeId = loc.Attributes["nodeId"].Value;
                string pingInstanceId = loc.Attributes["pingInstanceId"].Value;

                var node = m.Locations.FirstOrDefault(x => x.Id.Equals(nodeId));
                if (node != null)
                {
                    node.PingInstanceIds.Add(pingInstanceId);
                }
            }

            #endregion

            ShowLocations(tvwLocations);
            ShowPingInstances(string.Empty);

            m.Autostart();
        }