public static void Replay(List <Scenario> scenarios, Nats nats) { List <VehiclePosition> timedWaypoints = new List <VehiclePosition>(); foreach (var scenario in scenarios) { timedWaypoints.AddRange(GetTimedWaypointFromScenario(scenario)); } ReplayTimedWaypoints(nats, timedWaypoints); }
private static void ReplayTimedWaypoints(Nats nats, List <VehiclePosition> timedWaypoints) { var timeOrderedWaypoints = timedWaypoints.OrderBy(x => x.Position.Timestamp); foreach (var vehiclePosition in timeOrderedWaypoints) { var now = DateTimeOffset.Now; if (now < vehiclePosition.Position.Timestamp) { Thread.Sleep((int)vehiclePosition.Position.Timestamp.Subtract(now).TotalMilliseconds); } var json = JsonSerializer.GetJsonPositionReport(vehiclePosition.Vehicle, vehiclePosition.Position); Console.Out.WriteLine(json); if (nats != null) { nats.Publish("vehicle." + vehiclePosition.Vehicle.Id + ".position", json); } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseStaticFiles(); app.UseMvc(); Playback.Playback.ScenarioPath = Path.Combine(env.WebRootPath, "scenarios"); Playback.Nats.Url = Environment.GetEnvironmentVariable("NATS_URL"); Playback.Nats.User = Environment.GetEnvironmentVariable("NATS_USER"); Playback.Nats.Password = Environment.GetEnvironmentVariable("NATS_PASS"); Nats = new Playback.Nats(); HostingEnvironment = env; }
public static void Replay(Scenario scenario, Nats nats) { List <VehiclePosition> timedWaypoints = GetTimedWaypointFromScenario(scenario); ReplayTimedWaypoints(nats, timedWaypoints); }