public async Task <GeofenceRequest[]> GetTriggered(string userId, Location newLocation) { var gfs = (await _locationStore.GetActiveGeofenceRequests(userId, newLocation.Timestamp)) .Select(async(gf) => { var triggered = false; var distance = Geolocation.GeoCalculator.GetDistance(gf.Lat, gf.Lng, newLocation.Latitude, newLocation.Longitude, 5, Geolocation.DistanceUnit.Meters); if (gf.Exit) { if (distance >= gf.Radius) { await _logger.LogForFocusItem(userId, gf.FocusItemId, $"Geofence {gf.Id}/Exit triggered"); triggered = true; } } else { if (distance <= gf.Radius) { await _logger.LogForFocusItem(userId, gf.FocusItemId, $"Geofence {gf.Id}/Enter triggered"); triggered = true; } } return(new { gf, triggered }); }); return((await Task.WhenAll(gfs)).Where(v => v.triggered).Select(v => v.gf).ToArray()); }
public async Task <LocationResponse> LocationUpdateReceivedAsync(string userId, Location location, DateTimeOffset now, FocusManageResult focusManageResult) { await pushSyncService.SetLocationRequestDone(userId); await locationStore.UpdateLocationAsync(userId, location); //if (location.RequestSupport.HasValue && !location.RequestSupport.Value) //{ // return new LocationResponse(); //} var response = new LocationResponse() { NextUpdateRequiredAt = await RequestLocationForItems(userId, focusManageResult, now, location.Timestamp), Geofences = await locationStore.GetActiveGeofenceRequests(userId, now) }; if (response.NextUpdateRequiredAt.HasValue) { await pushSyncService.SetLocationRequestedExternal(userId, response.NextUpdateRequiredAt.Value); } return(response); }