|
|
|
@ -1,18 +1,15 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using Volo.Abp;
|
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
using Volo.ClientSimulation.Clients;
|
|
|
|
|
using Volo.ClientSimulation.Scenarios;
|
|
|
|
|
|
|
|
|
|
namespace Volo.ClientSimulation
|
|
|
|
|
{
|
|
|
|
|
public class Simulation : ISingletonDependency
|
|
|
|
|
public class Simulation : ISingletonDependency, IDisposable
|
|
|
|
|
{
|
|
|
|
|
public GlobalOptions GlobalOptions { get; }
|
|
|
|
|
|
|
|
|
|
public GlobalOptions CurrentOptions { get; private set; }
|
|
|
|
|
|
|
|
|
|
public SimulationState State { get; private set; }
|
|
|
|
|
|
|
|
|
|
public List<IDisposableClientHandler> ActiveClients { get; }
|
|
|
|
@ -21,14 +18,16 @@ namespace Volo.ClientSimulation
|
|
|
|
|
|
|
|
|
|
protected ClientSimulationOptions Options { get; }
|
|
|
|
|
|
|
|
|
|
protected IServiceScope ServiceScope { get; }
|
|
|
|
|
|
|
|
|
|
public Simulation(
|
|
|
|
|
GlobalOptions globalOptions,
|
|
|
|
|
IClientFactory clientFactory,
|
|
|
|
|
IServiceScopeFactory serviceScopeFactory,
|
|
|
|
|
IOptions<ClientSimulationOptions> options)
|
|
|
|
|
{
|
|
|
|
|
GlobalOptions = globalOptions;
|
|
|
|
|
ClientFactory = clientFactory;
|
|
|
|
|
Options = options.Value;
|
|
|
|
|
ServiceScope = serviceScopeFactory.CreateScope();
|
|
|
|
|
ActiveClients = new List<IDisposableClientHandler>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -36,22 +35,21 @@ namespace Volo.ClientSimulation
|
|
|
|
|
{
|
|
|
|
|
State = SimulationState.Starting;
|
|
|
|
|
|
|
|
|
|
CurrentOptions = GlobalOptions.Clone();
|
|
|
|
|
|
|
|
|
|
lock (ActiveClients)
|
|
|
|
|
{
|
|
|
|
|
ActiveClients.Clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < CurrentOptions.MaxClientCount; i++)
|
|
|
|
|
foreach (var scenarioConfiguration in Options.Scenarios)
|
|
|
|
|
{
|
|
|
|
|
var selectedScenario = RandomHelper.GetRandomOfList(Options.Scenarios);
|
|
|
|
|
ActiveClients.Add(ClientFactory.Create(selectedScenario));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var activeClient in ActiveClients)
|
|
|
|
|
{
|
|
|
|
|
activeClient.Client.Stopped += ActiveClientOnStopped;
|
|
|
|
|
activeClient.Client.Start();
|
|
|
|
|
for (int i = 0; i < scenarioConfiguration.ClientCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var scenario = (IScenario) ServiceScope.ServiceProvider.GetRequiredService(scenarioConfiguration.ScenarioType);
|
|
|
|
|
var clientHandler = ClientFactory.Create(scenario);
|
|
|
|
|
|
|
|
|
|
ActiveClients.Add(clientHandler);
|
|
|
|
|
clientHandler.Client.Stopped += ActiveClientOnStopped;
|
|
|
|
|
clientHandler.Client.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -82,5 +80,10 @@ namespace Volo.ClientSimulation
|
|
|
|
|
ActiveClients.RemoveAll(c => c.Client == client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
ServiceScope.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|