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 bool OnStart() { try { ServicePointManager.DefaultConnectionLimit = int.MaxValue; // We obtain the number of instance running this role and pass it along // to the simulation profile. Note that we are not supporting runtime // changing in the number of instances. Adding new instances at runtime will // increase the number of cars beyond the number specified in the configuration. var instanceCount = RoleEnvironment.CurrentRoleInstance.Role.Instances.Count; // Obtain the simulation configuration and generate a simulation profile. Set up // the cancellation token to terminate the simulation after the configured duration var configuration = SimulatorConfiguration.GetCurrentConfiguration(); _scenario = string.IsNullOrEmpty(configuration.Scenario) ? SimulationScenarios.DefaultScenario() : configuration.Scenario; var instrumentationPublisher = new SenderInstrumentationManager(instrumentationEnabled: true, installInstrumentation: false) .CreatePublisher("WaWorkerHost"); var hostName = ConfigurationHelper.SourceName; _simulationProfile = new SimulationProfile( hostName, instanceCount, instrumentationPublisher, configuration); _cancellationTokenSource.CancelAfter(configuration.ScenarioDuration); Logger.WorkerRoleStartedWith(configuration); } catch (Exception ex) { // Hard error on startup, usually configuration or security related // Ensure that we log this error, including a direct post to the local // event log LogHelpers.HandleRoleException(Logger, "OnStart()", ex); throw; } return(base.OnStart()); }