public void ApplyStatus(StatusFactory factory, BaseAvatar source) { if (currentEffects.Contains(factory)) { return; } Status s = factory.GetStatus(this, source); currentEffects.Add(factory); s.OnUnapply += () => { Debug.Log("OnUnapply"); currentEffects.Remove(factory); OnStatusRemoved(s); }; s.Apply(); OnStatusApplied(s); }
public SubmissionResult Verify(Submission submission, Problem problem, ProblemTest problemTest, Execution execution, string output) { SubmissionResult submissionResult = new SubmissionResult { SubmissionId = submission.Id, TestId = submission.Id, Time = execution.TotalMs, Memory = (int)execution.UsedMemoryKBs }; if (problem.TimeLimit + 199 < execution.TotalMs) { submissionResult.Score = 0; submissionResult.StatusId = StatusFactory.GetStatus(Constants.Statuses.Codes.TLE).Id; } if (problem.MemoryLimit < execution.UsedMemoryKBs) { submissionResult.Score = 0; submissionResult.StatusId = StatusFactory.GetStatus(Constants.Statuses.Codes.MLE).Id; } else if (!execution.HasOutputFile) { submissionResult.Score = 0; submissionResult.StatusId = StatusFactory.GetStatus(Constants.Statuses.Codes.MOF).Id; } else if (MathcesOutput(output, execution.Output)) { submissionResult.Score = problemTest.Score; submissionResult.StatusId = StatusFactory.GetStatus(Constants.Statuses.Codes.OK).Id; } else { submissionResult.Score = 0; submissionResult.StatusId = StatusFactory.GetStatus(Constants.Statuses.Codes.WA).Id; } if (!execution.HasTerminated && submissionResult.Score == 0) { submissionResult.Score = 0; submissionResult.StatusId = StatusFactory.GetStatus(Constants.Statuses.Codes.TLE).Id; } return(submissionResult); return(null); }
public ActionResult Post([FromBody] EmulatorPacket emulatorPacket) { EntityEntry <EmulationSessionMap> session; try { session = _sap1EmuContext.Add <EmulationSessionMap>(new EmulationSessionMap { EmulationID = Guid.NewGuid(), ConnectionID = null, SessionStart = DateTime.UtcNow, EmulatorId = _emulatorId, StatusId = StatusFactory.GetStatus(StatusType.Pending).Id, InstructionSetId = _instructionSets[emulatorPacket.SetName] }); _sap1EmuContext.CodeSubmissions.Add(new CodeSubmission() { EmulationID = session.Entity.EmulationID, Code = emulatorPacket.CodeList, }); _sap1EmuContext.SaveChanges(); } catch (KeyNotFoundException) { return(BadRequest( // TODO: Set Type to supported_sets url new ProblemDetails() { Status = StatusCodes.Status400BadRequest, Type = "", Title = "Invalid SetName...", Detail = $"The Instruction Set `{emulatorPacket.SetName}` does not exist.", Instance = HttpContext.Request.Path } )); } try { List <string> compiled_binary = Assemble.Parse(emulatorPacket.CodeList, emulatorPacket.SetName); RAMProgram rmp = new RAMProgram(compiled_binary); EngineProc engine = new EngineProc(); engine.Init(rmp, _decoder, emulatorPacket.SetName); engine.Run(); session.Entity.SessionEnd = DateTime.UtcNow; session.Entity.StatusId = StatusFactory.GetStatus(StatusType.Ok).Id; _sap1EmuContext.SaveChanges(); return(Ok(engine.FrameStack())); } catch (ParseException pe) { session.Entity.SessionEnd = DateTime.UtcNow; session.Entity.StatusId = StatusFactory.GetStatus(StatusType.ParsingError).Id; if (pe.InnerException != null) { string msg = (pe.Message + " " + pe.InnerException.Message); _sap1EmuContext.ErrorLog.Add(new ErrorLog() { EmulationID = session.Entity.EmulationID, ErrorMsg = msg }); _sap1EmuContext.SaveChanges(); return(BadRequest(msg)); } else { _sap1EmuContext.ErrorLog.Add(new ErrorLog() { EmulationID = session.Entity.EmulationID, ErrorMsg = pe.Message }); _sap1EmuContext.SaveChanges(); return(BadRequest(pe.Message)); } } catch (EngineRuntimeException ere) { session.Entity.SessionEnd = DateTime.UtcNow; session.Entity.StatusId = StatusFactory.GetStatus(StatusType.EmulationError).Id; if (ere.InnerException != null) { string msg = (ere.Message + " " + ere.InnerException.Message); _sap1EmuContext.ErrorLog.Add(new ErrorLog() { EmulationID = session.Entity.EmulationID, ErrorMsg = msg }); _sap1EmuContext.SaveChanges(); return(BadRequest(ere.Message + " " + ere.InnerException.Message)); } else { _sap1EmuContext.ErrorLog.Add(new ErrorLog() { EmulationID = session.Entity.EmulationID, ErrorMsg = ere.Message }); _sap1EmuContext.SaveChanges(); return(BadRequest(ere.Message)); } } catch (Exception e) { session.Entity.SessionEnd = DateTime.UtcNow; session.Entity.StatusId = StatusFactory.GetStatus(StatusType.SystemError).Id; _sap1EmuContext.ErrorLog.Add(new ErrorLog() { EmulationID = session.Entity.EmulationID, ErrorMsg = e.Message }); _sap1EmuContext.SaveChanges(); return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult StartEmulation([FromBody] SAP2CodePacket sap2CodePacket) { EmulationSessionMap session = null; try { session = _sap1EmuContext.EmulationSessionMaps .Single(esm => esm.EmulationID == sap2CodePacket.EmulationID); } catch (InvalidOperationException) { return(BadRequest(sap2CodePacket.EmulationID)); } if (session.StatusId != (int)StatusType.Pending) { string message = string.Empty; switch ((StatusType)session.StatusId) { case StatusType.Ok: message = "Emulation Complete: Please use 'GET: /session/{id}/recall' instead"; break; case StatusType.SQLError: case StatusType.ParsingError: case StatusType.EmulationError: case StatusType.SystemError: message = "Emulation Errored: Please create new session"; break; case StatusType.InProgress: message = "Emulation In Progress: Please use 'POST: /{id}/resume' instead"; break; default: message = "Unknown Host Error"; break; } return(BadRequest( new { EmulationID = sap2CodePacket.EmulationID, Status = StatusFactory.GetStatus((StatusType)session.StatusId), Message = message } )); } // This will save the plain code try { _sap1EmuContext.CodeSubmissions.Add( new CodeSubmission() { EmulationID = session.EmulationID, Code = sap2CodePacket.Code } ); _sap1EmuContext.SaveChanges(); } catch (Exception e) { _sap1EmuContext.ErrorLog.Add( new ErrorLog { EmulationID = session.EmulationID, ErrorMsg = "NON-FATAL SQL ERROR:\t" + e.Message + (e.InnerException != null ? "\t" + e.InnerException.Message : "") } ); //session.SessionEnd = DateTime.UtcNow; session.StatusId = (int)StatusType.SQLError; _sap1EmuContext.SaveChanges(); } SAP2BinaryPacket sap2BinaryPacket; // Assemble try { sap2BinaryPacket = new SAP2BinaryPacket() { EmulationID = sap2CodePacket.EmulationID, Code = Assemble.Parse((List <string>)sap2CodePacket.Code), SetName = sap2CodePacket.SetName }; } catch (ParseException pe) { session.StatusId = (int)StatusType.ParsingError; session.SessionEnd = DateTime.UtcNow; string errorMsg = pe.Message + (pe.InnerException != null ? "\n" + pe.InnerException.Message : ""); _sap1EmuContext.ErrorLog.Add( new ErrorLog { EmulationID = session.EmulationID, ErrorMsg = errorMsg } ); _sap1EmuContext.SaveChanges(); return(BadRequest( new { EmulationID = sap2CodePacket.EmulationID, Status = StatusFactory.GetStatus((StatusType)session.StatusId), Message = errorMsg } )); } // Save Binary try { _sap1EmuContext.CodeSubmissionsBinary.Add( new CodeSubmission() { EmulationID = session.EmulationID, Code = sap2BinaryPacket.Code } ); _sap1EmuContext.SaveChanges(); } catch (Exception e) { _sap1EmuContext.ErrorLog.Add( new ErrorLog { EmulationID = session.EmulationID, ErrorMsg = "NON-FATAL SQL ERROR:\t" + e.Message + (e.InnerException != null ? "\t" + e.InnerException.Message : "") } ); session.SessionEnd = DateTime.UtcNow; session.StatusId = (int)StatusType.SystemError; _sap1EmuContext.SaveChanges(); } // Run Emulator try { RAMProgram rmp = new RAMProgram((List <string>)sap2BinaryPacket.Code); EngineProc engine = new EngineProc(); engine.Init(rmp, _decoder, sap2BinaryPacket.SetName); engine.Run(); session.StatusId = (int)StatusType.Ok; session.SessionEnd = DateTime.UtcNow; _sap1EmuContext.SaveChanges(); return(Ok(engine.FrameStack())); } catch (EngineRuntimeException ere) { session.StatusId = (int)StatusType.EmulationError; session.SessionEnd = DateTime.UtcNow; string errorMsg = ere.Message + (ere.InnerException != null ? "\n" + ere.InnerException.Message : ""); _sap1EmuContext.ErrorLog.Add( new ErrorLog { EmulationID = session.EmulationID, ErrorMsg = errorMsg } ); _sap1EmuContext.SaveChanges(); return(BadRequest( new { EmulationID = sap2CodePacket.EmulationID, Status = StatusFactory.GetStatus((StatusType)session.StatusId), Message = errorMsg } )); } }