Returns information about the GetMetricStatisticsResult response and response metadata.
Inheritance: Amazon.Runtime.AmazonWebServiceResponse
        private static void UnmarshallResult(XmlUnmarshallerContext context, GetMetricStatisticsResponse 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("Datapoints/member", targetDepth))
                    {
                        var unmarshaller = DatapointUnmarshaller.Instance;
                        var item = unmarshaller.Unmarshall(context);
                        response.Datapoints.Add(item);
                        continue;
                    }
                    if (context.TestExpression("Label", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.Label = unmarshaller.Unmarshall(context);
                        continue;
                    }
                } 
           }

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

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

            return response;
        }
        private long AverageValue(GetMetricStatisticsResponse result)
        {
            var lastStat = result.Datapoints.OrderBy(dp => dp.Timestamp).FirstOrDefault();

            if (lastStat == null)
                return 0;

            return Convert.ToInt64(lastStat.Average);
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            GetMetricStatisticsResponse response = new GetMetricStatisticsResponse();

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

            return response;
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context,GetMetricStatisticsResponse 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("Label", targetDepth))
                    {
                        response.Label = StringUnmarshaller.GetInstance().Unmarshall(context);
                            
                        continue;
                    }
                    if (context.TestExpression("Datapoints/member", targetDepth))
                    {
                        response.Datapoints.Add(DatapointUnmarshaller.GetInstance().Unmarshall(context));
                            
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }
                            


            return;
        }
        private long ConsumedValue(GetMetricStatisticsResponse result)
        {
            var lastStat = result.Datapoints.OrderBy(dp => dp.Timestamp).FirstOrDefault();

            if (lastStat == null)
                return 0;

            // Based on AWS documentation, Average ConsumedCapacity need to be computed based on the Sum metric over the 1 min period
            // For more information, visit http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/dynamo-metricscollected.html
            return Convert.ToInt64(lastStat.Sum / 60);
        }