public async Task AgentSimulatioAsync(int simulationConfigurationId) { // In-memory database only exists while the connection is open var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:" }; var connection = new SqliteConnection(connectionStringBuilder.ToString()); // create OptionsBuilder with InMemmory Context var builder = new DbContextOptionsBuilder <MasterDBContext>(); builder.UseSqlite(connection); var simNumber = _evaluationContext.GetSimulationNumber(simulationConfigurationId, SimulationType.Decentral); using (var c = new InMemoryContext(builder.Options)) { c.Database.OpenConnection(); c.Database.EnsureCreated(); InMemoryContext.LoadData(_evaluationContext, c); var sim = new AgentSimulation(c, _messageHub); await sim.RunSim(simulationConfigurationId, simNumber); CopyResults.Copy(c, _evaluationContext, simulationConfigurationId, simNumber, SimulationType.Decentral); CalculateKpis.MachineSattleTime(_evaluationContext, simulationConfigurationId, SimulationType.Decentral, simNumber); CalculateKpis.CalculateAllKpis(_evaluationContext, simulationConfigurationId, SimulationType.Decentral, simNumber, true); } connection.Close(); _messageHub.EndSimulation("Simulation with Id:" + simulationConfigurationId + " Completed." , simulationConfigurationId.ToString() , simNumber.ToString()); }
public async Task RunSimulation(int simulationId, int simulationNumber) { await _agentSimulation.RunSim(simulationId, simulationNumber); _messageHub.SendToAllClients("Number of involved Agents: " + Agent.AgentCounter.Count, MessageType.success); _messageHub.SendToAllClients("Number of instructions send: " + Agent.InstructionCounter, MessageType.success); var itemlist = from val in Agent.AgentStatistics group val by new { val.AgentType } into grouped select new { Agent = grouped.First().AgentType, ProcessingTime = grouped.Sum(x => x.ProcessingTime), Count = grouped.Count().ToString() }; foreach (var item in itemlist) { _messageHub.SendToAllClients(" Agent (" + Agent.AgentCounter.Count(x => x == item.Agent) + "): " + item.Agent + " -> Runtime: " + item.ProcessingTime + " Milliseconds with " + item.Count + " Instructions Processed", MessageType.warning); } //var jobs = itemlist.Count(x => x.) var jobs = AgentStatistic.Log.Count(x => x.Contains("Finished Work with")); _messageHub.SendToAllClients(jobs + " Jobs processed in " + (Agent.AgentStatistics.Max(x => x.Time) - 1) + " minutes", MessageType.success); _messageHub.SendToAllClients("Simulation Finished"); _messageHub.EndScheduler(); }