private static void Main(string[] args) { var configuration = SimulatorConfiguration.GetCurrentConfiguration(); var instrumentationPublisher = new SenderInstrumentationManager(instrumentationEnabled: true, installInstrumentation: true) .CreatePublisher("Console"); var carEmulator = new SimulationProfile("Console", 1, instrumentationPublisher, configuration); var options = SimulationScenarios .AllScenarios .ToDictionary( scenario => "Run " + scenario, scenario => (Func <CancellationToken, Task>)(token => carEmulator.RunEmulationAsync(scenario, token))); // Add Single shot foreach (var scenario in SimulationScenarios.AllScenarios) { var name = scenario; options.Add( "Send 1 message from " + name, token => carEmulator.RunOneMessageEmulationAsync(name, token) ); } ConsoleHost.WithOptions(options, configuration.ScenarioDuration); }
public override void Run() { var stopwatch = Stopwatch.StartNew(); try { Logger.WorkerRoleRunning(); // Run the scenario for the specified time _simulationProfile .RunEmulationAsync(_scenario, _cancellationTokenSource.Token) .Wait(); stopwatch.Stop(); Logger.TotalSimulationTook(stopwatch.Elapsed); // After the scenario completes, we do not want // it to restart automatically. We block the thread // to keep from exiting Run(). Normally, blocking a // thread is a very bad thing to do. if (_cancellationTokenSource.IsCancellationRequested) { Logger.SpinningAfterScenario(); _isSpinningAfterCompletingScenario = true; _spinningCompleteEvent.WaitOne(); } } catch (Exception e) { LogHelpers.HandleRoleException(Logger, "Run()", e); } finally { _runCompleteEvent.Set(); } }