protected override Task Handle(IDictionary<string, object> env) { var ctx = new Context(env); if ("Input".Equals(ctx.Command)) { var numbers = (ctx.GetSemanticValue("Numbers") as string) .TrimEnd(',') .Split(',') .Select(int.Parse) .ToList(); var display = numbers[0]; var buttons = numbers.Skip(1).ToList(); var result = this.Solve(display, buttons); ctx.Response = result.ToString(); } else if ("Reset".Equals(ctx.Command)) { this.Reset(); ctx.Response = "reset"; } else { throw new InvalidOperationException(); } return Task.FromResult(0); }
protected override Task Handle(IDictionary<string, object> env) { var ctx = new Context(env); if ("Input".Equals(ctx.Command)) { var column = int.Parse(ctx.GetSemanticValue("Column") as string); var letters = ctx.GetSemanticValue("Letters") as string; this.columns[column - 1] = letters; ctx.Response = this.Solve(); } else if ("Reset".Equals(ctx.Command)) { this.Reset(); ctx.Response = "reset"; } else { throw new InvalidOperationException(); } return Task.FromResult(0); }
public override Task Invoke(IDictionary<string, object> env) { var ctx = new Context(env); if (this.minConfidence <= ctx.Confidence) { return this.next.Invoke(env); } else { return Task.FromResult(0); } }
protected override Task Handle(IDictionary<string, object> env) { var ctx = new Context(env); var colors = (ctx.GetSemanticValue("Colors") as string) .TrimEnd() .Split(' ') .Select(s => Enum.Parse(typeof(Color), s, true)) .Cast<Color>() .ToList(); var wire = this.solver.Invoke(this.settings, colors); ctx.Response = this.responses[wire - 1]; return Task.FromResult(0); }
protected override Task Handle(IDictionary<string, object> env) { var ctx = new Context(env); if ("Reset".Equals(ctx.Command)) { this.settings.SerialLastDigit = Parity.NotSet; this.settings.SerialVowel = null; this.settings.BatteryCount = null; this.settings.IndicatorCAR = null; this.settings.IndicatorFRK = null; this.settings.StrikeCount = 0; this.memoryHandler.Reset(); this.sequencesHandler.Reset(); this.passwordsHandler.Reset(); ctx.Response = "reset"; } else if ("SerialParity".Equals(ctx.Command)) { var value = ctx.GetSemanticValue("Value") as string; if ("even".Equals(value)) { this.settings.SerialLastDigit = Parity.Even; } else if ("odd".Equals(value)) { this.settings.SerialLastDigit = Parity.Odd; } else { throw new InvalidOperationException(); } ctx.Response = value; } else if ("SerialVowel".Equals(ctx.Command)) { var value = ctx.GetSemanticValue("Value") as string; if ("yes".Equals(value)) { this.settings.SerialVowel = true; } else if ("no".Equals(value)) { this.settings.SerialVowel = false; } ctx.Response = "vowel " + value; } else if ("BatteryCount".Equals(ctx.Command)) { var count = int.Parse(ctx.GetSemanticValue("Count") as string); this.settings.BatteryCount = count; ctx.Response = count.ToString(); } else if ("Indicator".Equals(ctx.Command)) { var label = ctx.GetSemanticValue("Label") as string; var value = ctx.GetSemanticValue("Value") as string; if ("CAR".Equals(label)) { if ("yes".Equals(value)) { this.settings.IndicatorCAR = true; } else if ("no".Equals(value)) { this.settings.IndicatorCAR = false; } ctx.Response = "car " + value; } else if ("FRK".Equals(label)) { if ("yes".Equals(value)) { this.settings.IndicatorFRK = true; } else if ("no".Equals(value)) { this.settings.IndicatorFRK = false; } ctx.Response = "freak " + value; } else { throw new InvalidOperationException(); } } else if ("StrikeCount".Equals(ctx.Command)) { var count = int.Parse(ctx.GetSemanticValue("Count") as string); this.settings.StrikeCount = count; ctx.Response = count.ToString(); } else { throw new InvalidOperationException(); } return Task.FromResult(0); }
protected override Task Handle(IDictionary<string, object> env) { var ctx = new Context(env); var color = (Color)Enum.Parse(typeof(Color), ctx.GetSemanticValue("Color") as string, true); if ("Button".Equals(ctx.Command)) { var label = (ButtonLabel)Enum.Parse(typeof(ButtonLabel), ctx.GetSemanticValue("Label") as string, true); var action = this.solver.Invoke(this.settings, color, label); if (action == ButtonAction.Hold) { ctx.Response = "hold"; } else if (action == ButtonAction.Tap) { ctx.Response = "tap"; } else { throw new InvalidOperationException(); } } else if ("Strip".Equals(ctx.Command)) { ctx.Response = this.SolveStrip(color); } return Task.FromResult(0); }
protected override Task Handle(IDictionary<string, object> env) { var ctx = new Context(env); if ("Simon".Equals(ctx.Command)) { var colors = (ctx.GetSemanticValue("Colors") as string) .TrimEnd(',') .Split(',') .Select(s => Enum.Parse(typeof(Color), s, true)) .Cast<Color>() .ToList(); ctx.Response = colors .Select(c => this.Solve(c).ToString()) .Aggregate("", (acc, s) => string.Format("{0} {1}", acc, s)); } else { throw new InvalidOperationException(); } return Task.FromResult(0); }