[tomboy/autosync: 236/241] [Sync] Initial guts of background sync
- From: Sanford Armstrong <sharm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tomboy/autosync: 236/241] [Sync] Initial guts of background sync
- Date: Mon, 25 Jan 2010 19:38:10 +0000 (UTC)
commit 1e472fa8fba2d84a2a27af5c95398a1d9a415a94
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Mon Jan 25 01:40:44 2010 -0800
[Sync] Initial guts of background sync
Tomboy/Addins/WebSyncService/WebSyncServer.cs | 13 +++++++--
Tomboy/Synchronization/FileSystemSyncServer.cs | 5 +++
Tomboy/Synchronization/SyncManager.cs | 33 ++++++++++++++++++++++++
3 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/Tomboy/Addins/WebSyncService/WebSyncServer.cs b/Tomboy/Addins/WebSyncService/WebSyncServer.cs
index 6884ec5..285c16a 100644
--- a/Tomboy/Addins/WebSyncService/WebSyncServer.cs
+++ b/Tomboy/Addins/WebSyncService/WebSyncServer.cs
@@ -34,7 +34,7 @@ namespace Tomboy.WebSync
{
public class WebSyncServer : SyncServer
{
- private string serverUrl;
+ private string rootUri;
private IWebConnection connection;
private RootInfo root;
@@ -43,8 +43,8 @@ namespace Tomboy.WebSync
public WebSyncServer (string serverUrl, IWebConnection connection)
{
- this.serverUrl = serverUrl;
this.connection = connection;
+ rootUri = serverUrl + "/api/1.0/"; // TODO: Trim trailing / from serverUrl if necessary
}
#region SyncServer implementation
@@ -52,7 +52,6 @@ namespace Tomboy.WebSync
public bool BeginSyncTransaction ()
{
// TODO: Check connection and auth (is getting root/user resources a sufficient check?)
- string rootUri = serverUrl + "/api/1.0/";
root = RootInfo.GetRoot (rootUri, connection);
user = UserInfo.GetUser (root.User.ApiRef, connection);
if (user.LatestSyncRevision.HasValue)
@@ -141,6 +140,14 @@ namespace Tomboy.WebSync
foreach (Note note in notes)
pendingCommits.Add (NoteConvert.ToNoteInfo (note));
}
+
+ public bool UpdatesAvailableSince (int revision)
+ {
+ root = RootInfo.GetRoot (rootUri, connection);
+ user = UserInfo.GetUser (root.User.ApiRef, connection);
+ return user.LatestSyncRevision.HasValue &&
+ user.LatestSyncRevision.Value > revision;
+ }
#endregion
diff --git a/Tomboy/Synchronization/FileSystemSyncServer.cs b/Tomboy/Synchronization/FileSystemSyncServer.cs
index 5cd5315..9aa29cb 100644
--- a/Tomboy/Synchronization/FileSystemSyncServer.cs
+++ b/Tomboy/Synchronization/FileSystemSyncServer.cs
@@ -96,6 +96,11 @@ namespace Tomboy.Sync
return noteUUIDs;
}
+ public bool UpdatesAvailableSince (int revision)
+ {
+ return LatestRevision > revision; // TODO: Mounting, etc?
+ }
+
public virtual IDictionary<string, NoteUpdate> GetNoteUpdatesSince (int revision)
{
Dictionary<string, NoteUpdate> noteUpdates = new Dictionary<string, NoteUpdate> ();
diff --git a/Tomboy/Synchronization/SyncManager.cs b/Tomboy/Synchronization/SyncManager.cs
index 0559932..2ccc906 100644
--- a/Tomboy/Synchronization/SyncManager.cs
+++ b/Tomboy/Synchronization/SyncManager.cs
@@ -195,6 +195,38 @@ namespace Tomboy.Sync
// Update sync item based on configuration.
UpdateSyncAction ();
+
+ // TODO: Prefs, etc
+ // TODO: No need to do this on main loop
+ GLib.Timeout.Add (5000, BackgroundSyncChecker);
+ }
+
+ static bool BackgroundSyncChecker ()
+ {
+ // TODO: Exit if syncing, block sync while checking
+ var addin = GetConfiguredSyncService ();
+ if (addin != null) {
+ var server = addin.CreateSyncServer ();
+ bool clientHasUpdates = false;
+ bool serverHasUpdates = false;
+ foreach (Note note in new List<Note> (NoteMgr.Notes)) {
+ if (client.GetRevision (note) == -1 ||
+ note.MetadataChangeDate > client.LastSyncDate) {
+ clientHasUpdates = true;
+ break;
+ }
+ }
+ // Wasteful to check when we'll sync anyway
+ // TODO: Unless we want to show a bubble when server has updates for users that don't autosync
+ if (!clientHasUpdates)
+ serverHasUpdates = server.UpdatesAvailableSince (client.LastSynchronizedRevision);
+ addin.PostSyncCleanup (); // Let FUSE unmount, etc
+
+ if (clientHasUpdates || serverHasUpdates)
+ ; // TODO: Sync!
+ }
+
+ return true;
}
static void Preferences_SettingChanged (object sender, EventArgs args)
@@ -851,6 +883,7 @@ namespace Tomboy.Sync
int LatestRevision { get; } // NOTE: Only reliable during a transaction
SyncLockInfo CurrentSyncLock { get; }
string Id { get; }
+ bool UpdatesAvailableSince (int revision);
}
public interface SyncClient
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]