public async Task ExecuteAsync(ParcelTrackingEntity parcel) { GisObject gisObject = new GisObject { Latitude = parcel.Latitude, Longitude = parcel.Longitude }; // Create a new hybrid connection client var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(keyName, key); var client = new HybridConnectionClient(new Uri($"sb://{relayNamespace}/{connectionName}"), tokenProvider); // Initiate the connection var relayConnection = await client.CreateConnectionAsync(); // Bi-directional sync of GIS data: // 1. Send a GIS object to the relay // 2. Receive a GIS object with the resolved address and update the entity // 3. Close the relay connection await new Task( () => SendToRelay(relayConnection, gisObject) .ContinueWith(async(t) => { GisObject resolved = await ReadFromRelay(relayConnection); ShowAddress(resolved); }) .ContinueWith(async(t) => await relayConnection.CloseAsync(CancellationToken.None)) .Start()); void ShowAddress(GisObject resolved) { var addr = resolved.Address; parcel.Address = $"{addr.Line}, {addr.ZipCode} {addr.City}, {addr.Country}"; Update(parcel); // Update the tracking information in the system } }
private void Update(ParcelTrackingEntity parcel) { throw new NotImplementedException(); }