/// <summary> /// Initialize connection with TransportHub and subscribe to receive location updates. /// </summary> /// <returns></returns> private async Task InitializeSignalRClient() { try { _liveTrackingService = new LiveTrackingClientService(); await _liveTrackingService.Initialize("http://localhost:5000/live-tracking"); _liveTrackingService.SubscribeHubMethod("location-update"); _liveTrackingService.OnMessageReceived += (locationUpdate) => { UpdateLocationOnMap(locationUpdate); }; } catch (Exception ex) { InformationLabel.Text = "SignalR Connection error: " + ex.Message; } }
private static async Task Main(string[] args) { List <LocationUpdate> locationUpdates = new List <LocationUpdate> { new LocationUpdate { Latitude = 52.23292, Longitude = 20.99114, DriverName = "Daniel" }, new LocationUpdate { Latitude = 52.25229, Longitude = 20.94341, DriverName = "Daniel" }, new LocationUpdate { Latitude = 52.19462, Longitude = 20.82109, DriverName = "Daniel" }, new LocationUpdate { Latitude = 52.09011, Longitude = 20.36584, DriverName = "Daniel" }, new LocationUpdate { Latitude = 52.01813, Longitude = 19.97684, DriverName = "Daniel" }, new LocationUpdate { Latitude = 51.87744, Longitude = 19.64773, DriverName = "Daniel" }, new LocationUpdate { Latitude = 51.13844, Longitude = 16.93472, DriverName = "Daniel" }, new LocationUpdate { Latitude = 51.12705, Longitude = 16.92196, DriverName = "Daniel" }, }; var hubClient = new LiveTrackingClientService(); await hubClient.Initialize("http://localhost:5000/live-tracking"); Observable .Interval(TimeSpan.FromSeconds(3)) .Subscribe( async x => { var locationUpdate = locationUpdates.FirstOrDefault(); if (locationUpdate != null) { await hubClient.SendHubMessage("location-update", locationUpdate); Console.WriteLine("SENDING LOCATION UPDATE: " + locationUpdate.DriverName + " " + locationUpdate.Latitude + " " + locationUpdate.Longitude); locationUpdates.Remove(locationUpdate); } else { Console.WriteLine("UPDATES COMPLETED"); } }); Console.ReadKey(); }
private static async Task Main(string[] args) { List <LocationUpdate> locationUpdates = new List <LocationUpdate> { new LocationUpdate { Latitude = -8.083573, Longitude = -34.919268, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.083626, Longitude = -34.919123, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.083695, Longitude = -34.918909, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.083552, Longitude = -34.918748, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.083313, Longitude = -34.918694, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.082803, Longitude = -34.918560, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.082222, Longitude = -34.918489, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.081507, Longitude = -34.918503, DriverName = "Tales" }, //////////////////////////////// new LocationUpdate { Latitude = -8.080935, Longitude = -34.918508, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.080861, Longitude = -34.918095, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.080843, Longitude = -34.917874, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.080824, Longitude = -34.917545, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.080795, Longitude = -34.917259, DriverName = "Tales" }, new LocationUpdate { Latitude = -8.080811, Longitude = -34.916825, DriverName = "Tales" }, }; var hubClient = new LiveTrackingClientService(); await hubClient.Initialize("http://singalapi.azurewebsites.net/live-tracking"); Observable .Interval(TimeSpan.FromSeconds(3)) .Subscribe( async x => { var locationUpdate = locationUpdates.FirstOrDefault(); if (locationUpdate != null) { await hubClient.SendHubMessage("location-update", locationUpdate); Console.WriteLine("SENDING LOCATION UPDATE: " + locationUpdate.DriverName + " " + locationUpdate.Latitude + " " + locationUpdate.Longitude); locationUpdates.Remove(locationUpdate); } else { Console.WriteLine("UPDATES COMPLETED"); } }); Console.ReadKey(); }