public void Write(Bus13VehicleLocationUpdate update) { if (_kmlWriter == null) { _kmlWriter = GetKmlWriter(update.Vehicle.Id, _outputDir); } if (update.Waypoints != null && update.Waypoints.Any()) { foreach (var waypoint in update.Waypoints) { Console.WriteLine( "id:{0}, fr:{1:F2}, lat:{2}, lng:{3}", update.Vehicle.Id, waypoint.Fraction, waypoint.Location.Position.Latitude, waypoint.Location.Position.Longitude); _kmlWriter.AddPoint(waypoint.Location.Position); } } _kmlWriter.AddPoint(update.Vehicle.Location.Position); _kmlWriter.Save(); }
public void Write(Bus13VehicleLocationUpdate update) { try { var outputFile = Path.Combine(_outputDir, string.Format("trace-{0}.json", update.Vehicle.Id)); using (var streamWriter = new StreamWriter(File.OpenWrite(outputFile))) using (var jsonTextWriter = new JsonTextWriter(streamWriter)) { var updateDTO = new VehicleLocationUpdateDTO { ReceivedAt = DateTime.UtcNow, VehicleId = update.Vehicle.Id, LastUpdatedAt = update.LastUpdate, Latitude = update.Vehicle.Location.Position.Latitude, Longitude = update.Vehicle.Location.Position.Longitude, Heading = update.Vehicle.Location.Heading, Waypoints = new List <WaypointDTO>() }; if (update.Waypoints != null) { foreach (var waypoint in update.Waypoints) { updateDTO.Waypoints.Add( new WaypointDTO { Fraction = waypoint.Fraction, Latitude = waypoint.Location.Position.Latitude, Longitude = waypoint.Location.Position.Longitude, Heading = waypoint.Location.Heading }); } } _updates.Updates.Add(updateDTO); _serializer.Serialize(jsonTextWriter, _updates); jsonTextWriter.Flush(); } } catch (Exception e) { Console.WriteLine("An error occured while writing json response: {0}", e); } }
private Bus13VehicleLocationUpdate ParseVehicleLocationUpdate(Bus13VehicleLocation bus13Vehicle) { var vehicle = new Vehicle { Id = bus13Vehicle.Id, CarPlate = bus13Vehicle.Gos_Num, Location = new GeoLocation(this.ParsePoint(bus13Vehicle.Lat, bus13Vehicle.Lon), Convert.ToSingle(bus13Vehicle.Dir)), Type = this.ParseVehicleType(bus13Vehicle.RType), RouteInfo = new VehicleRouteInfo { RouteId = this.GenerateId( new Bus13Route { Id = bus13Vehicle.RId.ToString(), Num = bus13Vehicle.RNum, Type = bus13Vehicle.RType }), RouteNumber = bus13Vehicle.RNum, DisplayName = this.GetRouteDisplayName(bus13Vehicle.RNum, this.ParseVehicleType(bus13Vehicle.RType)) } }; var locationUpdate = new Bus13VehicleLocationUpdate { Vehicle = vehicle, LastUpdate = DateTime.ParseExact(bus13Vehicle.LastTime, "dd.MM.yyyy H:mm:ss", CultureInfo.InvariantCulture), Waypoints = new List <Waypoint>() }; if (bus13Vehicle.Anim_Points != null && bus13Vehicle.Anim_Points.Any()) { locationUpdate.Waypoints = bus13Vehicle.Anim_Points.Select( x => new Waypoint( this.ParsePoint(x.Lat, x.Lon), Convert.ToSingle(int.Parse(x.Dir)), int.Parse(x.Percent) / 100.0f)) .ToList(); } ; return(locationUpdate); }