public async Task ReloadDataAsync() { lock (syncRoot) { if (_isDataReloading) { return; } _isDataReloading = true; } var savedAlarms = await _repository.GetAllAsync().ConfigureAwait(true); GeolocationAlarms.Clear(); foreach (var geolocationAlarm in savedAlarms) { GeolocationAlarms.Add(geolocationAlarm); if (geolocationAlarm.IsActive && !_geofenceService.IsGeofenceRegistered(geolocationAlarm.Name)) { _geofenceService.RegisterGeofence(_builder.BuildFromAlarm(geolocationAlarm)); } } lock (syncRoot) _isDataReloading = false; }
public async Task DeleteAsync(Alarm alarm) { GeolocationAlarms.Remove(alarm); await _repository.DeleteAsync(alarm).ConfigureAwait(false); _geofenceService.RemoveGeofence(alarm.Name); }
private async Task InsertAsync(Alarm alarm) { GeolocationAlarms.Add(alarm); await _repository.InsertAsync(alarm).ConfigureAwait(false); _geofenceService.RegisterGeofence(_builder.BuildFromAlarm(alarm)); }
private void ReplaceAlram(Alarm replacement, Alarm replaced) { replacement.Id = replaced.Id; var index = GeolocationAlarms.IndexOf(replaced); GeolocationAlarms.RemoveAt(index); GeolocationAlarms.Insert(index, replacement); }
public async Task UpdateAsync(Alarm alarm) { if (!GeolocationAlarms.Contains(alarm)) { return; } ReplaceAlarm(alarm); await _repository.UpdateAsync(alarm).ConfigureAwait(false); _geofenceService.ReplaceGeofence(alarm.Name, _builder.BuildFromAlarm(alarm)); }
public async Task SaveAsync(Alarm alarm) { var notUniqueAlarm = GeolocationAlarms.FirstOrDefault(geolocationAlarm => geolocationAlarm.Name == alarm.Name); if (notUniqueAlarm == null) { await InsertAsync(alarm).ConfigureAwait(false); } else { ReplaceAlram(alarm, notUniqueAlarm); await UpdateAsync(alarm).ConfigureAwait(false); } }
private void ReplaceAlarm(Alarm replacement) { var replaced = GeolocationAlarms.First(alarm => alarm.Id == replacement.Id); ReplaceAlram(replacement, replaced); }