Exemplo n.º 1
0
        public async Task <GetGatewayResponse> Handle(GetGatewayRequest message)
        {
            var restClient = new RestClient(ConfigurationManager.AppSettings["ServiceEndpoints:Gateways"]);

            var gatewayRequest = new RestRequest("gateways/{id}", Method.GET);

            gatewayRequest.AddUrlSegment("id", message.Id.ToString());

            var gatewayResponse = await restClient.ExecuteTaskAsync <Messages.Gateway>(gatewayRequest);

            if (gatewayResponse.StatusCode == HttpStatusCode.NotFound)
            {
                return(new GetGatewayResponse()
                {
                    ErrorModel = new ErrorModel(ErrorType.NotFound)
                });
            }

            var gateway = Mapper.Map <Gateway>(gatewayResponse.Data);

            var response = new GetGatewayResponse()
            {
                Data = gateway
            };

            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetGatewayResponse response = new GetGatewayResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Gateway", targetDepth))
                {
                    var unmarshaller = GatewayUnmarshaller.Instance;
                    response.Gateway = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }