public new void ClientSyncsToNewServer()
        {
            base.ClientSyncsToNewServer ();

            // now switch the client to a new, empty server
            ClearServer (reset: true);

            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            // three notes should have been uploaded
            Assert.AreEqual (3, syncServer.UploadedNotes.Count);

            // zero notes should have been deleted from Server
            Assert.AreEqual (0, syncServer.DeletedServerNotes.Count);

            // zero notes should have been deleted from client
            Assert.AreEqual (0, syncClientOne.DeletedNotes.Count);

            // make sure the client and the server notes are equal
            var local_notes = clientEngineOne.GetNotes ();
            var server_notes = serverEngine.GetNotes ();
            foreach (var kvp in local_notes) {
                Assert.Contains (kvp.Key, server_notes.Keys);
            }

            // after the sync the client should carry the associated ServerId
            // from the new server
            Assert.That (!string.IsNullOrEmpty (syncClientOne.AssociatedServerId));
            Assert.AreEqual (syncClientOne.AssociatedServerId, syncServer.Id);

            Assert.AreEqual (clientManifestOne.ServerId, serverManifest.ServerId);
        }
        public void ClientDeletesNotesAfterFirstSync()
        {
            // perform initial sync
            FirstSyncForBothSidesTest ();

            Assert.AreEqual (3, clientEngineOne.GetNotes ().Count);

            // now, lets delete a note from the client
            var deleted_note = clientEngineOne.GetNotes ().First ().Value;
            clientEngineOne.DeleteNote (deleted_note);
            clientManifestOne.NoteDeletions.Add (deleted_note.Guid, deleted_note.Title);

            // perform a sync again
            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            // one note should have been deleted on server
            Assert.AreEqual (1, syncServer.DeletedServerNotes.Count);
            Assert.AreEqual (deleted_note.Guid, syncServer.DeletedServerNotes.First ());

            // zero notes were deleted on the client
            Assert.AreEqual (0, syncClientOne.DeletedNotes.Count);

            //  server now holds a total of two notes
            Assert.AreEqual (2, syncServer.GetAllNotes (true).Count);

            // all notes on the client and the server should be equal
            var client_notes = clientEngineOne.GetNotes ().Values;
            var server_notes = syncServer.GetAllNotes (true);
            var intersection = client_notes.Intersect (server_notes);
            Assert.AreEqual (2, intersection.Count ());
        }
Exemple #3
0
        public override void SetUp()
        {
            base.SetUp();
            DTOUser           user;
            List <DTONote>    sample_notes;
            JsonServiceClient client = GetAdminServiceClient();

            user = new DTOUser()
            {
                Username       = "******",
                Password       = "******",
                AdditionalData = "Its just john"
            };
            var user_url = new Rainy.WebService.Management.UserRequest().ToUrl("POST");

            client.Post <DTOUser> (user_url, user);
            sampleUser.Add(user);

            // add sample notes
            sample_notes = AbstractSyncServerTests.GetSomeSampleNotes()
                           .Select(n => n.ToDTONote()).ToList();

            var syncServer = new WebSyncServer(testServer.RainyListenUrl, testServer.GetAccessToken());

            var storage = new DiskStorage();
            var tmpPath = "/tmp/sync1";

            storage.SetPath(tmpPath);
            var engine     = new Engine(storage);
            var syncClient = new FilesystemSyncClient(engine, new SyncManifest());

            var syncManager = new Tomboy.Sync.SyncManager(syncClient, syncServer);

            syncManager.DoSync();

            sampleNotes[user.Username] = sample_notes;


            user = new DTOUser()
            {
                Username       = "******",
                Password       = "******",
                AdditionalData = "Jane, Johns wife"
            };
            client.Post <DTOUser> (user_url, user);
            sampleUser.Add(user);
            sampleNotes[user.Username] = AbstractSyncServerTests.GetSomeSampleNotes()
                                         .Select(n => n.ToDTONote()).ToList();

            // add sample user data
        }
Exemple #4
0
        public override void SetUp()
        {
            base.SetUp ();
            DTOUser user;
            List<DTONote> sample_notes;
            JsonServiceClient client = GetAdminServiceClient ();

            user = new DTOUser() {
                Username = "******",
                Password = "******",
                AdditionalData = "Its just john"
            };
            var user_url = new Rainy.WebService.Management.UserRequest ().ToUrl("POST");
            client.Post<DTOUser> (user_url, user);
            sampleUser.Add (user);

            // add sample notes
            sample_notes = AbstractSyncServerTests.GetSomeSampleNotes ()
                .Select (n => n.ToDTONote ()).ToList ();

            var syncServer = new WebSyncServer (testServer.RainyListenUrl, testServer.GetAccessToken ());

            var storage = new DiskStorage ();
            var tmpPath = "/tmp/sync1";
            storage.SetPath (tmpPath);
            var engine = new Engine (storage);
            var syncClient = new FilesystemSyncClient (engine, new SyncManifest ());

            var syncManager = new Tomboy.Sync.SyncManager (syncClient, syncServer);
            syncManager.DoSync ();

            sampleNotes[user.Username] = sample_notes;

            user = new DTOUser() {
                Username = "******",
                Password = "******",
                AdditionalData = "Jane, Johns wife"
            };
            client.Post<DTOUser> (user_url, user);
            sampleUser.Add (user);
            sampleNotes[user.Username] = AbstractSyncServerTests.GetSomeSampleNotes ()
                .Select (n => n.ToDTONote ()).ToList ();

            // add sample user data
        }
Exemple #5
0
        public void DeletedNoteShowsUpInNoteArchive()
        {
            FirstSyncForBothSides ();

            // now, lets delete a note from the client
            var deleted_note = clientEngineOne.GetNotes ().First ().Value;
            clientEngineOne.DeleteNote (deleted_note);
            clientManifestOne.NoteDeletions.Add (deleted_note.Guid, deleted_note.Title);

            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            var client = testServer.GetJsonClient ();
            var url = testServer.ListenUrl + new GetNoteArchiveRequest (){ Username = RainyTestServer.TEST_USER }.ToUrl ("GET");
            var resp = client.Get<NoteArchiveResponse> (url);

            Assert.That (resp.Guids.Contains (deleted_note.Guid));
        }
Exemple #6
0
        public void NoteArchiveContainsAllGuids()
        {
            FirstSyncForBothSides ();

            // now, lets delete a note from the client
            var first_note = clientEngineOne.GetNotes ().First ().Value;
            first_note.Title = "different";
            clientEngineOne.SaveNote (first_note);

            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            var client = testServer.GetJsonClient ();
            var url = testServer.ListenUrl + new GetNoteArchiveRequest (){ Username = RainyTestServer.TEST_USER }.ToUrl ("GET");
            var resp = client.Get<NoteArchiveResponse> (url);

            Assert.That (resp.Guids.Contains (first_note.Guid));
            Assert.AreEqual (1, resp.Guids.Count ());
        }
Exemple #7
0
        protected override void OnRealized()
        {
            base.OnRealized();

            SyncState state = SyncManager.State;

            if (state == SyncState.Idle)
            {
                // Kick off a timer to keep the progress bar going
                progressBarTimeoutId = GLib.Timeout.Add(500, OnPulseProgressBar);

                // Kick off a new synchronization
                SyncManager.PerformSynchronization(this);
            }
            else
            {
                // Adjust the GUI accordingly
                SyncStateChanged(state);
            }
        }
		/// <summary>
		/// Syncs the notes.
		/// </summary>
		/// <param name="sender">Sender.</param>
		partial void SyncNotes(NSObject sender) {
			var dest_manifest_path = Path.Combine (settings.syncURL, "manifest.xml");
			SyncManifest dest_manifest;
			if (!File.Exists (dest_manifest_path)) {
				using (var output = new FileStream (dest_manifest_path, FileMode.Create)) {
					SyncManifest.Write (new SyncManifest (), output);
				}
			}
			using (var input = new FileStream (dest_manifest_path, FileMode.Open)) {
				dest_manifest = SyncManifest.Read (input);
			}
			var dest_storage = new DiskStorage (settings.syncURL);
			var dest_engine = new Engine (dest_storage);

			var client = new FilesystemSyncClient (NoteEngine, manifestTracker.Manifest);
			var server = new FilesystemSyncServer (dest_engine, dest_manifest);
			var sync_manager = new SyncManager(client, server);
			sync_manager.DoSync ();
			RefreshNotesWindowController();
			// write back the dest manifest
		        using (var output = new FileStream (dest_manifest_path, FileMode.Create)) {
				SyncManifest.Write (dest_manifest, output);
			}

        	}
Exemple #9
0
        public void NoteConflictDetected(NoteManager manager,
                                         Note localConflictNote,
                                         NoteUpdate remoteNote,
                                         IList <string> noteUpdateTitles)
        {
            SyncTitleConflictResolution savedBehavior = SyncTitleConflictResolution.Cancel;
            object dlgBehaviorPref = Preferences.Get(Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR);

            if (dlgBehaviorPref != null && dlgBehaviorPref is int)             // TODO: Check range of this int
            {
                savedBehavior = (SyncTitleConflictResolution)dlgBehaviorPref;
            }

            SyncTitleConflictResolution resolution = SyncTitleConflictResolution.OverwriteExisting;
            // This event handler will be called by the synchronization thread
            // so we have to use the delegate here to manipulate the GUI.
            // To be consistent, any exceptions in the delgate will be caught
            // and then rethrown in the synchronization thread.
            Exception mainThreadException = null;

            Gtk.Application.Invoke(delegate {
                try {
                    SyncTitleConflictDialog conflictDlg =
                        new SyncTitleConflictDialog(localConflictNote, noteUpdateTitles);
                    Gtk.ResponseType reponse = Gtk.ResponseType.Ok;

                    bool noteSyncBitsMatch =
                        SyncManager.SynchronizedNoteXmlMatches(localConflictNote.GetCompleteNoteXml(),
                                                               remoteNote.XmlContent);

                    // If the synchronized note content is in conflict
                    // and there is no saved conflict handling behavior, show the dialog
                    if (!noteSyncBitsMatch && savedBehavior == 0)
                    {
                        reponse = (Gtk.ResponseType)conflictDlg.Run();
                    }


                    if (reponse == Gtk.ResponseType.Cancel)
                    {
                        resolution = SyncTitleConflictResolution.Cancel;
                    }
                    else
                    {
                        if (noteSyncBitsMatch)
                        {
                            resolution = SyncTitleConflictResolution.OverwriteExisting;
                        }
                        else if (savedBehavior == 0)
                        {
                            resolution = conflictDlg.Resolution;
                        }
                        else
                        {
                            resolution = savedBehavior;
                        }

                        switch (resolution)
                        {
                        case SyncTitleConflictResolution.OverwriteExisting:
                            if (conflictDlg.AlwaysPerformThisAction)
                            {
                                savedBehavior = resolution;
                            }
                            // No need to delete if sync will overwrite
                            if (localConflictNote.Id != remoteNote.UUID)
                            {
                                manager.Delete(localConflictNote);
                            }
                            break;

                        case SyncTitleConflictResolution.RenameExistingAndUpdate:
                            if (conflictDlg.AlwaysPerformThisAction)
                            {
                                savedBehavior = resolution;
                            }
                            RenameNote(localConflictNote, conflictDlg.RenamedTitle, true);
                            break;

                        case SyncTitleConflictResolution.RenameExistingNoUpdate:
                            if (conflictDlg.AlwaysPerformThisAction)
                            {
                                savedBehavior = resolution;
                            }
                            RenameNote(localConflictNote, conflictDlg.RenamedTitle, false);
                            break;
                        }
                    }

                    Preferences.Set(Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR,
                                    (int)savedBehavior);                       // TODO: Clean up

                    conflictDlg.Hide();
                    conflictDlg.Destroy();

                    // Let the SyncManager continue
                    SyncManager.ResolveConflict(/*localConflictNote, */ resolution);
                } catch (Exception e) {
                    mainThreadException = e;
                }
            });
            if (mainThreadException != null)
            {
                throw mainThreadException;
            }
        }
        public void ClientSyncsMultipleTimes()
        {
            // perform initial sync
            FirstSyncForBothSidesTest ();

            foreach (var note in clientStorageOne.GetNotes ().Values) {
                note.Title = "New title";
                clientEngineOne.SaveNote (note);
            }

            // perform a sync again
            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            foreach (var note in clientStorageOne.GetNotes ().Values) {
                note.Title = "New title two";
                clientEngineOne.SaveNote (note);
            }

            return;

            // perform a sync again
            sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            foreach (var note in clientStorageOne.GetNotes ().Values) {
                note.Title = "New title three";
                clientEngineOne.SaveNote (note);
            }
        }
 protected void FirstSyncForBothSides()
 {
     SyncManager sync_manager = new SyncManager (this.syncClientOne, this.syncServer);
     sync_manager.DoSync ();
 }
        public void NoSyncingNeededIfNoChangesAreMade()
        {
            FirstSyncForBothSidesTest ();

            var server_id = syncClientOne.AssociatedServerId;

            // new instance of the server needed (to simulate a new connection)
            ClearServer (reset: false);

            // now that we are synced, there should not happen anything when syncing again
            SyncManager sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            // the association id should not have changed
            Assert.AreEqual (server_id, syncClientOne.AssociatedServerId);
            Assert.AreEqual (server_id, syncServer.Id);

            // no notes should have been transfered or deleted
            Assert.AreEqual (0, syncServer.UploadedNotes.Count);
            Assert.AreEqual (0, syncServer.DeletedServerNotes.Count);
        }
        public void FirstSyncForBothSidesTest()
        {
            // before the sync, the client should have an empty AssociatedServerId
            Assert.That (string.IsNullOrEmpty (syncClientOne.AssociatedServerId));

            SyncManager sync_manager = new SyncManager (this.syncClientOne, this.syncServer);
            sync_manager.DoSync ();

            // after the sync the client should carry the associated ServerId
            Assert.That (!string.IsNullOrEmpty (syncClientOne.AssociatedServerId));
            Assert.AreEqual (syncClientOne.AssociatedServerId, syncServer.Id);

            // both revisions should be 0
            Assert.AreEqual (0, syncClientOne.LastSynchronizedRevision);
            Assert.AreEqual (0, syncServer.LatestRevision);

            Assert.Greater (syncServer.UploadedNotes.Count, 0);

            ClearClientOne (reset: false);
            ClearClientTwo (reset: false);

            Assert.Greater (syncServer.UploadedNotes.Count, 0);
        }
Exemple #14
0
        public void NoteArchiveDoesHonorTheIncludeTextParameter()
        {
            FirstSyncForBothSides ();

            Tomboy.Note first_note = clientEngineOne.GetNotes ().Values.First ();
            first_note.Title = "different";
            clientEngineOne.SaveNote (first_note);

            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            var client = testServer.GetJsonClient ();
            var url = GetNoteHistoryUrl (first_note.Guid);
            var resp = client.Get<NoteHistoryResponse> (url + "?include_text=false");

            foreach (var archived_note in resp.Versions) {
                Assert.AreEqual ("", archived_note.Note.Text);
            }

            resp = client.Get<NoteHistoryResponse> (url + "?include_text=true");
            foreach (var archived_note in resp.Versions) {
                Assert.AreNotEqual ("", archived_note.Note.Text);
            }
        }
Exemple #15
0
        public void RetrieveAnArchivedVersionOfANote()
        {
            FirstSyncForBothSides ();

            Tomboy.Note first_note = clientEngineOne.GetNotes ().Values.First ();
            DTONote first_note_dto = first_note.ToDTONote ();

            var new_title = "Some other title";
            var old_title = first_note_dto.Title;
            var new_text = "Some new text";
            var old_text = first_note_dto.Text;

            first_note.Title = new_title;
            first_note.Text = new_text;

            clientEngineOne.SaveNote (first_note);

            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            var client = testServer.GetJsonClient ();
            var url = GetNoteHistoryUrl (first_note.Guid);
            var resp = client.Get<NoteHistoryResponse> (url);

            var rev = resp.Versions[0].Revision;

            url = GetArchivedNoteUrl (first_note.Guid, rev);
            var note = client.Get<DTONote> (url);

            Assert.AreEqual (old_text, note.Text);
            Assert.AreEqual (old_title, note.Title);
            Assert.AreEqual (first_note_dto.Tags, note.Tags);
        }
Exemple #16
0
        public void NoteHistoryIsPresentWithOneNoteAfterChange()
        {
            FirstSyncForBothSides ();

            var first_note = clientEngineOne.GetNotes ().Values.First ();
            var new_title = "Some other title";
            var old_title = first_note.Title;
            first_note.Title = new_title;
            clientEngineOne.SaveNote (first_note);

            var sync_manager = new SyncManager (syncClientOne, syncServer);
            sync_manager.DoSync ();

            var client = testServer.GetJsonClient ();
            var url = GetNoteHistoryUrl (first_note.Guid);
            var resp = client.Get<NoteHistoryResponse> (url);

            Assert.AreEqual (1, resp.Versions.Length);
            Assert.AreEqual (1, resp.Versions[0].Revision);
            Assert.AreEqual (old_title, resp.Versions[0].Note.Title);
        }