Exemplo n.º 1
0
        public object Put(PutNotesRequest request)
        {
            try {
                using (var note_repo = GetNotes (request.Username)) {

                    // constraint taken from snowy source code at http://git.gnome.org/browse/snowy/tree/api/handlers.py:143
                    var new_sync_rev = note_repo.Manifest.LastSyncRevision + 1;

                    // TODO LatestSyncRevision is not correctly SERIALIZED
                    Logger.DebugFormat ("client sent LatestSyncRevision: {0}", request.LatestSyncRevision);

                    // TODO sanitize LatestSyncRevision sent by client - we don't need it to update notes
                    // but a wrong LatestSyncRevision may be an indicator for a bug in the client

                    //if (new_sync_rev != note_repo.Manifest.LatestSyncRevision + 1)
                    //	throw new Exception ("Sync revisions differ by more than one, sth went wrong");

                    foreach (var dto_note in request.Notes) {
                        // map from the DTO
                        var note = dto_note.ToTomboyNote ();

                        if (dto_note.Command == "delete") {
                            note_repo.Engine.DeleteNote (note);
                        } else {
                            // track the revision of the note
                            note_repo.Manifest.NoteRevisions [dto_note.Guid] = (int)new_sync_rev;
                            note_repo.Engine.SaveNote (note, false);
                        }
                    }

                    // only update the sync revision if changes were sent
                    if (request.Notes.Count > 0)
                        note_repo.Manifest.LastSyncRevision = new_sync_rev;

                    var notes_to_return = NotesService.GetStoredNotes (note_repo);
                    notes_to_return.LatestSyncRevision = new_sync_rev;
                    return notes_to_return;
                }
            } catch (Exception e) {
                // log the error and rethrow
                Logger.DebugFormat ("CAUGHT EXCEPTION: {0} {1}", e.Message, e.StackTrace);
                throw e;
            }
        }
Exemplo n.º 2
0
        public void UploadNotes(IList<Note> notes)
        {
            var restClient = GetJsonClient ();

            var request = new PutNotesRequest ();
            //request.LatestSyncRevision = this.LatestRevision;
            request.Notes = notes.ToDTONotes ();

            restClient.Put<GetNotesResponse> (notesServiceUrl, request);

            // TODO if conflicts arise, this may be different
            UploadedNotes = notes;
        }
Exemplo n.º 3
0
        public void DeleteNotes(IList<string> delete_note_guids)
        {
            var restClient = GetJsonClient ();

            // to delete notes, we call PutNotes and set the command to 'delete'
            var request = new PutNotesRequest ();

            request.LatestSyncRevision = (int) this.LatestRevision;

            request.Notes = new List<DTONote> ();
            foreach (string delete_guid in delete_note_guids) {
                request.Notes.Add (new DTONote () {
                    Guid = delete_guid,
                    Command = "delete"
                });
                DeletedServerNotes.Add (delete_guid);
            }

            restClient.Put<PutNotesRequest> (notesServiceUrl, request);
            //			restClient.Put<PutNotesRequest> ("http://127.0.0.1:8090/johndoe/notes/", request);
        }
Exemplo n.º 4
0
 public object Post(PutNotesRequest request)
 {
     return Put (request);
 }
Exemplo n.º 5
0
        public object Put(PutNotesRequest request)
        {
            try {
                // check if we need to include the note body
                bool notes_as_html = false;
                string as_html = Request.GetParam ("notes_as_html");
                if (!string.IsNullOrEmpty (as_html) && !bool.TryParse (as_html, out notes_as_html))
                    throw new InvalidRequestDtoException () {ErrorMessage = "unable to parse parameter notes_as_html to boolean"};

                using (var note_repo = GetNotes ()) {

                    // constraint taken from snowy source code at http://git.gnome.org/browse/snowy/tree/api/handlers.py:143
                    var new_sync_rev = note_repo.Manifest.LastSyncRevision + 1;

                    // TODO LatestSyncRevision is not correctly SERIALIZED
                    Logger.DebugFormat ("client sent LatestSyncRevision: {0}", request.LatestSyncRevision);

                    // TODO sanitize LatestSyncRevision sent by client - we don't need it to update notes
                    // but a wrong LatestSyncRevision may be an indicator for a bug in the client

                    bool notes_were_deleted_or_uploaded = false;

                    foreach (var dto_note in request.Notes) {
                        notes_were_deleted_or_uploaded = true;
                        // map from the DTO
                        if (notes_as_html) {
                            dto_note.Text = dto_note.Text.ToTomboyXml ();
                        }

                        var note = dto_note.ToTomboyNote ();

                        if (dto_note.Command == "delete") {
                            note_repo.Engine.DeleteNote (note);
                        } else {
                            // track the revision of the note
                            note_repo.Manifest.NoteRevisions [dto_note.Guid] = (int)new_sync_rev;
                            note_repo.Engine.SaveNote (note, false);
                        }
                    }
                    var notes_to_return = NotesService.GetStoredNotes (note_repo);

                    if (notes_were_deleted_or_uploaded) {
                        note_repo.Manifest.LastSyncRevision = new_sync_rev;
                        note_repo.Manifest.LastSyncDate = DateTime.UtcNow;
                        notes_to_return.LatestSyncRevision = new_sync_rev;
                    }
                    return notes_to_return;
                }
            } catch (Exception e) {
                // log the error and rethrow
                Logger.DebugFormat ("CAUGHT EXCEPTION: {0} {1}", e.Message, e.StackTrace);
                throw e;
            }
        }