コード例 #1
0
        private void button13_Click(object sender, EventArgs e)
        {
            if (nics.Count > 0)
            {
                string selected = comboBox1.SelectedItem.ToString();
                string nicSelec = comboBox2.SelectedItem.ToString();

                Server selectedServ = serversL.Where(x => x.name == selected).FirstOrDefault();

                //=====ping

                bool pingable = false;
                Ping pinger   = null;
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                try
                {
                    pinger = new Ping();
                    PingReply reply = pinger.Send(selectedServ.ip);
                    pingable = reply.Status == IPStatus.Success;
                }
                catch (PingException)
                {
                    // Discard PingExceptions and return false;
                }
                finally
                {
                    if (pinger != null)
                    {
                        pinger.Dispose();
                    }
                }

                if (pingable)
                {
                    MessageBox.Show("The IP: " + selectedServ.ip + " is been used in the actual subnet", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
                else
                {
                    try
                    {
                        NetworkManagement.SetIP(nicSelec, selectedServ.ip, selectedServ.mask, selectedServ.gateway, selectedServ.dns);

                        MessageBox.Show("The IP Address has been changed", "Configured", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show("There was an error configuring the Adapter" + exp.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                    }
                }
            }
        }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            tabControl1.Appearance = TabAppearance.FlatButtons;
            tabControl1.ItemSize   = new Size(0, 1);
            tabControl1.SizeMode   = TabSizeMode.Fixed;

            treeView1.ImageIndex = 0;

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = true;
                doc.Load(AppContext.BaseDirectory + "\\config.xml");
                confList = new Dictionary <string, string>();
                XmlNodeList setings = doc.GetElementsByTagName("appSettings");
                XmlNodeList servers = doc.GetElementsByTagName("Servers");

                foreach (XmlNode node in setings[0].ChildNodes)
                {
                    if (node.NodeType == XmlNodeType.Element)
                    {
                        confList.Add(node.Attributes[0].Value, node.Attributes[1].Value);
                    }
                }

                if (confList.Count > 0)
                {
                    foreach (var item in confList)
                    {
                        switch (item.Key)
                        {
                        case "Server":
                            textBox1.Text    = item.Value;
                            textBox1.Enabled = false;
                            break;

                        case "Username":
                            textBox2.Text    = item.Value;
                            textBox2.Enabled = false;
                            break;

                        case "Password":
                            textBox3.Text    = item.Value;
                            textBox3.Enabled = false;
                            break;

                        case "ClientF":
                            textBox4.Text = item.Value;
                            break;

                        case "Fpath":
                            textBox9.Text    = item.Value;
                            textBox9.Enabled = false;
                            break;

                        case "Service":
                            if (item.Value == "0")
                            {
                                checkBox2.Checked = false;
                            }
                            else
                            {
                                checkBox2.Checked = true;
                            }
                            break;

                        case "IntH":
                            textBox5.Text = item.Value;
                            break;

                        case "IntM":
                            textBox6.Text = item.Value;
                            break;

                        case "IntS":
                            textBox7.Text = item.Value;
                            break;

                        case "Cleanup":
                            textBox10.Text = item.Value;
                            break;

                        case "Keep":
                            textBox11.Text = item.Value;
                            break;

                        case "ClName":
                            textBox13.Text = item.Value;
                            break;

                        case "Level":
                            if (item.Value == "0")
                            {
                                radioButton3.Checked = true;
                            }
                            else
                            {
                                radioButton3.Checked = false;
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    logs = "All params were loaded...";
                }
                else
                {
                    logs = "Error loading parametes";
                }

                //===Loading Servers information
                serversL = new List <Server>();

                foreach (XmlNode node in servers[0].ChildNodes)
                {
                    if (node.NodeType == XmlNodeType.Element)
                    {
                        StringReader  strReader  = null;
                        XmlSerializer serializer = null;
                        XmlTextReader xmlReader  = null;
                        Object        obj        = null;
                        try
                        {
                            strReader  = new StringReader(node.OuterXml);
                            serializer = new XmlSerializer(typeof(Server));
                            xmlReader  = new XmlTextReader(strReader);
                            obj        = serializer.Deserialize(xmlReader);
                            serversL.Add((Server)obj);
                        }
                        catch (Exception exp)
                        {
                            //Handle Exception Code
                        }
                        finally
                        {
                            if (xmlReader != null)
                            {
                                xmlReader.Close();
                            }
                            if (strReader != null)
                            {
                                strReader.Close();
                            }
                        }
                    }
                }
                updateComboServ();

                //===============================

                textBox8.Text += logs + Environment.NewLine;
                saveLog(logs);
                logs = "";

                timer3.Interval = Convert.ToInt32(confList["Cleanup"]) * 60000;
                updateTreeView();
            }
            catch (Exception ex)
            {
                saveLog(ex.ToString());
            }



            //====Loading NIC cards information

            nics = NetworkManagement.GetNICNames();

            foreach (var item in nics)
            {
                comboBox2.Items.Add(item);
            }
        }