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()); }
private static void Main(string[] args) { var observableEventListener = new ObservableEventListener(); var configuration = SimulatorConfiguration.GetCurrentConfiguration(); observableEventListener.EnableEvents(ScenarioSimulatorEventSource.Log, configuration.GetLogLevel()); observableEventListener.LogToConsole(); var hostName = ConfigurationHelper.SourceName; _deviceSimulator = new SimulationProfile(hostName, configuration); // check for scenario specified on the command line if (args.Length > 0) { var scenario = args.Contains("/default", StringComparer.OrdinalIgnoreCase) ? SimulationScenarios.DefaultScenario() : args.First(x => !x.StartsWith("/", StringComparison.Ordinal)); var ct = args.Contains("/webjob", StringComparer.OrdinalIgnoreCase) ? GetWebJobCancellationToken() : CancellationToken.None; ProvisionDevicesAsync(ct).Wait(); _deviceSimulator.RunSimulationAsync(scenario, ct).Wait(); return; } var options = new Dictionary <string, Func <CancellationToken, Task> >(); options.Add("Provision Devices", ProvisionDevicesAsync); // no command line arguments, so prompt with a menu. foreach (var scenario in SimulationScenarios.AllScenarios) { options.Add("Run " + scenario, (Func <CancellationToken, Task>)(token => _deviceSimulator.RunSimulationAsync(scenario, token))); } //options.Add("Deprovision Devices", DeprovisionDevicesAsync); Tests.Common.ConsoleHost.RunWithOptionsAsync(options).Wait(); }
public override void Run() { try { Trace.TraceInformation("ScenarioSimulator.WorkerRole is running"); var scenario = SimulationScenarios.DefaultScenario(); _deviceSimulator.RunSimulationAsync(scenario, _cancellationTokenSource.Token).Wait(); Trace.TraceInformation("ScenarioSimulator.WorkerRole is complete"); } catch (Exception ex) { Trace.TraceError(ex.ToString()); } finally { _runCompleteEvent.Set(); } }