Example #1
0
        private ThenResponse PerformThens(IEnumerable <Then> thens, EventInfo eventInfo)
        {
            ThenResponse ThenResult = ThenResponse.Continue;

            foreach (Then then in thens)
            {
                ThenResponse result = then.Perform(eventInfo);
                ThenResult |= result;
                if (result.HasFlag(ThenResponse.BreakThens) || result.HasFlag(ThenResponse.BreakRules))
                {
                    break;
                }
            }
            return(ThenResult);
        }
Example #2
0
        private ThenResponse Run(EventInfo eventInfo)
        {
            IReadOnlyList <Rule> rules = null;

            switch (eventInfo.ProxyConnection.ProxyInfo.DataType)
            {
            case ProxyDataType.Http:
                rules = HttpRulesRegistry.GetRules();
                break;

            case ProxyDataType.Text:
                rules = TextRulesRegistry.GetRules();
                break;

            default:
                rules = new List <Rule>();
                break;
            }


            ThenResponse thenResult = ThenResponse.Continue;

            foreach (Rule rule in rules)
            {
                try
                {
                    if (rule.Enabled && MatchWhens(rule.Whens, eventInfo))
                    {
                        thenResult |= PerformThens(rule.Thens, eventInfo);
                        if (thenResult.HasFlag(ThenResponse.BreakRules))
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.LogError(e, "Failure running rule", rule.Name);
                }
            }
            return(thenResult);
        }