Ejemplo n.º 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)
        {
            ListVirtualMachinesResponse response = new ListVirtualMachinesResponse();

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("VirtualMachines", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <VirtualMachine, VirtualMachineUnmarshaller>(VirtualMachineUnmarshaller.Instance);
                    response.VirtualMachines = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
 public override string ExecuteCommand()
 {
     try
     {
         var contentResult = base.ExecuteCommand();
         var result        = JsonConvert.DeserializeObject <ListVirtualMachinesResponseDto>(contentResult);
         ListVirtualMachinesResponse = result.ListVirtualMachinesResponse;
     }
     catch (Exception e)
     {
         LogHelper.WriteAllLog(e.Message, LogHelper.LogType.Error);
         throw;
     }
     return(string.Empty);
 }
Ejemplo n.º 3
0
        public ICommandResponse ParseResponse(WebResponse webResponse)
        {
            var response       = new ListVirtualMachinesResponse();
            var responseStream = webResponse.GetResponseStream();

            if ((responseStream != null) && (responseStream.CanRead))
            {
                var responseDocument = XDocument.Load(responseStream);
                response.Machines =
                    responseDocument.Root.Elements()
                    .Where(e => e.Name.LocalName.Equals("virtualMachine", StringComparison.InvariantCultureIgnoreCase))
                    .Select(Machine.From);
            }

            return(response);
        }