public void Execute(ServiceContext context, IEnumerable <Rule> rules, int rulecount, TestComplete ruleresult)
        {
            bool errorOccurred = false;

            if (context == null)
            {
                this.resultProvider.JobCompleted(true);
                var e = new RuntimeException(new ArgumentNullException("context"), Resource.NullServiceContext);
                this.LogRuntimeError(e);
                return;
            }

            if (rules == null)
            {
                throw new ArgumentNullException("rules");
            }

            int count = 0;

            try
            {
                foreach (var rule in rules)
                {
                    count++;
                    TestResult result;
                    try
                    {
                        result = RuleExecuter.ExecuteRule(context, rule);
                    }
                    catch (RuntimeException e)
                    {
                        errorOccurred = true;
                        result        = TestResult.CreateAbortedResult(rule, context.JobId);

                        e.JobId               = context.JobId;
                        e.RuleName            = rule.Name;
                        e.DestinationEndpoint = context.Destination.AbsolutePath;
                        this.LogRuntimeError(e);
                    }
                    catch (Exception ex)
                    {
                        if (!ExceptionHelper.IsCatchableExceptionType(ex))
                        {
                            throw;
                        }

                        errorOccurred = true;
                        result        = TestResult.CreateAbortedResult(rule, context.JobId);

                        var e = new RuntimeException(ex, null);
                        e.JobId               = context.JobId;
                        e.RuleName            = rule.Name;
                        e.DestinationEndpoint = context.Destination.AbsolutePath;
                        this.LogRuntimeError(e);
                    }
                    if (ruleresult != null)
                    {
                        ruleresult(result, rulecount, ref count);
                    }
                    this.resultProvider.Accept(result);
                }

                //this.resultProvider.JobCompleted(errorOccurred);
            }
            catch (Exception ex)
            {
                if (!ExceptionHelper.IsCatchableExceptionType(ex))
                {
                    throw;
                }

                this.resultProvider.JobCompleted(true);
            }
        }
        public void Execute(ServiceContext context, IEnumerable <Rule> rules, int rulecount, TestComplete ruleresult)
        {
            if (context == null)
            {
                this.resultProvider.JobCompleted(true);
                var e = new RuntimeException(new ArgumentNullException("context"), Resource.NullServiceContext);
                this.LogRuntimeError(e);
                return;
            }

            if (rules == null)
            {
                throw new ArgumentNullException("rules");
            }

            int count = 0;

            try
            {
                foreach (var rule in rules)
                {
                    count++;
                    TestResult result;
                    try
                    {
                        result = RuleExecuter.ExecuteRule(context, rule);
                    }
                    catch (RuntimeException e)
                    {
                        result = TestResult.CreateAbortedResult(rule, context.JobId);

                        e.JobId               = context.JobId;
                        e.RuleName            = rule.Name;
                        e.DestinationEndpoint = context.Destination.AbsolutePath;
                        this.LogRuntimeError(e);
                    }
                    catch (Exception ex)
                    {
                        if (!ExceptionHelper.IsCatchableExceptionType(ex))
                        {
                            throw;
                        }


                        result = TestResult.CreateAbortedResult(rule, context.JobId);

                        if (result.Details == null)
                        {
                            result.Details = new List <ExtensionRuleResultDetail>();
                        }
                        ExtensionRuleResultDetail detail = new ExtensionRuleResultDetail(result.RuleName, string.Empty, HttpMethod.Get, "Exception:  " + ex.Message);
                        result.Details.Add(detail);
                        detail = new ExtensionRuleResultDetail(result.RuleName, string.Empty, HttpMethod.Get, "StackTrace:  " + ex.StackTrace);
                        result.Details.Add(detail);



                        var e = new RuntimeException(ex, null);
                        e.JobId               = context.JobId;
                        e.RuleName            = rule.Name;
                        e.DestinationEndpoint = context.Destination.AbsolutePath;

                        this.LogRuntimeError(e);
                        bool tryagain = false;
                        if (tryagain)
                        {
                            result = RuleExecuter.ExecuteRule(context, rule);
                        }
                    }
                    if (ruleresult != null)
                    {
                        ruleresult(result, rulecount, ref count);
                    }
                    this.resultProvider.Accept(result);
                }

                //this.resultProvider.JobCompleted(errorOccurred);
            }
            catch (Exception ex)
            {
                if (!ExceptionHelper.IsCatchableExceptionType(ex))
                {
                    throw;
                }

                this.resultProvider.JobCompleted(true);
            }
        }