Пример #1
0
        private void btnLaunch_Click(object sender, EventArgs e)
        {
            if (this.treeSites.SelectedNode == null)
            {
                MessageBox.Show("Please select an NAE to launch.");
                return;
            }

            if (this.treeSites.SelectedNode.Tag is NAE)
            {
                try
                {
                    NAE nae = (NAE)this.treeSites.SelectedNode.Tag;

                    if (!StaticIP.IsIPv4(nae.IPAddress))
                    {
                        MessageBox.Show("Please enter a valid IP address for the NAE.");
                        return;
                    }

                    nae.Launch();
                }
                catch (Exception ex)
                {
                    Logger.WriteMessage("Error in launching NAE.");
                    Logger.WriteException(ex);
                    Logger.PromptLogReview("There was an error launching the NAE.");
                }
            }
            else
            {
                MessageBox.Show("Please select an NAE to launch.");
                return;
            }
        }
Пример #2
0
        private void exportToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            NAE            nae            = (NAE)this.treeSites.SelectedNode.Tag;

            saveFileDialog.Filter           = "XML Files (*.xml)|*.xml";
            saveFileDialog.FilterIndex      = 2;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName         = nae.Name + ".xml";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    XDocument document = new XDocument(nae.ToXML());
                    document.Save(saveFileDialog.FileName);
                }
                catch (Exception ex)
                {
                    Logger.WriteMessage("Failed to save XML file: " + saveFileDialog.FileName);
                    Logger.WriteException(ex);
                    Logger.PromptLogReview("An error occurred in saving the file, you may not have appropriate permissions.");
                }
            }
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            NAE nae = (NAE)this.listDevices.SelectedItems[0].Tag;

            nae.StaticIPAddress = this.generateStatic(nae.IPAddress);
            frmImport frm = new frmImport();

            foreach (Site site in Sites.FromTreeView(this.mainFrm.treeSites))
            {
                frm.comboSite.Items.Add(site.Name);
            }

            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK && !String.IsNullOrEmpty((String)frm.comboSite.SelectedItem))
            {
                String selectedSite = (String)frm.comboSite.SelectedItem;
                foreach (TreeNode node in this.mainFrm.treeSites.Nodes)
                {
                    Site site = (Site)node.Tag;
                    if (selectedSite.Equals(site.Name))
                    {
                        site.NAEs.Add(nae);
                        FormHandler.AddNAEToTree(node.Nodes, nae);
                    }
                }
            }
        }
Пример #4
0
        private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            TreeNode node = this.treeSites.SelectedNode;
            NAE      nae  = (NAE)node.Tag;

            Clipboard.SetText(nae.ToXML().ToString());
        }
Пример #5
0
        public static void AddNewNAEToTree(TreeView tree, TreeNode siteNode)
        {
            NAE nae = new NAE {
                Name = "New NAE"
            };
            TreeNode naeNode = new TreeNode(nae.Name);

            naeNode.Tag = nae;
            naeNode.ContextMenuStrip = frmMain.StaticContextNAE;

            if (!(siteNode.Tag is Site))
            {
                // Throw error
            }

            Site site = (Site)siteNode.Tag;

            site.NAEs.Add(nae);
            siteNode.Nodes.Add(naeNode);
            tree.LabelEdit = true;

            if (!naeNode.IsEditing)
            {
                naeNode.BeginEdit();
            }
        }
Пример #6
0
        public static void PacketHandler(Packet packet)
        {
            Console.WriteLine(packet.Timestamp.ToString("yyyy-MM-dd hh:mm:ss.fff") + " Length: " + packet.Length);

            IpV4Datagram ip      = packet.Ethernet.IpV4;
            UdpDatagram  udp     = ip.Udp;
            Datagram     payload = udp.Payload;

            byte[] data = payload.ToArray();
            NAE    nae  = NAEHandler.parseNAEFromPacket(data);
            String msg  = nae.Name + " reported online.";

            NAEHandler.listenFrm.Invoke(NAEHandler.listenFrm.AddNAEDelegate, new object[] { nae });

            if (NAEHandler.mainFrm.notifyIcon.Visible == true)
            {
                NAEHandler.mainFrm.notifyIcon.BalloonTipText = msg;
                NAEHandler.mainFrm.notifyIcon.ShowBalloonTip(500);
            }
            else
            {
                NAEHandler.mainFrm.notifyIcon.Visible        = true;
                NAEHandler.mainFrm.notifyIcon.BalloonTipText = msg;
                NAEHandler.mainFrm.notifyIcon.ShowBalloonTip(500);
                System.Threading.Thread.Sleep(3000);
                NAEHandler.mainFrm.notifyIcon.Visible = false;
            }
        }
Пример #7
0
        private void deleteToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Site site = (Site)this.treeSites.SelectedNode.Parent.Tag;
            NAE  nae  = (NAE)this.treeSites.SelectedNode.Tag;

            site.NAEs.Remove(nae);
            this.treeSites.Nodes.Remove(this.treeSites.SelectedNode);
        }
Пример #8
0
        public static void AddNAEToTree(TreeNodeCollection nodes, NAE nae)
        {
            TreeNode naeNode = new TreeNode(nae.Name);
            naeNode.Tag = nae;
            naeNode.ContextMenuStrip = frmMain.StaticContextNAE;

            nodes.Add(naeNode);
        }
Пример #9
0
        public static void AddNAEToTree(TreeNodeCollection nodes, NAE nae)
        {
            TreeNode naeNode = new TreeNode(nae.Name);

            naeNode.Tag = nae;
            naeNode.ContextMenuStrip = frmMain.StaticContextNAE;

            nodes.Add(naeNode);
        }
Пример #10
0
 public static NAE FromXML(XElement xnae)
 {
     NAE nae = new NAE { Name = xnae.Attribute("Name").Value,
                         IPAddress = xnae.Element("IPAddress").Value,
                         MAC = xnae.Element("MAC").Value,
                         OSVersion = xnae.Element("OSVersion").Value,
                         MSEAVersion = xnae.Element("MSEAVersion").Value,
                         NeuronID = xnae.Element("NeuronID").Value,
                         StaticIPAddress = StaticIP.FromXML(xnae.Element("StaticIP")) };
     return nae;
 }
Пример #11
0
 private void treeSites_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
 {
     if (e.Node.Tag is Site)
     {
         Site site = (Site)e.Node.Tag;
         site.Name = e.Label;
     }
     else if (e.Node.Tag is NAE)
     {
         NAE nae = (NAE)e.Node.Tag;
         nae.Name = e.Label;
     }
 }
Пример #12
0
        public static NAE FromXML(XElement xnae)
        {
            NAE nae = new NAE {
                Name            = xnae.Attribute("Name").Value,
                IPAddress       = xnae.Element("IPAddress").Value,
                MAC             = xnae.Element("MAC").Value,
                OSVersion       = xnae.Element("OSVersion").Value,
                MSEAVersion     = xnae.Element("MSEAVersion").Value,
                NeuronID        = xnae.Element("NeuronID").Value,
                StaticIPAddress = StaticIP.FromXML(xnae.Element("StaticIP"))
            };

            return(nae);
        }
Пример #13
0
 private void launchToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         NAE nae = (NAE)this.treeSites.SelectedNode.Tag;
         nae.Launch();
     }
     catch (Exception ex)
     {
         Logger.WriteMessage("Failed to launch NAE.");
         Logger.WriteException(ex);
         Logger.PromptLogReview("Failed to launch NAE.");
     }
 }
Пример #14
0
        public static Site FromXML(XElement xsite)
        {
            List <NAE> naes = new List <NAE>();

            foreach (XElement xnae in xsite.Element("NAEs").Elements())
            {
                naes.Add(NAE.FromXML(xnae));
            }

            Site site = new Site {
                Name = xsite.Attribute("Name").Value,
                NAEs = naes
            };

            return(site);
        }
Пример #15
0
        public void AddNAE(NAE nae)
        {
            foreach(NAE listnae in this.naes)
            {
                if (listnae.IPAddress.Equals(nae.IPAddress))
                {
                    return;
                }
            }

            string[] row = new string[] { nae.Name, nae.IPAddress, nae.MAC, nae.OSVersion, nae.MSEAVersion, nae.NeuronID };
            ListViewItem item = new ListViewItem(row);
            item.Tag = nae;

            this.listDevices.Items.Add(item);
            this.naes.Add(nae);
        }
Пример #16
0
        public void AddNAE(NAE nae)
        {
            foreach (NAE listnae in this.naes)
            {
                if (listnae.IPAddress.Equals(nae.IPAddress))
                {
                    return;
                }
            }

            string[]     row  = new string[] { nae.Name, nae.IPAddress, nae.MAC, nae.OSVersion, nae.MSEAVersion, nae.NeuronID };
            ListViewItem item = new ListViewItem(row);

            item.Tag = nae;

            this.listDevices.Items.Add(item);
            this.naes.Add(nae);
        }
Пример #17
0
 private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.treeSites.SelectedNode != null)
     {
         if (!String.IsNullOrEmpty(Clipboard.GetText()))
         {
             try
             {
                 TreeNodeCollection nodes = this.treeSites.SelectedNode.Nodes;
                 XElement           xnae  = XElement.Parse(Clipboard.GetText());
                 FormHandler.AddNAEToTree(nodes, NAE.FromXML(xnae));
             }
             catch (Exception ex)
             {
                 Logger.WriteMessage("Error in pasting NAE.");
                 Logger.WriteException(ex);
                 Logger.PromptLogReview("Failed to paste the NAE, the data in the clipboard may be corrupt.");
             }
         }
     }
 }
Пример #18
0
        private void btnSetStatic_Click(object sender, EventArgs e)
        {
            if (this.treeSites.SelectedNode == null)
            {
                MessageBox.Show("Please select an NAE to set a static IP for.");
                return;
            }

            if (!(this.treeSites.SelectedNode.Tag is NAE))
            {
                MessageBox.Show("Please select an NAE to set a static IP for.");
                return;
            }

            try
            {
                NAE nae = (NAE)this.treeSites.SelectedNode.Tag;
                NIC nic = (NIC)this.comboAdapterList.SelectedItem;

                if (!StaticIP.IsIPv4(nae.StaticIPAddress.Address) || !StaticIP.IsIPv4(nae.StaticIPAddress.SubnetMask) || !StaticIP.IsIPv4(nae.StaticIPAddress.DefaultGateway))
                {
                    MessageBox.Show("Please enter valid IP addresses for the NAE's static IP address, subnet mask, and gateway.");
                    return;
                }

                nic.SetStaticIP(nae.StaticIPAddress.Address, nae.StaticIPAddress.SubnetMask, nae.StaticIPAddress.DefaultGateway);
                NIC.LoadNICs(this.comboAdapterList);
                nic.ReselectNIC(this.comboAdapterList);

                nic = (NIC)this.comboAdapterList.SelectedItem;
                FormHandler.UpdateNICText(nic, this.txtAdapterIPAddress, this.txtAdapterSubnetMask, this.txtAdapterDefaultGateway);
            }
            catch (Exception ex)
            {
                Logger.WriteMessage("Error in setting the static IP address.");
                Logger.WriteException(ex);
                Logger.PromptLogReview("There was an error in setting the static IP address.");
            }
        }
Пример #19
0
        private void dataNAE_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = this.dataNAE.Rows[e.RowIndex];
            NAE             nae = (NAE)row.Tag;

            Console.WriteLine(nae.Name);

            switch (e.RowIndex)
            {
            case 0:
                nae.IPAddress = (String)row.Cells[1].Value;
                break;

            case 1:
                nae.MAC = (String)row.Cells[1].Value;
                break;

            case 2:
                nae.OSVersion = (String)row.Cells[1].Value;
                break;

            case 3:
                nae.MSEAVersion = (String)row.Cells[1].Value;
                break;

            case 4:
                nae.StaticIPAddress.Address = (String)row.Cells[1].Value;
                break;

            case 5:
                nae.StaticIPAddress.SubnetMask = (String)row.Cells[1].Value;
                break;

            case 6:
                nae.StaticIPAddress.DefaultGateway = (String)row.Cells[1].Value;
                break;
            }
        }
Пример #20
0
        private void treeSites_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Tag is NAE)
            {
                NAE nae = (NAE)e.Node.Tag;

                string[]   ip            = new string[] { "IP Address:", nae.IPAddress };
                string[]   mac           = new string[] { "MAC Address:", nae.MAC };
                string[]   osversion     = new string[] { "OS Version:", nae.OSVersion };
                string[]   mseaversion   = new string[] { "MSEA Version:", nae.MSEAVersion };
                string[]   staticip      = new string[] { "Static IP:", nae.StaticIPAddress.Address };
                string[]   staticsubnet  = new string[] { "Static Subnet:", nae.StaticIPAddress.SubnetMask };
                string[]   staticgateway = new string[] { "Static Gateway:", nae.StaticIPAddress.DefaultGateway };
                string[][] fields        = new string[][] { ip, mac, osversion, mseaversion, staticip, staticsubnet, staticgateway };

                this.dataNAE.Rows.Clear();
                foreach (string[] field in fields)
                {
                    int index = this.dataNAE.Rows.Add(field);
                    this.dataNAE.Rows[index].Tag = nae;
                }
            }
        }
Пример #21
0
        public static void AddNewNAEToTree(TreeView tree, TreeNode siteNode)
        {
            NAE nae = new NAE { Name = "New NAE" };
            TreeNode naeNode = new TreeNode(nae.Name);

            naeNode.Tag = nae;
            naeNode.ContextMenuStrip = frmMain.StaticContextNAE;

            if (!(siteNode.Tag is Site))
            {
                // Throw error
            }

            Site site = (Site)siteNode.Tag;
            site.NAEs.Add(nae);
            siteNode.Nodes.Add(naeNode);
            tree.LabelEdit = true;

            if (!naeNode.IsEditing)
            {
                naeNode.BeginEdit();
            }
        }
Пример #22
0
        private void importNAEToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "XML Files (*.xml)|*.xml";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    XElement xnae = XDocument.Load(openFileDialog.FileName).Root;
                    FormHandler.AddNAEToTree(this.treeSites.SelectedNode.Nodes, NAE.FromXML(xnae));
                }
                catch (Exception ex)
                {
                    Logger.WriteMessage("Failed to load XML file: " + openFileDialog.FileName);
                    Logger.WriteException(ex);
                    Logger.PromptLogReview("An error occurred in loading the file, it may be corrupted.");
                }
            }
        }
Пример #23
0
        private static NAE parseNAEFromPacket(byte[] packet)
        {
            int index  = 8;
            int count  = 0;
            int length = packet.Length;
            NAE nae    = new NAE();

            while (index < length)
            {
                if ((index + 2) > length)
                {
                    goto Finish;
                }

                MessageFields fields = (MessageFields)packet[index];
                count = packet[++index];

                if ((index + count) > length)
                {
                    goto Finish;
                }

                index++;
                switch (fields)
                {
                case MessageFields.IPV4Address:
                    var ipa = new System.Net.IPAddress((long)BitConverter.ToUInt32(packet, index));
                    nae.IPAddress = ipa.ToString();
                    break;

                case MessageFields.Name:
                    nae.Name = Encoding.ASCII.GetString(packet, index, count);
                    break;

                case MessageFields.MACAddress:
                    nae.MAC = packet[index].ToString("x2") + ":" + packet[index + 1].ToString("x2") + ":" + packet[index + 2].ToString("x2") + ":" + packet[index + 3].ToString("x2") + ":" + packet[index + 4].ToString("x2") + ":" + packet[index + 5].ToString("x2");
                    break;

                case MessageFields.OSVersion:
                    nae.OSVersion = Encoding.ASCII.GetString(packet, index, count);
                    break;

                case MessageFields.Message:
                    // Future: Console.WriteLine("Message: " + Encoding.ASCII.GetString(packet, index, count));
                    break;

                case MessageFields.ProductCode:
                    // Future: Console.WriteLine("Product Code: " + Encoding.ASCII.GetString(packet, index, count));
                    break;

                case MessageFields.BatteryStatus:
                    //Future: Console.WriteLine("Battery Status: " + Encoding.ASCII.GetString(packet, index, count));
                    break;

                case MessageFields.NeuronID:
                    nae.NeuronID = packet[index].ToString("x2") + ":" + packet[index + 1].ToString("x2") + ":" + packet[index + 2].ToString("x2") + ":" + packet[index + 3].ToString("x2") + ":" + packet[index + 4].ToString("x2") + ":" + packet[index + 5].ToString("x2");
                    break;

                case MessageFields.DHCPEnabled:
                    //Future: Console.WriteLine("DHCP Enabled: " + (packet[index] == 1));
                    break;

                case MessageFields.MessageReason:
                    //Future
                    break;

                case MessageFields.MSEAVersion:
                    nae.MSEAVersion = Encoding.ASCII.GetString(packet, index, count);
                    break;
                }
                index += count;
            }

Finish:
            return(nae);
        }
Пример #24
0
        private static NAE parseNAEFromPacket(byte[] packet)
        {
            int index = 8;
            int count = 0;
            int length = packet.Length;
            NAE nae = new NAE();

            while (index < length)
            {
                if ((index + 2) > length)
                {
                    goto Finish;
                }

                MessageFields fields = (MessageFields)packet[index];
                count = packet[++index];

                if ((index + count) > length)
                {
                    goto Finish;
                }

                index++;
                switch (fields)
                {
                    case MessageFields.IPV4Address:
                        var ipa = new System.Net.IPAddress((long)BitConverter.ToUInt32(packet, index));
                        nae.IPAddress = ipa.ToString();
                        break;
                    case MessageFields.Name:
                        nae.Name = Encoding.ASCII.GetString(packet, index, count);
                        break;
                    case MessageFields.MACAddress:
                        nae.MAC = packet[index].ToString("x2") + ":" + packet[index + 1].ToString("x2") + ":" + packet[index + 2].ToString("x2") + ":" + packet[index + 3].ToString("x2") + ":" + packet[index + 4].ToString("x2") + ":" + packet[index + 5].ToString("x2");
                        break;
                    case MessageFields.OSVersion:
                        nae.OSVersion = Encoding.ASCII.GetString(packet, index, count);
                        break;
                    case MessageFields.Message:
                        // Future: Console.WriteLine("Message: " + Encoding.ASCII.GetString(packet, index, count));
                        break;
                    case MessageFields.ProductCode:
                        // Future: Console.WriteLine("Product Code: " + Encoding.ASCII.GetString(packet, index, count));
                        break;
                    case MessageFields.BatteryStatus:
                        //Future: Console.WriteLine("Battery Status: " + Encoding.ASCII.GetString(packet, index, count));
                        break;
                    case MessageFields.NeuronID:
                        nae.NeuronID = packet[index].ToString("x2") + ":" + packet[index + 1].ToString("x2") + ":" + packet[index + 2].ToString("x2") + ":" + packet[index + 3].ToString("x2") + ":" + packet[index + 4].ToString("x2") + ":" + packet[index + 5].ToString("x2");
                        break;
                    case MessageFields.DHCPEnabled:
                        //Future: Console.WriteLine("DHCP Enabled: " + (packet[index] == 1));
                        break;
                    case MessageFields.MessageReason:
                        //Future
                        break;
                    case MessageFields.MSEAVersion:
                        nae.MSEAVersion = Encoding.ASCII.GetString(packet, index, count);
                        break;
                }
                index += count;
            }

            Finish:
            return nae;
        }