Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="returned">Return values</param>
 public ExecuteServiceResponse(RemoteServiceReturn returned)
 {
     this.Returned = returned;
 }
Exemple #2
0
        /// <summary>
        /// Create the response from a message and HL7 response content
        /// </summary>
        /// <param name="request">Request made</param>
        /// <param name="message">HL7 response content</param>
        /// <returns></returns>
        public Response FromMessage(Request request, string message)
        {
            if (!IsOkMessage(message))
            {
                return(CreateFailureException(message));
            }

            var rows = ExtractRows(message);

            if (request is RegisterTeamRequest)
            {
                var fullRequest = (RegisterTeamRequest)request;
                var response    = new RegisterTeamResponse();

                var teamId     = rows[0][2];
                var expiration = rows[0][3];

                try
                {
                    response.TeamId     = int.Parse(teamId);
                    response.Expiration = expiration;

                    return(response);
                }
                catch (Exception)
                {
                    throw new FormatException("Failure to parse teamId, must be integer");
                }
            }
            else if (request is UnRegisterTeamRequest)
            {
                var fullRequest = (UnRegisterTeamRequest)request;
                var response    = new UnRegisterTeamResponse();
                return(response);
            }
            else if (request is QueryTeamRequest)
            {
                var fullRequest = (QueryTeamRequest)request;
                var response    = new QueryTeamResponse();

                return(response);
            }
            else if (request is PublishServiceRequest)
            {
                var fullRequest = (PublishServiceRequest)request;
                var response    = new PublishServiceResponse();
                return(response);
            }
            else if (request is QueryServiceRequest)
            {
                var fullRequest = (QueryServiceRequest)request;

                var numSegments  = int.Parse(rows[0][4]);
                var serviceName  = rows[1][2];
                var numArgs      = int.Parse(rows[1][4]);
                var numResponses = int.Parse(rows[1][5]);
                var description  = rows[1][6];

                var mchIndex = 2 + numArgs + numResponses;
                var ip       = rows[mchIndex][1];
                var port     = int.Parse(rows[mchIndex][2]);
                var service  = new RemoteService(IPAddress.Parse(ip), port, serviceName, fullRequest.TagName, 1, description);

                var response = new QueryServiceResponse(service);
                // Read the args
                for (int i = 0; i < numArgs; i++)
                {
                    var arg = 2 + i;
                    var row = rows[arg];

                    var pos       = int.Parse(row[1]);
                    var argName   = row[2];
                    var dataType  = ServiceArgument.TypeFromString(row[3]);
                    var mandatory = false;

                    try
                    {
                        // Optional
                        mandatory = row[4].Equals("mandatory", StringComparison.CurrentCultureIgnoreCase);
                    }
                    catch (Exception)
                    {
                        // Ignore...
                    }

                    service.Args.Add(new ServiceArgument(pos, argName, dataType, mandatory));
                }

                // Read the responses
                for (int i = 0; i < numResponses; i++)
                {
                    var resp = 2 + i + numArgs;
                    var row  = rows[resp];

                    var pos      = int.Parse(row[1]);
                    var respName = row[2];
                    var dataType = ServiceArgument.TypeFromString(row[3]);

                    service.Returns.Add(new ServiceReturn(pos, respName, dataType));
                }

                return(response);
            }
            else if (request is ExecuteServiceRequest)
            {
                var fullRequest = (ExecuteServiceRequest)request;

                var numSegments  = int.Parse(rows[0][4]);
                var name         = rows[0][2];
                var numResponses = int.Parse(rows[0][4]);

                var returnedCall = new RemoteServiceReturn(name);

                for (int resp = 0; resp < numResponses; resp++)
                {
                    var row = rows[1 + resp];
                    Debug.Assert(row[0] == "RSP");

                    var pos      = int.Parse(row[1]);
                    var argName  = row[2];
                    var dataType = row[3];
                    var value    = row[4];

                    var serviceReturn = new ServiceReturn(pos, argName, ServiceArgument.TypeFromString(dataType), value);
                    returnedCall.Returns.Add(serviceReturn);
                }

                var response = new ExecuteServiceResponse(returnedCall);
                return(response);
            }
            else
            {
                throw new KeyNotFoundException("Failure to create response for request of type: " + request.GetType().Name);
            }
        }