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

            return;
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonCloudWatchConfig config = new AmazonCloudWatchConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonCloudWatchClient client = new AmazonCloudWatchClient(creds, config);

            DescribeInsightRulesResponse resp = new DescribeInsightRulesResponse();

            do
            {
                DescribeInsightRulesRequest req = new DescribeInsightRulesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.DescribeInsightRules(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.InsightRules)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DescribeInsightRulesResponse response = new DescribeInsightRulesResponse();

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

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("DescribeInsightRulesResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }