This is the response object from the ListMetrics operation.
Inheritance: Amazon.Runtime.AmazonWebServiceResponse
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListMetricsResponse response = new ListMetricsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;
            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {                    
                    if(context.TestExpression("ListMetricsResult", 2))
                    {
                        UnmarshallResult(context, response);                        
                        continue;
                    }
                    
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return response;
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListMetricsResponse response)
        {
            
            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("Metrics/member", targetDepth))
                    {
                        var unmarshaller = MetricUnmarshaller.Instance;
                        var item = unmarshaller.Unmarshall(context);
                        response.Metrics.Add(item);
                        continue;
                    }
                    if (context.TestExpression("NextToken", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.NextToken = unmarshaller.Unmarshall(context);
                        continue;
                    }
                } 
           }

            return;
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListMetricsResponse response = new ListMetricsResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if(context.TestExpression("ListMetricsResult", 2))
                    {
                        response.ListMetricsResult = ListMetricsResultUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }

            return response;
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context,ListMetricsResponse response)
        {
            
            int originalDepth = context.CurrentDepth;
            int targetDepth = originalDepth + 1;
            
            if (context.IsStartOfDocument) 
               targetDepth += 2;
            
            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Metrics/member", targetDepth))
                    {
                        response.Metrics.Add(MetricUnmarshaller.GetInstance().Unmarshall(context));
                            
                        continue;
                    }
                    if (context.TestExpression("NextToken", targetDepth))
                    {
                        response.NextToken = StringUnmarshaller.GetInstance().Unmarshall(context);
                            
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }
                            


            return;
        }
Beispiel #5
0
    public static void CWListMetrics()
    {
      #region CWListMetrics
      var client = new AmazonCloudWatchClient();

      var filter = new DimensionFilter
      {
        Name = "InstanceType",
        Value = "t1.micro"
      };

      var request = new ListMetricsRequest
      {
        Dimensions = new List<DimensionFilter>() { filter },
        MetricName = "CPUUtilization",
        Namespace = "AWS/EC2"
      };

      var response = new ListMetricsResponse();

      do
      {
        response = client.ListMetrics(request);

        if (response.Metrics.Count > 0)
        {
          foreach (var metric in response.Metrics)
          {
            Console.WriteLine(metric.MetricName +
              " (" + metric.Namespace + ")");

            foreach (var dimension in metric.Dimensions)
            {
              Console.WriteLine("  " + dimension.Name + ": "
                + dimension.Value);
            }
          }
        }
        else
        {
          Console.WriteLine("No metrics found.");
        }

        request.NextToken = response.NextToken;

      } while (!string.IsNullOrEmpty(response.NextToken));
      #endregion

      Console.ReadLine();
    }