public async Task <SaveResult> StoreSubmision(SubmisionDto submision) { try { if (!_directoryEngine.ValidateSubmision(submision)) { return new SaveResult { Type = ResultType.ValidationFailed } } ; return(await _directoryEngine.StoreSubmision(submision)); } catch (Exception ex) { await _logger.LogException(new ExceptionLogDto(ex)); return(new SaveResult { Type = ResultType.Exception, Message = ex.Message }); } }
public async Task <IActionResult> ProblemContestExecute([FromForm] FileExecutionContestViewModel model) { //read the content of the file Tuple <string, long> fileContent = await FileHelpers.ProcessFormFile(model.File, ModelState); double sizeOfFile = (fileContent.Item2) % 1000; var compilationModel = new CompilationModel { Content = fileContent.Item1, Language = model.Compilator, ProblemName = model.ProblemName, Username = User.Identity.Name }; //save the submission var submission = new Submision { SubmisionId = Guid.NewGuid(), DataOfSubmision = DateTime.Now, Compilator = model.Compilator, ProblemId = Guid.Parse(model.ProblemId), SourceSize = sizeOfFile.ToString(), StateOfSubmision = SubmissionStatus.NotCompiled.ToString(), UserName = User.Identity.Name, MessageOfSubmision = string.Empty, Score = 0, JobQueued = false, SourceCode = fileContent.Item1 }; await _submisionRepository.AddAsync(submission); var submissionContest = new SubmisionContest { SubmisionContestId = Guid.NewGuid(), ContestId = model.ContestId, SubmisionId = submission.SubmisionId }; await _submisionContestRepository.AddAsync(submissionContest); //build the submission dto var problem = _problemRepository.GetItem(submission.ProblemId); string problemName = problem.ProblemName; int nrOfTests = _testRepository.GetNumberOfTestForProblem(problem.ProblemId); var submissionDtoModel = new SubmisionDto { Compilator = submission.Compilator, ProblemName = problemName, Content = submission.SourceCode, SubmissionId = submission.SubmisionId, UserName = User.Identity.Name, MemoryLimit = problem.MemoryLimit, TimeLimit = problem.TimeLimit, NumberOfTests = nrOfTests, FileName = problemName.ToLower() }; await Task.Run(() => VerificaThread(submissionDtoModel)); return(RedirectToAction(nameof(ProblemsOverview), new { id = model.ContestId })); }
public async Task MakeSubmissionRequestAsync(SubmisionDto submision, string _compilationApi, string _executionApi) { UpdateSubmissionStatus(submision.SubmissionId, SubmissionStatus.Compiling, string.Empty, 0); //notify signal r to compiling status await NotifyResponse(MessageType.CompilationMessage, SubmissionStatus.Compiling.ToString(), submision.SubmissionId.ToString(), "0"); var compilationModel = new CompilationModel { Content = submision.Content, Language = submision.Compilator, ProblemName = submision.ProblemName, Username = submision.UserName }; var client = new HttpClient(); var serializedData = JsonConvert.SerializeObject(compilationModel); var httpContent = new StringContent(serializedData, Encoding.UTF8, "application/json"); var response = await client.PostAsync(_compilationApi, httpContent); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); var content = JsonConvert.DeserializeObject <ResponseCompilationModel>(result); if (content.CompilationResponse == "SUCCESS") { UpdateSubmissionStatus(submision.SubmissionId, SubmissionStatus.Compiled, content.OutputMessage, 0); //notify with signal r await NotifyResponse(MessageType.CompilationMessage, SubmissionStatus.Compiled.ToString(), submision.SubmissionId.ToString(), "0"); //call the api to execute await semaphoreSlim.WaitAsync(); try { await ExecuteSubmission(submision, _executionApi); } finally { semaphoreSlim.Release(); } } else { UpdateSubmissionStatus(submision.SubmissionId, SubmissionStatus.CompilationError, content.OutputMessage, 0); //notify with signal r await NotifyResponse(MessageType.CompilationMessage, SubmissionStatus.CompilationError.ToString(), submision.SubmissionId.ToString(), "0"); } } else { //server error UpdateSubmissionStatus(submision.SubmissionId, SubmissionStatus.ServerError, response.ReasonPhrase, 0); } }
public async Task <int> StoreSubmision(SubmisionDto submision) { using (var ctx = _contextFactory.ConstructContext()) { await ctx.Submisions.AddAsync(submision.ToEntity()); return(await ctx.SaveChangesAsync(true)); } }
private async Task VerificaThread(SubmisionDto submissionDtoModel) { semaphoreSlim.Wait(); try { var submRequest = new SubmissionRequest(_submissionHub, _submisionRepository, _hubContext, _serializeTests, _evaluationRepository); await submRequest.MakeSubmissionRequestAsync(submissionDtoModel, _compilationApi, _executionApi); } finally { semaphoreSlim.Release(); } }
public bool ValidateSubmision(SubmisionDto submision) { if (submision == null) { return(false); } if (!submision.FamilyName.HasValue()) { return(false); } if (submision.HomeAddress == null) { return(false); } if (!submision.HomeAddress.City.HasValue()) { return(false); } if (string.IsNullOrEmpty(submision.HomeAddress.Zip)) { return(false); } if (string.IsNullOrEmpty(submision.HomeAddress.Street)) { return(false); } if (!ValidatePhone(submision.HomePhone)) { return(false); } if (!ValidatePhone(submision.AdultOneMobilePhone)) { return(false); } if (!ValidatePhone(submision.AdultTwoMobilePhone)) { return(false); } return(!string.IsNullOrEmpty(submision.AdultOneFirstName.TryTrim())); }
public async Task SubmitFormTest2() { //Arrange using (var dirCtxFactory = new SharedSqliteInMemoryContextFactory <DirectoryContext>()) using (var logCtxFactory = new SharedSqliteInMemoryContextFactory <LogContext>()) using (var logCtx = logCtxFactory.ConstructContext()) { await logCtx.Database.ExecuteSqlCommandAsync("delete from detail"); await logCtx.Database.ExecuteSqlCommandAsync("delete from header"); var manager = FactoryManager(null, logCtxFactory, dirCtxFactory); var request = new SubmisionDto { FamilyName = "testerson", AdultOneFirstName = "test", HomePhone = new PhoneDto { PhoneType = PhoneType.Home, Number = "6365555555" }, HomeAddress = new AddressDto { Street = "123 Main", City = "Hometown", Zip = "90210", AddressType = AddressType.Home, State = new StateDto { Abbreviation = "GH" } }, }; //Act var result = await manager.StoreSubmision(request); //Assert Assert.IsNotNull(result, "should always respond."); Assert.AreEqual(ResultType.Exception, result.Type, "Should succeed"); Assert.AreEqual("Could not match state: GH", result.Message, "Should be equal"); Assert.AreEqual(1, logCtx.LogHeaders.Count(), "Should be a msg logged after this"); Assert.AreEqual(2, logCtx.LogDetails.Count(), "Should be two details logged after this"); } }
private async Task ExecuteSubmission(SubmisionDto submision, string _executionApi) { var client = new HttpClient(); var executionModel = new ExecutionModel { MemoryLimit = submision.MemoryLimit, ProblemName = submision.ProblemName, UserName = submision.UserName, TimeLimit = submision.TimeLimit, Compilator = submision.Compilator, FileName = submision.FileName, NumberOfTests = submision.NumberOfTests }; var serializedExecutionData = JsonConvert.SerializeObject(executionModel); var httpContentExecution = new StringContent(serializedExecutionData, Encoding.UTF8, "application/json"); var responseExecution = await client.PostAsync(_executionApi, httpContentExecution); if (responseExecution.StatusCode == System.Net.HttpStatusCode.OK) { var resultExecution = await responseExecution.Content.ReadAsStringAsync(); var responseExecutionModels = DeserializeExecutionResponse(resultExecution); var serializedData = _serializeTests.SerializeReponseTest(responseExecutionModels); //save in db the serializedData var evaluationModel = new Evaluation { EvaluationId = Guid.NewGuid(), EvaluationResult = serializedData.Item1, Score = serializedData.Item2, SubmisionId = submision.SubmissionId }; await _evaluationRepository.AddAsync(evaluationModel); UpdateSubmissionStatus(submision.SubmissionId, SubmissionStatus.Executed, string.Empty, serializedData.Item2); //notify with signalR await NotifyResponse(MessageType.ExecutionMessage, SubmissionStatus.Executed.ToString(), submision.SubmissionId.ToString(), serializedData.Item2.ToString()); var x = 2; } else { //server error UpdateSubmissionStatus(submision.SubmissionId, SubmissionStatus.ServerError, responseExecution.ReasonPhrase, 0); } }
public async Task <SaveResult> StoreSubmision(SubmisionDto submision) { var state = await GetStateByAbbr(submision.HomeAddress.State.Abbreviation); if (state == null) { throw new InvalidDataException($"Could not match state: {submision.HomeAddress.State.Abbreviation}"); } submision.HomeAddress.State.Id = state.Id; var rowCount = await _directoryAccessor.StoreSubmision(submision); return(new SaveResult { Type = DeterminExpectedRowCount(submision) == rowCount ? ResultType.Success : ResultType.SaveFailure, RowsAffected = rowCount }); }
private void AddRow(DataTable table, SubmisionDto dto) { var row = table.NewRow(); row[0] = dto.FamilyName; row[1] = dto.AdultOneFirstName; row[2] = dto.AdultTwoFirstName; row[3] = dto.OtherFamily; row[4] = dto.PublishAddress.ToString(); row[5] = dto.PublishPhone.ToString(); row[6] = dto.HomePhone?.Number; //TODO: format like nnn-nnn-nnnn row[7] = dto.HomeAddress.Street; row[8] = dto.HomeAddress.City; row[9] = dto.HomeAddress.State.Name; row[10] = dto.HomeAddress.Zip; row[11] = dto.AdultOneMobilePhone?.Number; //TODO: format like nnn-nnn-nnnn row[12] = dto.AdultOneEmailAddress?.Address; row[13] = dto.AdultTwoMobilePhone?.Number; //TODO: format like nnn-nnn-nnnn row[14] = dto.AdultTwoEmailAddress?.Address; table.Rows.Add(row); }
internal static SubmisionEntitiy ToEntity(this SubmisionDto dto) { if (dto == null) { return(null); } return(new SubmisionEntitiy { PublishAddress = dto.PublishAddress, PublishPhone = dto.PublishPhone, FamilyName = dto.FamilyName, AdultOneFirstName = dto.AdultOneFirstName, AdultTwoFirstName = dto.AdultTwoFirstName, OtherFamily = dto.OtherFamily, HomeAddress = dto.HomeAddress?.ToEntity(), HomePhone = dto.HomePhone?.ToEntity(), AdultOneMobilePhone = dto.AdultOneMobilePhone?.ToEntity(), AdultTwoMobilePhone = dto.AdultTwoMobilePhone?.ToEntity(), AdultOneEmail = dto.AdultOneEmailAddress?.ToEntity(), AdultTwoEmail = dto.AdultTwoEmailAddress?.ToEntity() }); }
private int DeterminExpectedRowCount(SubmisionDto dto) { var count = 1; if (dto.HomeAddress != null) { count++; } if (dto.HomePhone != null) { count++; } if (dto.AdultOneEmailAddress != null) { count++; } if (dto.AdultOneMobilePhone != null) { count++; } if (dto.AdultTwoEmailAddress != null) { count++; } if (dto.AdultTwoMobilePhone != null) { count++; } return(count); }