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); } }
/// <summary> /// /// </summary> /// <param name="args"></param> /// <param name="resps"></param> /// <param name="serviceName"></param> /// <param name="serviceTeamName"></param> /// <param name="serviceDescription"></param> /// <param name="serviceIP"></param> /// <param name="servicePort"></param> /// <param name="teamName"></param> /// <param name="teamID"></param> /// <param name="expiration"></param> /// <param name="regIP"></param> /// <param name="regPort"></param> /// <param name="frm"></param> public static void buildSelectedService(string[] args, string[] resps, string serviceName, string serviceTeamName, string serviceDescription, string serviceIP, string servicePort, string teamName, string teamID, string expiration, string regIP, string regPort, frmSelectedService frm) { //Fill text boxes with data from previous forms frm.txtServiceName.Text = serviceName; frm.txtServiceTeamName.Text = serviceTeamName; frm.txtDescription.Text = serviceDescription; frm.txtServiceIP.Text = serviceIP; frm.txtServicePort.Text = servicePort; frm.txtTeamName.Text = teamName; frm.txtTeamID.Text = teamID; frm.txtExpiration.Text = expiration; frm.txtRegistryIP.Text = regIP; frm.txtRegistryPort.Text = regPort; List <Argument> arguments = new List <Argument>(); //List of all arguments service needs List <Response> responses = new List <Response>(); //list of all responses service will be sending string[] parsedArg = null; //parsing an argument to its deliminited sections string[] parsedResp = null; // parsing a response to its delimited sections foreach (string arg in args) //cycle through all args { parsedArg = MessageParser.parseMessage(arg); //parse the arg into its parts arguments.Add(new Argument()); arguments.Last().lblArgPosition.Text = parsedArg[1]; arguments.Last().lblArgName.Text = parsedArg[2]; arguments.Last().lblArgDataType.Text = parsedArg[3]; arguments.Last().lblArgMandatory.Text = parsedArg[4]; arguments.Last().Name = arg; frm.flpArgs.Controls.Add(arguments.Last()); } foreach (string resp in resps) { parsedResp = MessageParser.parseMessage(resp); responses.Add(new Response()); responses.Last().lblRespPosition.Text = parsedResp[1]; responses.Last().lblRespName.Text = parsedResp[2]; responses.Last().lblDataType.Text = parsedResp[3]; arguments.Last().Name = resp; frm.flpResps.Controls.Add(responses.Last()); } frm.Show(); }