public IEnumerable <Rule> GetRules()
        {
            IEnumerable <Rule> rules = null;

            try
            {
                using (FileStream stream = File.OpenRead(this.filePath))
                {
                    XElement xml = XElement.Load(stream);
                    rules = CreateRules(xml);
                }
            }
            catch (Exception ex)
            {
                if (!ExceptionHelper.IsCatchableExceptionType(ex))
                {
                    throw;
                }

                RuntimeException.WrapAndLog(ex, Resource.InvalidXmlRule + ":" + this.filePath, this.logger);
            }

            return(rules);
        }
        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 Log(RuntimeException runtimeError)
 {
     //throw new NotImplementedException();
 }
        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);
            }
        }
 /// <summary>
 /// Wraps exception inside RuntimeException and sends it to logging object.
 /// </summary>
 /// <param name="exception">Exception object to be logged</param>
 /// <param name="detail">Detail information of the exception</param>
 /// <param name="logger">The logging object</param>
 public static void WrapAndLog(Exception exception, string detail, ILogger logger)
 {
     if (logger != null)
     {
         var e = new RuntimeException(exception, detail);
         e.JobId = Guid.Empty;
         e.RuleName = string.Empty;
         e.DestinationEndpoint = string.Empty;
         logger.Log(e);
     }
 }
 /// <summary>
 /// Logs runtime failures
 /// </summary>
 /// <param name="e">The runtime exception generated by interop rule engine.</param>
 private void LogRuntimeError(RuntimeException e)
 {
     if (this.logger != null)
     {
         this.logger.Log(e);
     }
 }
        public void Execute(ServiceContext context, IEnumerable<Rule> rules)
        {
            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");
            }

            bool errorOccurred = false;
            try
            {
                foreach (var rule in rules)
                {
                    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);
                    }

                    this.resultProvider.Accept(result);
                }

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

                this.resultProvider.JobCompleted(true);
            }
        }