public void RunSimulation() { var krankenhausMain = new KrankenhausMain(); krankenhausMain.PatientsMoved += KrankenhausConsolePrinter.PrintPatientsMovedToConsole; krankenhausMain.PatientsMoved += KrankenhausFileLogger.LogPatientsMovedToConsole; krankenhausMain.SimulationOver += CancelSimulation; var threadOne = new Thread(krankenhausMain.ThreadOne); //Adds 30 patients threadOne.Start(); var threadFive = new Thread(krankenhausMain.ThreadFive); //Adds 10 doctors threadFive.Start(); Thread simulationPartOne = new Thread(() => PartOne(krankenhausMain)); //Starts threads which runs every 3 seconds simulationPartOne.Start(); Thread simulationPartTwo = new Thread(() => PartTwo(krankenhausMain)); //Starts threads which runs every 5 seconds simulationPartTwo.Start(); Thread runCheckIfSimulationIsOverLoop = new Thread(() => RunCheckIfSimulationIsOverLoop(krankenhausMain));//Starts a thread which continuously checks if simulation is over runCheckIfSimulationIsOverLoop.Start(); }
/// <summary> /// Calls the thread which checks if the simulation is over. If all patietns have been moved to afterlife or being discharged for hospital. /// </summary> /// <param name="krankenhausMain"></param> private void RunCheckIfSimulationIsOverLoop(KrankenhausMain krankenhausMain) { while (true) { Thread checkIfSimulationIsOver = new Thread(krankenhausMain.ThreadCheckIfSimulationOver); //Starts a thread which checks if simulation is over checkIfSimulationIsOver.Start(); if (SimulationOver) { break; } Thread.Sleep(1000); } }
/// <summary> /// Starts all threads running on a 3 second interval and checks if KrankenhausSimulation property "simulationOver" is true. Then the threads stops getting started. /// </summary> /// <param name="krankenhausMain"></param> private void PartOne(KrankenhausMain krankenhausMain) { while (true) { var threadThree = new Thread(krankenhausMain.ThreadThree); threadThree.Start(); Thread.Sleep(300); if (SimulationOver) { break; } } }
/// <summary> /// **ONLY FOR USE BY LEAD DEVELOPER or Paul T ** Removes all records from every table in the database /// </summary> public static void RemoveEverythingFromAllTable() { var kranken = new KrankenhausMain(); kranken.RemoveAllFromDatabase(); using (var db = new KrankenhausContext()) { var patientHistory = db.PatientHistories.ToList(); for (int i = 0; i < patientHistory.Count; i++) { db.PatientHistories.Remove(patientHistory[i]); db.SaveChanges(); } } }
/// <summary> /// Starts all threads running on a 5 second interval and checks if KrankenhausSimulation property "simulationOver" is true. Then the threads stops getting started. /// </summary> /// <param name="krankenhausMain"></param> private void PartTwo(KrankenhausMain krankenhausMain) { while (true) { var threadTwo = new Thread(krankenhausMain.ThreadTwo); threadTwo.Start(); var threadFour = new Thread(krankenhausMain.ThreadFour); threadFour.Start(); var threadSix = new Thread(krankenhausMain.ThreadSix); threadSix.Start(); Thread.Sleep(500); if (SimulationOver) { break; } } }
/// <summary> /// Removes all info from the database, making sure it is a "clean slate" for next simulation /// </summary> internal void RemoveAllCurrentInfoFromSimulator() { KrankenhausMain krankenhausMain = new KrankenhausMain(); krankenhausMain.RemoveAllFromDatabase(); }