コード例 #1
0
        private void cmdDisconnect_Click(object sender, EventArgs e)//If user wants to disconnect their team
        {
            byte[] buffer     = new byte[1024];
            string teamName   = txtTeamName.Text;
            string teamID     = txtTeamID.Text;
            string message    = MessageBuilder.unRegisterTeam(teamName, teamID);//Disconnecting unregisters team
            string ipString   = txtRegistryIP.Text;
            string portString = txtRegistryPort.Text;

            string[]       response = null;
            bool           isOK     = false;
            frmConnectTeam frm      = new frmConnectTeam();//Begin building form for reconnection
            IPAddress      ip       = IPAddress.Parse(ipString);
            int            port     = int.Parse(portString);
            Socket         regSock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);//Create socket for the registry

            //Try to unregister team
            try
            {
                regSock.Connect(ip, port);//Connect to registry
                Logging.LogLine("Calling SOA-Registry with message :");
                Logging.LogLine("\t" + message);
                TCPHelper.sendMessage(message, regSock);                        //Send the disconnect messge
                string respMessage = TCPHelper.receiveMessage(buffer, regSock); //Wait for response
                Logging.LogLine("\tResponse from SOA-Registry:");
                Logging.LogLine("\t\t" + respMessage);
                Logging.LogLine("---");

                response = MessageParser.parseMessage(respMessage);//Parse response by |
                //Was the response OK?
                isOK = MessageParser.checkOK(response[1]);
                if (isOK == true)
                {
                    //Close current form and open new form
                    this.Hide();
                    frm.Show();
                    regSock.Disconnect(true);
                }
                else if (isOK == false)
                {
                    MessageBox.Show("ERROR CODE: " + response[2] + "\n" + response[3]);
                    regSock.Disconnect(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void cmdDisconnectTeam_Click(object sender, EventArgs e)
        {
            byte[] buffer     = new byte[1024];
            string teamName   = txtTeamName.Text;
            string teamID     = txtTeamID.Text;
            string message    = MessageBuilder.unRegisterTeam(teamName, teamID);
            string ipString   = txtRegIP.Text;
            string portString = txtRegPort.Text;

            string[]       response = null;
            bool           isOK     = false;
            frmConnectTeam frm      = new frmConnectTeam();
            IPAddress      ip       = IPAddress.Parse(ipString);
            int            port     = int.Parse(portString);
            Socket         regSock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            try
            {
                regSock.Connect(ip, port);
                Logging.LogLine("Calling SOA-Registry with message :");
                Logging.LogLine("\t" + message);
                TCPHelper.sendMessage(message, regSock);
                string respMessage = TCPHelper.receiveMessage(buffer, regSock);
                Logging.LogLine("\tResponse from SOA-Registry:");
                Logging.LogLine("\t\t" + respMessage);
                Logging.LogLine("---");
                response = MessageParser.parseMessage(respMessage);
                isOK     = MessageParser.checkOK(response[1]);
                if (isOK == true)
                {
                    frm.Show();
                    this.Hide();
                    regSock.Disconnect(true);
                }
                else if (isOK == false)
                {
                    MessageBox.Show("ERROR CODE: " + response[2] + "\n" + response[3]);
                    regSock.Disconnect(true);
                }
            }
            catch
            {
            }
        }
コード例 #3
0
        private void cmdSelect_Click(object sender, EventArgs e)
        {
            string         ipAddressString = txtHostName.Text;
            string         portString      = txtPort.Text;
            string         teamName        = txtTeamName.Text;
            string         teamMessage     = "";
            IPAddress      ip       = null;
            bool           valid    = true;
            int            port     = 0;
            MessageBuilder msgBuild = new MessageBuilder();
            TcpListener    listener = new TcpListener(Dns.GetHostEntry(Dns.GetHostName()).AddressList[1], 3000);
            TcpClient      registry = null;

            try
            {
                port = int.Parse(portString);
                ip   = IPAddress.Parse(ipAddressString);
            }
            catch (Exception ex)
            {
                valid = false;
                MessageBox.Show(ex.Message);
            }
            if (valid == true)
            {
                try
                {
                    teamMessage = msgBuild.registerTeam(teamName);
                    listener.Start();
                    listener.BeginAcceptTcpClient(TCPHelper.OnClientAccepted, listener);
                    registry = TCPHelper.connectEndPoint(ip, port);
                    TCPHelper.sendMessage(registry, teamMessage);
                }
                catch (Exception ex)
                {
                }
            }
        }
コード例 #4
0
        private void cmdSelect_Click(object sender, EventArgs e)//Button for user to confirm selection of a service
        {
            byte[] buffer          = new byte[1024];
            string serviceSelected = cboServiceSelect.Text;
            string teamName        = txtTeamName.Text;
            string teamID          = txtTeamID.Text;
            string ipString        = txtRegIP.Text;
            string portString      = txtRegPort.Text;
            string expiration      = txtExpiration.Text;
            string mchInfo         = "";

            frmConnectTeam     frmConnect = new frmConnectTeam();
            frmSelectedService frmService = new frmSelectedService();

            string[] response = null;
            string[] args     = null;
            string[] rsps     = null;
            string   srvInfo  = "";

            string[] srvInfoParsed      = null;
            string[] mchInfoParsed      = null;
            bool     isOK               = false;
            int      regPort            = int.Parse(portString);
            int      numArgs            = 0;
            int      servicePort        = 0;
            int      numResponses       = 0;
            string   serviceIPString    = "";
            string   servicePortString  = "";
            string   serviceTeamName    = "";
            string   serviceName        = "";
            string   numArgsString      = "";
            string   serviceDescription = "";
            string   numResponsesString = "";
            //Build messages and connect sockets for communication
            string    tag       = MessageParser.parseTag(serviceSelected);
            string    message   = MessageBuilder.queryService(teamName, teamID, tag);//Build message to find a service
            IPAddress regIP     = IPAddress.Parse(ipString);
            IPAddress serviceIP = null;
            //Declare sockets for registry and service
            Socket regSock     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            Socket serviceSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            try
            {
                regSock.Connect(regIP, regPort);//Connect to the registry socket
                Logging.LogLine("Calling SOA-Registry with message :");
                Logging.LogLine("\t" + message);
                TCPHelper.sendMessage(message, regSock);                        //Send query service HL7 /message
                string respMessage = TCPHelper.receiveMessage(buffer, regSock); //Wait for response
                Logging.LogLine("\tResponse from SOA-Registry:");
                Logging.LogLine("\t\t" + respMessage);
                Logging.LogLine("---");
                response = MessageParser.parseMessage(respMessage); //parse response into deliminated parts
                isOK     = MessageParser.checkOK(response[1]);      //Check if OK or not
                if (isOK == true)
                {
                    args          = MessageParser.argsParser(MessageParser.parseMessageByEOS(respMessage));        //Get an array of arguments
                    rsps          = MessageParser.respParser(MessageParser.parseMessageByEOS(respMessage));        //get an array of responses
                    srvInfo       = MessageParser.parseSegment(SRV, MessageParser.parseMessageByEOS(respMessage)); //get the SRV segment...
                    srvInfoParsed = MessageParser.parseMessage(srvInfo);                                           //...Parse the SRV segment by | character
                    mchInfo       = MessageParser.parseSegment(MCH, MessageParser.parseMessageByEOS(respMessage)); //Get the MCH Segment...
                    mchInfoParsed = MessageParser.parseMessage(mchInfo);                                           //...parse the mch segment by | character
                    //Service connection info
                    serviceIPString   = mchInfoParsed[1];
                    servicePortString = mchInfoParsed[2];
                    serviceIP         = IPAddress.Parse(serviceIPString);
                    servicePort       = int.Parse(servicePortString);
                    serviceTeamName   = srvInfoParsed[1];
                    serviceName       = srvInfoParsed[2];
                    //Parse arguments and responses
                    numArgsString      = srvInfoParsed[4];
                    numArgs            = int.Parse(numArgsString);
                    numResponsesString = srvInfoParsed[5];
                    numResponses       = int.Parse(numResponsesString);
                    serviceDescription = srvInfoParsed[6];
                    //Build the form programmatically
                    FormBuilder.buildSelectedService(args, rsps, serviceName, serviceTeamName,
                                                     serviceDescription, serviceIPString, servicePortString,
                                                     teamName, teamID, expiration, ipString, portString, frmService);
                    this.Hide();
                }
                else if (isOK == false)
                {
                    MessageBox.Show("ERROR CODE: " + response[2] + "\n" + response[3]);
                    if (response[3].Contains("Team Licence Expired"))
                    {
                        frmConnect.Show();
                        this.Hide();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #5
0
        private void cmdExecute_Click(object sender, EventArgs e)
        {
            string message     = "";
            string teamName    = txtTeamName.Text;
            string teamID      = txtTeamID.Text;
            string serviceName = txtServiceName.Text;
            string argValue    = "";
            string errorString = "";
            //error checks
            bool          error   = false;
            bool          parse   = false;
            List <string> args    = new List <string>();                                                        //All arguments converted from controls to strings
            string        arg     = "";                                                                         //an indivudual argument string for storage in args
            Socket        service = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); //Socket to be used to connect to service
            int           port    = 0;                                                                          //Service Port Number

            int.TryParse(txtServicePort.Text, out port);                                                        //Parse Port from form text to int value
            IPAddress ip = IPAddress.Parse(txtServiceIP.Text);

            byte[] buffer = new byte[1024];//buffer for storing messages received from service
            //Cycle through all arguments
            bool   isOK            = false;
            string responseMessage = "";

            string[] responseMessageParsed = null;
            string[] resps      = null;
            string[] parsedResp = null;
            foreach (Argument argument in flpArgs.Controls)
            {
                argValue = argument.txtArgValue.Text;//get user input for argument

                //Check the datatype of the argument and then compare the value to the datatype specified
                if (argument.lblArgDataType.Text.ToUpper() == "CHAR")
                {
                    if (char.TryParse(argValue, out char result))
                    {
                        parse = true;
                    }
                }
                else if (argument.lblArgDataType.Text.ToUpper() == "SHORT")
                {
                    if (short.TryParse(argValue, out short result))
                    {
                        parse = true;
                    }
                }
                else if (argument.lblArgDataType.Text.ToUpper() == "INT")
                {
                    if (int.TryParse(argValue, out int result))
                    {
                        parse = true;
                    }
                }
                else if (argument.lblArgDataType.Text.ToUpper() == "LONG")
                {
                    if (long.TryParse(argValue, out long result))
                    {
                        parse = true;
                    }
                }
                else if (argument.lblArgDataType.Text.ToUpper() == "FLOAT")
                {
                    if (float.TryParse(argValue, out float result))
                    {
                        parse = true;
                    }
                }
                else if (argument.lblArgDataType.Text.ToUpper() == "DOUBLE")
                {
                    if (double.TryParse(argValue, out double result))
                    {
                        parse = true;
                    }
                }
                else if (argument.lblArgDataType.Text.ToUpper() == "STRING")
                {
                    parse = true;
                }
                //Check if argument is a mandatory field and if it is filled out respectively
                //If argument is mandatory and is not filled in, show error
                if (argument.lblArgMandatory.Text == "mandatory" && argument.txtArgValue.Text == "")
                {
                    error        = true;
                    errorString += "ERROR: Mandatory fields not filled in\n";
                }
                //If the argument is not the required datatype, show error
                if (parse == false)
                {
                    error        = true;
                    errorString += "ERROR: Value does not correspond to data type\n";
                }
                //If now error is specified (argument is filled in correctly), add argument to the list of arguments
                if (error == false)
                {
                    arg = "ARG|" + argument.lblArgPosition.Text + "|" + argument.lblArgName.Text + "|" + argument.lblArgDataType.Text + "||" + argument.txtArgValue.Text + "|";
                    args.Add(arg);
                }
                //If there is an error, show message instead of adding to the argList
                else
                {
                    MessageBox.Show(errorString);
                    errorString = "";
                    args.Clear();//Empty the arg List and start over
                }
                parse = false;
            }
            try
            {
                //If there were no errors after all args are compiled, send the message
                if (error == false)
                {
                    message = MessageBuilder.executeService(teamName, teamID, serviceName, args.Count, args); //Build the executeService
                    service.Connect(ip, port);                                                                //Connect to the service's socket
                    Logging.LogLine("Sending service request to IP " + ip + ", PORT" + port + " :");
                    Logging.LogLine("\t" + message);
                    TCPHelper.sendMessage(message, service);                     //Send the execute message to the service
                    responseMessage = TCPHelper.receiveMessage(buffer, service); //Wait for a response from the service
                    Logging.LogLine("\tResponse from Published Service: ");
                    Logging.LogLine("\t\t" + responseMessage);
                    Logging.LogLine("---");
                    //Start handling message
                    responseMessageParsed = MessageParser.parseMessage(responseMessage);
                    if (responseMessage != null)
                    {
                        isOK = MessageParser.checkOK(responseMessageParsed[1]);
                    }
                    //Check if the respnse is an OK or NOT-OK response
                    if (isOK == true)
                    {
                        resps = MessageParser.respParser(MessageParser.parseMessageByEOS(responseMessage));

                        foreach (string resp in resps)                              //iterate through each response message segment
                        {
                            parsedResp = MessageParser.parseMessage(resp);          //parse each segment by |
                            foreach (Response response in flpResps.Controls)        //iterate through each response control on the form
                            {
                                if (response.lblRespPosition.Text == parsedResp[1]) //if the response position is equal to the field in the form...
                                {
                                    response.txtRespValue.Text = parsedResp[4];     //Finally, fill the text field with the correct values
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("ERROR CODE: " + responseMessageParsed[2] + "\n" + responseMessageParsed[3]);//Display the error code and error if something went wrong
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #6
0
        private void cmdConnect_Click(object sender, EventArgs e) //Button user clicks when trying to connect to the registry
        {
            byte[]    buffer          = new byte[1024];           //data buffer for storing messages
            string    ipAddressString = txtHostName.Text;         //pull registry ip address from user input
            string    portString      = txtPort.Text;             //pull registry port from user input
            string    teamName        = txtTeamName.Text;         //pull team name from user input
            string    message         = "";                       //string for storing received messages
            string    teamMessage     = "";                       //string for storing HL7 register team message
            IPAddress ip    = null;
            bool      valid = true;
            bool      isOK  = false;
            int       port  = 0;

            Socket regSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); //Socket for the registry

            string[]            response   = null;                                                       //message received broken into parsed segments by |
            frmServiceSelection frm        = new frmServiceSelection();                                  //Next form as an object for building
            frmConnectTeam      frmConnect = new frmConnectTeam();

            try
            {
                port = int.Parse(portString);            //turn port from string to int
                ip   = IPAddress.Parse(ipAddressString); //turn ip from string to IPAddress
            }
            catch (Exception ex)
            {
                valid = false;
                MessageBox.Show(ex.Message);
            }
            if (valid == true)
            {
                try
                {
                    regSock.Connect(ip, port);                           //Connect to the registry
                    //Build register team message
                    teamMessage = MessageBuilder.registerTeam(teamName); //Build the Register Team message
                    Logging.LogLine("Calling SOA-Registry with message :");
                    Logging.LogLine("\t" + teamMessage);
                    TCPHelper.sendMessage(teamMessage, regSock);
                    message = TCPHelper.receiveMessage(buffer, regSock);
                    Logging.LogLine("\tResponse from SOA-Registry :");
                    Logging.LogLine("\t\t" + message);
                    Logging.LogLine("---");

                    response = MessageParser.parseMessage(message);
                    isOK     = MessageParser.checkOK(response[1]);
                    //Check if the respnse is an OK or NOT-OK response
                    if (isOK == true)
                    {
                        FormBuilder.buildServiceSelection(teamName, response[2], response[3], ipAddressString, portString, frm); //pull out the new form
                        this.Hide();                                                                                             //put this form away
                    }
                    else if (isOK == false)
                    {
                        MessageBox.Show("ERROR CODE: " + response[2] + "\n" + response[3]);
                        if (response[3].Contains("Team Licence Expired"))
                        {
                            frmConnect.Show();
                            this.Hide();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR:" + ex.Message);
                }
            }
        }