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

            int originalDepth = context.CurrentDepth;
            int targetDepth = originalDepth + 1;
            if (context.IsStartOfDocument) 
               targetDepth = 2;

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {

                    if (context.TestExpression("imagesSet/item", targetDepth))
                    {
                        var unmarshaller = ImageUnmarshaller.Instance;
                        var item = unmarshaller.Unmarshall(context);
                        response.Images.Add(item);
                        continue;
                    }
                } 
            }

            return response;
        }
Example #2
0
 public List <Image> DescribeImages()
 {
     try
     {
         AWSModel.DescribeImagesRequest  request  = new AWSModel.DescribeImagesRequest();
         AWSModel.DescribeImagesResponse response = ec2.DescribeImages(request);
         List <Image> images = new List <Image>();
         if (response != null)
         {
             foreach (AWSModel.Image image in response.DescribeImagesResult.Image)
             {
                 if (image.ImageType.Equals("machine"))
                 {
                     Image vmImage = new Image();
                     vmImage.ImageId = image.ImageId;
                     vmImage.Name    = image.ImageLocation;
                     vmImage.State   = image.ImageState;
                     images.Add(vmImage);
                 }
             }
         }
         return(images);
     }
     catch (WebException e)
     {
         throw new MonoscapeEC2Exception(e.Message, e);
     }
     catch (AmazonEC2Exception e)
     {
         throw new MonoscapeEC2Exception(e.Message, e);
     }
 }
        public void GetAllImagesByTagName_Ok()
        {
            const string filterName = "tag-key";
            var images = new List<Image>();
            var response = new DescribeImagesResponse {Images = images};
            Ec2Mock.Setup(x => x.DescribeImages(It.Is<DescribeImagesRequest>(req => req.Filters.Single().Name == filterName
                                                                                    && req.Filters.Single().Values.Contains(Conventions.BaseImageTag))))
                   .Returns(response);

            List<Image> result = ImageService.GetImagesByTagName(Conventions.BaseImageTag);

            ReferenceEquals(images, result).Should().BeTrue();
        }
 public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) 
 {   
     DescribeImagesResponse response = new DescribeImagesResponse();
     
     int targetDepth = 2;
     while (context.Read())
     {
         if (context.IsStartElement || context.IsAttribute)
         {
             
             if (context.TestExpression("imagesSet/item", targetDepth))
             {
                 response.Images.Add(ImageUnmarshaller.GetInstance().Unmarshall(context));
                     
                 continue;
             }
         }
     }
          
                 
     return response;
 }