static void BackgroundSyncChecker() { lastBackgroundCheck = DateTime.Now; currentAutosyncTimeoutMinutes = autosyncTimeoutPrefMinutes; if (syncThread != null) { return; } var addin = GetConfiguredSyncService(); if (addin != null) { // TODO: block sync while checking SyncServer server = null; try { server = addin.CreateSyncServer(); if (server == null) { throw new Exception("addin.CreateSyncServer () returned null"); } } catch (Exception e) { Logger.Debug("BackgroundSyncChecker: Exception while creating SyncServer: {0}\n{1}", e.Message, e.StackTrace); addin.PostSyncCleanup(); // TODO: Needed? return; // TODO: Figure out a clever way to get the specific error up to the GUI } bool serverHasUpdates = false; bool clientHasUpdates = client.DeletedNoteTitles.Count > 0; if (!clientHasUpdates) { foreach (Note note in new List <Note> (NoteMgr.Notes)) { if (client.GetRevision(note) == -1 || note.MetadataChangeDate > client.LastSyncDate) { clientHasUpdates = true; break; } } } // NOTE: Important to check, at least to verify // that server is available try { Logger.Debug("BackgroundSyncChecker: Checking server for updates"); serverHasUpdates = server.UpdatesAvailableSince(client.LastSynchronizedRevision); } catch { // TODO: A libnotify bubble might be nice Logger.Debug("BackgroundSyncChecker: Error connecting to server"); addin.PostSyncCleanup(); return; } addin.PostSyncCleanup(); // Let FUSE unmount, etc if (clientHasUpdates || serverHasUpdates) { Logger.Debug("BackgroundSyncChecker: Detected that sync would be a good idea now"); // TODO: Check that it's safe to sync, block other sync UIs PerformSynchronization(new SilentUI(NoteMgr)); } } }