Ejemplo n.º 1
0
        public ActionResult <CheckTaskResponse> Post([FromBody] CheckTaskRequest value)
        {
            var res = new ObjectResult(JsonConvert.SerializeObject(_tasksManager.CheckCode(value, path)));

            res.ContentTypes.Add(new MediaTypeHeaderValue("application/json"));
            return(res);
        }
Ejemplo n.º 2
0
        public IActionResult Check(CurrentTask values)
        {
            var watch = new Stopwatch();

            watch.Start();
            _currentTask.Code = values.Code;

            string path = _settings.Value.BaseUrlApi + "/api/task";
            var    obj  = new CheckTaskRequest()
            {
                Code = _currentTask.Code, Id = _currentTask.Id
            };
            CheckTaskResponse resp;

            try
            {
                resp = JsonConvert.DeserializeObject <CheckTaskResponse>(PostObject(path, obj).Result);
            }
            catch (TimeoutException)
            {
                ViewBag.Message = "Timeout!";
                return(View("Error"));
            }
            catch (AggregateException)
            {
                ViewBag.Message = "Cannot reach API";
                return(View("Error"));
            }
            catch (Exception e)
            {
                ViewBag.Message = e.Message;
                return(View("Error"));
            }

            //ViewBag.CurrentTask = _currentTask;

            //if (resp.Result)
            //{
            ViewBag.AlertClass     = "alert alert-info";
            ViewBag.AlertText      = "Result:";
            ViewBag.TasksCounter   = _tasksCounter;
            _currentTask.Completed = true;
            //}
            //else
            //{
            //    ViewBag.AlertClass = "alert alert-danger";
            //    ViewBag.AlertText = "Error";
            //    _currentTask.Completed = false;
            //}
            watch.Stop();
            var time   = "\r\nTime: " + watch.Elapsed;
            var length = "\r\nLength: " + values.Code.Length + "/1300";

            ViewBag.Message = resp.Message + time + length;
            return(View("Task", _currentTask));
        }
Ejemplo n.º 3
0
        public CheckTaskResponse CheckCode(CheckTaskRequest request, ConfigurationPaths paths)
        {
            CheckTaskResponse answer = new CheckTaskResponse()
            {
                Id = request.Id, Result = true
            };

            if (request.Code == null)
            {
                answer.Message = "Please, enter your code";
                answer.Result  = false;
                return(answer);
            }

            Compiler = new CodeCompiler();

            try
            {
                Compiler.CreateCs(paths.CsFilePath, "test", request.Code);
                ProcessResultModel result = Compiler.CompileProgram(paths.CompilerPath, paths.CsFilePath);

                if (result.ExitCode != 0)
                {
                    answer.Result  = false;
                    answer.Message = result.Result.Substring(371, result.Result.Length - 371);
                    return(answer);
                }

                SetTests(request.Id, paths);
                //answer.Message = "Running tests: \n";

                for (int i = 0; i < TestValues.Length && i < TestResults.Length; i++)
                {
                    var res = RunTest(TestValues[i], TestResults[i], paths.CsFilePath);
                    answer.Message += "\nTest № " + (i + 1).ToString();
                    if (res.ExitCode != 0)
                    {
                        answer.Result = false;
                    }
                    answer.Message += res.Result;
                }

                Compiler.DeleteFiles(paths.CsFilePath);
            }
            catch (Exception e)
            {
                answer.Result  = false;
                answer.Message = e.Message;
                return(answer);
            }

            return(answer);
        }