You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Subscribe to updates on the GetVehicleLocationsAsync endpoint
You can also subscribe to the location data. The data isn't live in the sense that it isn't streamed from anywhere, the service is simply executing the GetVehicleLocationsAsync endpoint every minute behind the scenes, essentially polling for new data.
Data returned from the API is compared to data stored in an internal cache, if any new data is present, an event is raised containing the updates.
The cache service is not a data store. It's only used to present the client with updates on new data, and also to ignore data that's been received late and is out of order (due to newer items existing). It only caches the most recent data points for each vehicle, as the new data replaces the existing data as opposed to being added to the same collection.
CancellationTokenSourcects=new CancellationTokenSource(TimeSpan.FromMinutes(60));IbbClientclient=new IbbClient();// The cache service raises events notifying the client of new data.// It also ensures that data that's received out of order is ignored.VehicleLocationCacheServicecacheService=new VehicleLocationCacheService(client);
cacheService.OnVehicleLocationUpdate +=(sender,data)=>{// The event arguments contains a collection of all the updated data.// The updated elements are batched together.IEnumerable<VehiclesLocationUpdatedEventArgs>updatedData= data.UpdatedVehicleLocations; Console.WriteLine($"Elements updated: {updatedData.Count()}");};await cacheService.BeginTracking(cts.Token);