public async Task Sync(SyncExtent extent) { lastSync = DateTime.Now; if (extent == SyncExtent.None) { return; } // Force an update to the connection status, because it's possible to turn off the network on // a device and hit the sync button before the Connectivity plugin has received a connection change // event to update its status. Fortunately, its IsConnected property changes quickly, so make sure // IsOffline is updated from that before we check it. IsOffline = !CrossConnectivity.Current.IsConnected; if (IsOffline) { // Remember to sync when we go back online syncWhenReconnected = true; syncWhenReconnectedExtent = extent; return; } IsSyncing = true; Task <SyncResult> taskCategories = Empty <SyncResult> .Task; Task <SyncResult> taskSettings = Empty <SyncResult> .Task; if (extent == SyncExtent.All) { Task <SyncResult> taskAP = dataModel.SyncAuthProviders(); // Fire and forget taskCategories = dataModel.SyncCategories(); } if (extent == SyncExtent.All || extent == SyncExtent.SettingsAndItems) { taskSettings = dataModel.SyncSettings(); } // Do both categories and settings before syncing items await Task.WhenAll(taskCategories, taskSettings); await dataModel.SyncItems(); IsSyncing = false; // This makes sure the Configuration knows it can reset its changed flag. if (applyConfiguration) { dataModel.Configuration.ConfigurationApplied(); } }
public async Task CheckTimeAndSync(TimeSpan elapsed, Boolean alwaysDoItems) { SyncExtent extent = alwaysDoItems ? SyncExtent.Items : SyncExtent.None; if (elapsed.TotalMinutes >= 30) { extent = SyncExtent.SettingsAndItems; } if (elapsed.TotalDays >= 1) { extent = SyncExtent.All; } await Sync(extent); }