示例#1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateHostResponse response = new CreateHostResponse();

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("HostArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.HostArn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Tags", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Tag, TagUnmarshaller>(TagUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
示例#2
0
        public HttpResponseMessage CreateHost(CreateHostRequest request)
        {
            CreateHostResponse responseData = null;

            string newAPIKey = null;

            try
            {
                //Validate input
                if (request == null ||
                    string.IsNullOrEmpty(request.Name))
                {
                    return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.InvalidParam, ResponseMessages.InvalidParam)));
                }

                //Perform transaction
                HostServices hostService = new HostServices();
                hostService.CreateHost(request, out newAPIKey);

                responseData        = new CreateHostResponse();
                responseData.APIKey = newAPIKey;

                //Send response
                return(Request.CreateResponse(new GenericResponse(responseData, ResponseCodes.Success, ResponseMessages.Success)));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                return(Request.CreateResponse(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)));
            }
        }