예제 #1
0
        public ActionResult History(string filter, int deleteId = 0, bool myOperHistory = false)
        {
            var model = new HistoryViewModel();

            if (deleteId != 0)
            {
                OperationResultRepository.Delete(deleteId);
                deleteId = 0;
            }
            if (myOperHistory)
            {
                model.OperationHistory = GetCurrentUser().Operations;
                return(View(model));
            }
            if (filter == null || filter == "")
            {
                model.OperationHistory = OperationResultRepository.GetAll();
                model.Top = OperationResultRepository.GetTop(3);
            }
            else
            {
                model.OperationHistory = OperationResultRepository.GetAll(filter);
            }
            return(View(model));
        }
        public ActionResult History(string oper)
        {
            ViewBag.TopOperations = OperationResultRepository.GetTop(2);
            var operations = !string.IsNullOrWhiteSpace(oper)
                ? OperationResultRepository.GetAll(true).Where(o => o.OperationName == oper)
                : OperationResultRepository.GetAll(true);

            return(View(operations));
        }
예제 #3
0
        public ActionResult Index(OperationViewModel model, string submit)
        {
            bool forcedCalc = (submit == "Forced Calc");

            var operResults = OperationResultRepository.GetAll();

            var oldResult = operResults.FirstOrDefault(o =>
                                                       o.OperationName.Trim() == model.Operation && o.Arguments == model.InputData);

            if (oldResult != null && !forcedCalc)
            {
                model.Result = $"old => {oldResult.Result}";
            }
            else
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                //Подготовка словаря операций с тем же ключом, что в DropDownList
                var opers = Calc.Operations
                            .Where(o => o is IOperationArgs)
                            .ToDictionary(o => o.GetType().FullName,
                                          o => o);

                var result = Calc.Execute(opers[model.Operation], model.InputData.Split(' '));

                stopwatch.Stop();
                model.Result = result.ToString();
                //!!!Опасное преобразовние
                bool nanOrInfinity = (double.IsNaN((double)result) || double.IsInfinity((double)result));
                var  operResult    = new OperationResult()
                {
                    Id            = (oldResult != null) ? oldResult.Id : 0,
                    OperationName = model.Operation,
                    Result        = !nanOrInfinity ? result as double? : null,
                    Arguments     = model.InputData,
                    ExecutionTime = stopwatch.ElapsedMilliseconds,
                    ExecutionDate = DateTime.Now,
                    User          = GetCurrentUser()
                };
                //запись в базу
                if (forcedCalc && oldResult != null)
                {
                    OperationResultRepository.Update(operResult);
                }
                else
                {
                    OperationResultRepository.Save(operResult);
                }
            }
            model.Operations = Operations;

            return(View(model));
        }
        public ActionResult Index(OperationViewModel model)
        {
            var operResults = OperationResultRepository.GetAll();

            var oldResult = operResults.FirstOrDefault(
                op => op.OperationName == model.Operation && op.Arguments == model.InputData.Trim()
                );

            if (oldResult != null)
            {
                model.Result = $"Это уже вычислял {oldResult.Iniciator?.Name}  {oldResult.ExecutionDate}(заняло {oldResult.ExecutionTime} ms.) и получили {oldResult.Result}";
            }
            else
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();

                var names  = model.Operation.Split('.');
                var opers  = Calc.Operations.Where(o => o.Name == names[1]);
                var oper   = opers.FirstOrDefault(o => o.GetType().Name == names[0]);
                var result = Calc.Execute(oper, model.InputData.Trim().Split(' '));
                Thread.Sleep(new Random().Next(1, 100));
                stopWatch.Stop();

                model.Result = $"{result}";

                var operResult = new OperationResult()
                {
                    OperationName = model.Operation,
                    Result        = result as double?,
                    Arguments     = model.InputData.Trim(),
                    ExecutionTime = stopWatch.ElapsedMilliseconds * 10,
                    ExecutionDate = DateTime.Now,
                    Iniciator     = GetCurrentUser()
                };

                OperationResultRepository.Save(operResult);
            }

            model.Operations = OperationList;

            return(View(model));
        }
예제 #5
0
 public ActionResult History(HistoryViewModel model, string delete)
 {
     model.OperationHistory = OperationResultRepository.GetAll();
     return(View(model));
 }