static string CreatePoem() { Dictionary <string, Rule> rules = RulesFactory.GetDictionaryOfRules("rules.txt"); RulesInterpreter intepreter = new RulesInterpreter(rules); string poem = intepreter.GetTextForRule("POEM"); return(poem); }
public void Setup() { var clock = new Mock <IClock>(); clock.SetupGet(c => c.UtcNow).Returns(DateTime.UtcNow); _rulesInterpreter = new RulesInterpreter(clock.Object); _context = new Mock <HttpContextBase>(); SetRewriteBase(""); }
public void OnActionExecuting(ActionExecutingContext filterContext) { var settings = _rewriteRulesService.GetSettings(); if (!settings.IsEnabled || string.IsNullOrWhiteSpace(settings.Rules)) { return; } try { var interpretter = new RulesInterpreter(_clock); filterContext.Result = interpretter.Interpret(filterContext.HttpContext, settings.Rules) ?? filterContext.Result; } catch (RuleEvaluationException e) { Logger.Error("Rewrite rule evaluation failed for url {0} on rule {1} with message: ", e.Url, e.Rule, e.Message); } }
static void Main(string[] args) { string InputFileLocation = @"C:\Users\matta\Documents\AdventofCode2020\Inputs\"; string InputFileName = "Day19B.txt"; string fileAsString = File.ReadAllText(Path.Combine(InputFileLocation, InputFileName)).Replace("\r", ""); string[] initialSplit = { "\n\n" }; string[] splitFile = fileAsString.Split(initialSplit, StringSplitOptions.RemoveEmptyEntries); //0 is rules, 1 is candidate strings string[] rules = splitFile[0].Split('\n', StringSplitOptions.RemoveEmptyEntries); RulesInterpreter rulesInterpreter = new RulesInterpreter(rules); string[] messages = splitFile[1].Split('\n', StringSplitOptions.RemoveEmptyEntries); int runningTotal = 0; foreach (string message in messages) { if (rulesInterpreter.CheckMessage(message)) { runningTotal++; } } Console.WriteLine(runningTotal.ToString()); }