protected override async Task StartListeningAsync()
        {
            await base.StartListeningAsync();

            SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() =>
            {
                if (Beacons.Count > 0)
                {
                    _proximityObserver = new ProximityObserver(new CloudCredentials(EstimoteCloudAppId, EstimoteCloudAppToken), error =>
                    {
                        SensusServiceHelper.Get().Logger.Log("Error while initializing proximity observer:  " + error, LoggingLevel.Normal, GetType());
                    });

                    List <ProximityZone> beaconZones = new List <ProximityZone>();

                    foreach (EstimoteBeacon beacon in Beacons)
                    {
                        ProximityZone beaconZone = new ProximityZone(beacon.Tag, new ProximityRange(beacon.ProximityMeters))
                        {
                            OnEnter = async(triggeringDeviceAttachment) =>
                            {
                                await StoreDatumAsync(new EstimoteBeaconDatum(DateTimeOffset.UtcNow, beacon, EstimoteBeaconProximityEvent.Entered));
                            },

                            OnExit = async(triggeringDeviceAttachment) =>
                            {
                                await StoreDatumAsync(new EstimoteBeaconDatum(DateTimeOffset.UtcNow, beacon, EstimoteBeaconProximityEvent.Exited));
                            }
                        };

                        beaconZones.Add(beaconZone);
                    }

                    _proximityObserver.StartObservingZones(beaconZones.ToArray());
                }

                if (Location != null)
                {
                    EILRequestFetchLocation locationFetchRequest = new EILRequestFetchLocation(Location.Identifier);

                    locationFetchRequest.SendRequest((fetchedLocation, error) =>
                    {
                        if (error == null)
                        {
                            _foregroundIndoorLocationManager.StartPositionUpdatesForLocation(fetchedLocation);
                            _backgroundIndoorLocationManager.StartPositionUpdatesForLocation(fetchedLocation);
                            _indoorLocation = fetchedLocation;
                        }
                        else
                        {
                            SensusServiceHelper.Get().Logger.Log("Failed to fetch Estimote indoor location:  " + error, LoggingLevel.Normal, GetType());
                        }
                    });
                }
            });
        }
 public override async void DidUpdatePosition(EILBackgroundIndoorLocationManager locationManager, EILOrientedPoint position, EILPositionAccuracy positionAccuracy, EILLocation location)
 {
     await(UpdatedPositionAsync?.Invoke(position, positionAccuracy, location) ?? Task.CompletedTask);
 }