/// <summary> /// This loads the items using the <see cref="CalcHistoryHelper"/>. It does not need to be a task or async becuase this /// is a simple operation (There is no file I/O). /// </summary> private void ExecuteLoadItemsCommand() { // if (IsBusy) { return; } //Set this to true so the app knows we are attempting to load a list. If the user tries to refresh the ListView while //it's already being refreshed in a previous request, there could be an error. This prevents that. IsBusy = true; Items.Clear(); var historyLogs = CalcHistoryHelper.ReadHistoryLog(); foreach (var log in historyLogs) { Items.Add(log); } IsBusy = false; }
/// <summary> /// Calculator logic handling. This processes the button input. This also calls <see cref="UpdateCalculatorExpression"/> to update /// the displayed expression. /// </summary> /// <param name="inpt">The value of the button that was pressed.</param> public string HandleCalculatorInput(string inpt) { //Handle operators //Note that ÷ and × are special HTML characters. if (OPERATORS.Contains(inpt)) { if (calculatorExpression != "" && !ExpressionEndsWithOperator(calculatorExpression) && !calculatorExpression.EndsWith(".")) { //Reset the decimal tracker doesCurrentWordHaveDot = false; calculatorExpression += inpt; } } //Handle decimal points else if (inpt == ".") { //Skip this If there is already a decimal for this number, if the calculator expression is blank, or if the //expression ends with an operator. if (!doesCurrentWordHaveDot && calculatorExpression != "" && !ExpressionEndsWithOperator(calculatorExpression)) { calculatorExpression += "."; doesCurrentWordHaveDot = true; } else { return(calculatorExpression); } } //Handle equals else if (inpt == "=") { //If the current expression ends with an operator, do not process it. if (calculatorExpression != "" && !ExpressionEndsWithOperator(calculatorExpression)) { //TODO: Save the calculation in a log. //Calculate the input string calculated = Calculate(ConvertExpression(calculatorExpression)); //Save it in the history CalcHistoryHelper.LogEntry(calculatorExpression + " = " + calculated); calculatorExpression = calculated; } } //Handle CLEAR else if (inpt == "CLEAR") { doesCurrentWordHaveDot = false; calculatorExpression = ""; } //Handle all digits else if (Regex.IsMatch(inpt, "[0-9]+")) { calculatorExpression += inpt; } //Handle miscellaneous cases for debugging. The program should never flow here, but in the event //I missed a case, I'll be able to debug it. else { Console.WriteLine("Input case unaccounted for: " + inpt + " when current expression is: " + calculatorExpression); } return(calculatorExpression); }