コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }