コード例 #1
0
ファイル: Stream.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Send a message
        /// </summary>
        /// <param name="request">The request information.</param>
        /// <returns>The response information.</returns>
        public Model.Message.InformationResponse SendMessage(Model.Message.InformationRequest request)
        {
            Model.Message.InformationResponse response = null;

            try
            {
                // Initialise the composition assembly collection.
                Compose();

                // Is there a collection of imported assemblies.
                if (MessageHandler.Count() < 1)
                {
                    throw new Exception("No composition assemblies have been loaded.");
                }

                // Get response.
                response = MessageHandler.First(u => u.GetResponse(request, true) != null).GetResponse(request, false);

                // If no response.
                if (response == null)
                {
                    throw new Exception("Request name is not supported.");
                }

                // Return the response data.
                return(response);
            }
            catch (Exception ex)
            {
                // Create the response data.
                response = new Model.Message.InformationResponse()
                {
                    RequestName  = request.RequestName,
                    ReturnCode   = 1,
                    ErrorMessage = ex.Message,
                    Body         = ""
                };

                // Return the response data.
                return(response);
            }
        }
コード例 #2
0
ファイル: Stream.cs プロジェクト: waffle-iron/nequeo
        /// <summary>
        /// Send and recieve string message.
        /// </summary>
        /// <param name="message">The received message</param>
        /// <returns>The send message</returns>
        public string MessageString(string message)
        {
            Serialisation.GenericSerialisation <Model.Message.InformationRequest>  serlRequest  = null;
            Serialisation.GenericSerialisation <Model.Message.InformationResponse> serlResponse = null;
            Model.Message.InformationResponse response = null;
            Model.Message.InformationRequest  request  = null;

            try
            {
                // Initialise the composition assembly collection.
                Compose();

                // Create the instance of the request and response serialised objects.
                serlRequest  = new Serialisation.GenericSerialisation <Model.Message.InformationRequest>();
                serlResponse = new Serialisation.GenericSerialisation <Model.Message.InformationResponse>();

                // Get the request data.
                request = serlRequest.Deserialise(Encoding.UTF8.GetBytes(message));

                // Is there a collection of imported assemblies.
                if (MessageHandler.Count() < 1)
                {
                    throw new Exception("No composition assemblies have been loaded.");
                }

                // Get response.
                response = MessageHandler.First(u => u.GetResponse(request, true) != null).GetResponse(request, false);

                // If no response.
                if (response == null)
                {
                    throw new Exception("Request name is not supported.");
                }

                // Return the response data.
                return(Encoding.UTF8.GetString(serlResponse.Serialise(response)));
            }
            catch (Exception ex)
            {
                // Create the response data.
                response = new Model.Message.InformationResponse()
                {
                    RequestName  = (request != null ? request.RequestName : ""),
                    ReturnCode   = 1,
                    ErrorMessage = ex.Message,
                    Body         = ""
                };

                // Return the response data.
                return(Encoding.UTF8.GetString(serlResponse.Serialise(response)));
            }
            finally
            {
                // Clean-up
                if (serlRequest != null)
                {
                    serlRequest.Dispose();
                }

                // Clean-up
                if (serlResponse != null)
                {
                    serlResponse.Dispose();
                }
            }
        }