Esempio n. 1
0
        private void TbCommand_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Enter))
            {
                byte[] resvReponse = null;

                if (tbService.Text.Equals("TCP"))
                {
                    TcpConnect tcpCon = new TcpConnect();
                    //resvReponse = tcpCon.SendRequest_Message(tbIp.Text, tbPort.Text, tbCommand.Text);
                }
                else
                {
                    udpClient = new Udp_Client();
                    udpClient.StartAsClient(tbIp.Text, tbPort.Text);
                    resvReponse = udpClient.SendRequest(Encoding.UTF8.GetBytes(tbCommand.Text));
                }

                if (resvReponse != null)
                {
                    string sResponse = Encoding.UTF8.GetString(resvReponse);

                    if (sResponse.Length < 20)
                    {
                        if (sResponse.Equals("SUCCESS"))
                        {
                            //tbResponse.Text = sResponse;

                            if (tbService.Text.Equals("TCP"))
                            {
                                TcpConnect tcpCon = new TcpConnect();
                                //resvReponse = tcpCon.SendRequest_Message(tbIp.Text, tbPort.Text, "view machinelist");
                            }
                            else
                            {
                                Udp_Client udpClient = new Udp_Client();
                                resvReponse = udpClient.SendRequest(Encoding.UTF8.GetBytes("view machinelist"));
                            }
                        }
                    }

                    /* MachineList Set GRID*/
                    if (resvReponse.Length > 20)
                    {
                        DataTable dataTable = Fomatter.xmlDataToDataTable(Encoding.UTF8.GetString(resvReponse));
                        if (dataTable.Rows.Count > 0)
                        {
                            dgvMachinelist.DataSource = null;
                        }
                        dgvMachinelist.DataSource = dataTable;
                        //SetDataGeidView(dataTable);
                    }

                    tbCommand.Text = "";
                }
            }
        }
Esempio n. 2
0
        static string CmdExcute(string sCommand)
        {
            string[] splitCommand = sCommand.ToUpper().Split(new String[] { " " }, StringSplitOptions.None);

            switch (splitCommand[0])
            {
            case "EXIT":
                return("FAIL");

            case "SET":
                if (splitCommand[1].Equals("MACHINE"))
                {
                    String setMachineName = splitCommand[2];
                    if (setMachineName.Length > 0)
                    {
                        Machine newMachine = new Machine();
                        newMachine.SetMachine(setMachineName);

                        machineList.Add(newMachine);

                        return("SUCCESS");
                    }
                }
                else if (splitCommand[1].Equals("MACHINESTATE"))
                {
                    foreach (Machine machine in machineList)
                    {
                        if (machine.MachineName.Equals(splitCommand[2]))
                        {
                            machine.SetMachineState(splitCommand[3]);
                            return(machine.View());
                        }
                    }
                }
                else
                {
                    goto default;
                }

                break;

            case "VIEW":
                if (splitCommand[1].Equals("MACHINE"))
                {
                    String findMachineName = splitCommand[2];
                    foreach (Machine machine in machineList)
                    {
                        if (machine.MachineName.Equals(findMachineName))
                        {
                            logger.Info(machine.ViewMachine(machine.MachineName));
                            return("SUCCESS");
                        }
                    }
                }
                else if (splitCommand[1].Equals("MACHINELIST"))
                {
                    //logger.Info(Fomatter.XmlWriter(machineList));
                    //return "SUCCESS";
                    return(Fomatter.XmlWriter(machineList));
                }
                else
                {
                    goto default;
                }
                break;

            case "SAVE":
                if (splitCommand[1].Equals("MACHINELIST"))
                {
                    String sFileName = @".\MachineList.xml";
                    if (sFileName.Length > 0)
                    {
                        logger.Info("Start Save MachineList ... ");

                        XmlDocument doc = new XmlDocument();
                        doc.Load(new System.IO.StringReader(Fomatter.XmlWriter(machineList)));
                        doc.Save(sFileName);

                        logger.Info("End Save MachineList ");
                    }
                }
                else
                {
                    goto default;
                }
                break;

            case "LOAD":
                if (splitCommand[1].Equals("MACHINELIST"))
                {
                    String sFileName = @".\MachineList.xml";
                    if (sFileName.Length > 0)
                    {
                        logger.Info("Start Loading MachineList ... ");

                        XmlDocument doc = new XmlDocument();
                        doc.Load(sFileName);
                        machineList = (List <Machine>)Fomatter.XmlDeserialize(doc.OuterXml);

                        logger.Info("End Loading MachineList ");
                    }
                }
                else
                {
                    goto default;
                }
                break;


            case "START":     /* TCP | UDP 통신 Start  */
                if (splitCommand[1].Equals("TCP"))
                {
                    tcpConnect = new TcpConnect();
                    tcpConnect.StartListening(splitCommand[2]);
                    tcpConnect.OnReceiveMessage += OnReceiveMeaasge;
                    return("SUCCESS");
                }
                else if (splitCommand[1].Equals("UDP"))
                {
                    udpServer = new Udp_Server();
                    udpServer.StartAsServer(splitCommand[2], splitCommand[3]);
                    udpServer.MessageEvent += OnReceiveMeaasge;
                    return("SUCCESS");
                }
                else if (splitCommand[1].Equals("AUTOSAVE"))
                {
                    int interval = 60;
                    if (splitCommand.Length > 2)
                    {
                        //if (int.TryParse(splitCommand[2], out interval)) SET_AUTOSAVE(interval);
                    }
                }
                else if (splitCommand[1].Equals("MULTICAST"))
                {
                    if (udpServer != null)
                    {
                        udpServer.JoinMulticastGroup();
                        return("SUCCESS");
                    }
                }
                else if (splitCommand[1].Equals("AUTOSEND"))
                {
                    int interval;
                    if (int.TryParse(splitCommand[2], out interval))
                    {
                        AutoSendMessage(interval, splitCommand[3], splitCommand[4], splitCommand[5]);
                    }
                }
                break;

            case "STOP":     /* TCP | UDP 통신 Stop  */
                if (splitCommand[1].Equals("TCP"))
                {
                    tcpConnect.StopListening();
                    logger.Info("Dispose of a TCP Listener ...");
                    return("SUCCESS");
                }
                else if (splitCommand[1].Equals("UDP"))
                {
                    udpServer.StopAsServer();
                    logger.Info("Dispose of a UDP Listener ...");
                    return("SUCCESS");
                }
                break;

            case "SEND":
                Udp_Client client = new Udp_Client();
                client.StartAsClient(splitCommand[1], splitCommand[2]);
                StringBuilder sb = new StringBuilder();
                for (int i = 3; i < splitCommand.Length; i++)
                {
                    sb.Append(splitCommand[i] + " ");
                }
                client.SendData(Encoding.UTF8.GetBytes(sb.ToString().Trim()));
                break;

            case "SENDR":
                if (splitCommand[1].Equals("UDP"))
                {
                    if (udpClient == null)
                    {
                        udpClient = new Udp_Client();
                        udpClient.StartAsClient(splitCommand[2], splitCommand[3]);
                    }

                    StringBuilder sb2 = new StringBuilder();
                    for (int i = 4; i < splitCommand.Length; i++)
                    {
                        sb2.Append(splitCommand[i] + " ");
                    }
                    byte[] bResponse = udpClient.SendRequest(Encoding.UTF8.GetBytes(sb2.ToString()));

                    return(Encoding.UTF8.GetString(bResponse));
                }
                break;

            default:
                logger.Info("다시 입력바랍니다.");
                break;
            }

            return(null);
        }