/// <summary> /// Configure all keys that will be allowed at <see cref="cs"/>. /// </summary> public void configureKeys() { var operators = new Dictionary <bi, char>(); foreach (var(@char, item) in bs.expressionSymbols.Keys) { operators.Add(item, @char); } operatorActions = new Dictionary <bi, BooleanOperation> { { bi.NegationOperator, new BooleanOperation(operators[bi.NegationOperator], new[] { ck.NumPad1, ck.D1 }) }, { bi.ConjunctionOperator, new BooleanOperation(operators[bi.ConjunctionOperator], new[] { ck.NumPad2, ck.D2 }) }, { bi.DisjunctionOperator, new BooleanOperation(operators[bi.DisjunctionOperator], new[] { ck.NumPad3, ck.D3 }) }, { bi.ExclusiveDisjunctionOperator, new BooleanOperation(operators[bi.ExclusiveDisjunctionOperator], new[] { ck.NumPad4, ck.D4 }) }, { bi.ConditionalOperator, new BooleanOperation(operators[bi.ConditionalOperator], new[] { ck.NumPad5, ck.D5 }) }, { bi.BiconditionalOperator, new BooleanOperation(operators[bi.BiconditionalOperator], new[] { ck.NumPad6, ck.D6 }) } }; extraActions = new Dictionary <ck, char>() { { ck.D0, ')' }, { ck.D9, '(' } }; letterKeys = new List <ck>() { ck.A, ck.B, ck.C, ck.D, ck.E, ck.F, ck.G, ck.H, ck.I, ck.J, ck.K, ck.L, ck.M, ck.N, ck.O, ck.P, ck.Q, ck.R, ck.S, ck.T, ck.U, ck.V, ck.X, ck.Y, ck.Z, ck.W }; optionKeys = operatorActions.Values.SelectMany(vars => vars.keys).ToList(); deletionKeys = new List <ck>() { ck.Backspace, ck.Delete }; parenthesisKeys = extraActions.Keys.ToList(); executionKey = ck.Enter; allowedKeys = new List <ck>(); allowedKeys.AddRange(letterKeys); allowedKeys.AddRange(optionKeys); allowedKeys.AddRange(deletionKeys); allowedKeys.AddRange(parenthesisKeys); allowedKeys.Add(executionKey); }
=> _authenticator = new Authenticator(ck, cs, at, ats, id, name, client);
_authenticator = new Authenticator(ck, cs, at, ats, client);
/// <summary> /// Handle <see cref="ck"/> based on its own dependency. /// </summary> /// <param name="key"></param> private void handleKeys(ck key) { if (allowedKeys.Contains(key)) { if (letterKeys.Contains(key)) { expression += key.ToString().ToUpperInvariant(); } if (optionKeys.Contains(key)) { expression += getOperation(key).symbol; } if (deletionKeys.Contains(key) && !string.IsNullOrEmpty(expression)) { expression = expression.Remove(expression.Length - 1); } if (parenthesisKeys.Contains(key)) { expression += extraActions[key]; } handleParenthesis(); if (executionKey == key) { if (!isEmpty()) { if (hasParenthesis) { if (isMissingParenthesis) { log.error("\r\nExpression is invalid due missing parenthesis statement!"); log.info("\n"); log.warning("Press any key to continue..."); cs.ReadKey(true); cs.Clear(); handleCalculator(); return; } } handleExecution(); return; } else { log.error("\r\nExpression is empty!"); log.info("\n"); log.warning("Press any key to continue..."); cs.ReadKey(true); } } } else { log.error($"\rConsole key '{key.ToString()}' isn't allowed!"); log.info("\n"); log.warning("Press any key to continue..."); cs.ReadKey(true); } cs.Clear(); handleCalculator(); }
/// <summary> /// Gets <see cref="BooleanOperation"/> based on <paramref name="key"/>. /// </summary> /// <param name="key"></param> /// <returns></returns> public BooleanOperation getOperation(ck key) => operatorActions.Values.First(op => op.keys.Contains(key));