Exemplo n.º 1
0
        private void OnEqualPressCommandExecute(object p)
        {
            if (CurrentExpression.Content != "")
            {
                CurrentExpression.CalculateResult();
                ExpressionHistory.Add(CurrentExpression);
                OnPropertyChanged("CurrentExpression");

                CurrentExpression = new MathExpression();
            }
        }
        // POST api/<controller>
        public HttpResponseMessage Post([FromBody] string value)
        {
            ExpressionEvaluator eg = new ExpressionEvaluator();
            string reps            = "";

            try
            {
                reps = eg.Evaluate(value).ToString();
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Sorry this is too complex"))
                {
                    reps = "Sorry this is too complex";
                }
                else
                {
                    reps = "Error";
                }
            }

            //List<KeyValuePair<string, string>> ExpressionHistory = System.Web.HttpContext.Current.Session["ExpressionHistory"] as List<KeyValuePair<string, string>>;
            //if(ExpressionHistory == null)
            //{
            //    ExpressionHistory = new List<KeyValuePair<string, string>>();
            //}
            List <KeyValuePair <string, string> > ExpressionHistory = SessionBag.Current.ImportData;

            if (ExpressionHistory == null)
            {
                ExpressionHistory = new List <KeyValuePair <string, string> >();
            }

            KeyValuePair <string, string> exPressionValue = new KeyValuePair <string, string>(value, reps);

            // exPressionValue.a = value;
            ExpressionHistory.Add(exPressionValue);
            //System.Web.HttpContext.Current.Session["ExpressionHistory"] = ExpressionHistory;
            SessionBag.Current.ImportData = ExpressionHistory;
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, reps);

            return(response);
        }
 public HistoryEditCommand(ExpressionHistory expressionHistory, string expression)
 {
     _expressionHistory = expressionHistory;
     _expression        = expression;
     _expressionHistory.Append(_expression);
 }