private string CreateNoteChangesJsonString(IList <NoteInfo> noteUpdates, int?expectedNewRevision) { Hyena.Json.JsonObject noteChangesObj = new Hyena.Json.JsonObject(); Hyena.Json.JsonArray noteChangesArray = new Hyena.Json.JsonArray(); foreach (NoteInfo note in noteUpdates) { noteChangesArray.Add(note.ToUpdateObject()); } noteChangesObj [NoteChangesElementName] = noteChangesArray; if (expectedNewRevision != null) { noteChangesObj [LatestSyncRevisionElementName] = expectedNewRevision; } // TODO: Handle errors Hyena.Json.Serializer serializer = new Hyena.Json.Serializer(noteChangesObj); // TODO: Log this for debugging? return(serializer.Serialize()); }
public Hyena.Json.JsonObject ToUpdateObject() { Hyena.Json.JsonObject noteUpdateObj = new Hyena.Json.JsonObject(); if (string.IsNullOrEmpty(Guid)) { throw new InvalidOperationException("Cannot create a valid JSON representation without a Guid"); } noteUpdateObj [GuidElementName] = Guid; if (!string.IsNullOrEmpty(Command)) { noteUpdateObj [CommandElementName] = Command; return(noteUpdateObj); } if (Title != null) { noteUpdateObj [TitleElementName] = Title; } if (NoteContent != null) { noteUpdateObj [NoteContentElementName] = NoteContent; } if (NoteContentVersion.HasValue) { noteUpdateObj [NoteContentVersionElementName] = NoteContentVersion.Value; } if (LastChangeDate.HasValue) { noteUpdateObj [LastChangeDateElementName] = LastChangeDate.Value.ToString(NoteArchiver.DATE_TIME_FORMAT); } if (LastMetadataChangeDate.HasValue) { noteUpdateObj [LastMetadataChangeDateElementName] = LastMetadataChangeDate.Value.ToString(NoteArchiver.DATE_TIME_FORMAT); } if (CreateDate.HasValue) { noteUpdateObj [CreateDateElementName] = CreateDate.Value.ToString(NoteArchiver.DATE_TIME_FORMAT); } // TODO: Figure out what we do on client side for this // if (LastSyncRevision.HasValue) // noteUpdateObj [LastSyncRevisionElementName] = LastSyncRevision; if (OpenOnStartup.HasValue) { noteUpdateObj [OpenOnStartupElementName] = OpenOnStartup.Value; } if (Pinned.HasValue) { noteUpdateObj [PinnedElementName] = Pinned.Value; } if (Tags != null) { Hyena.Json.JsonArray tagArray = new Hyena.Json.JsonArray(); foreach (string tag in Tags) { tagArray.Add(tag); } noteUpdateObj [TagsElementName] = tagArray; } return(noteUpdateObj); }
private string CreateNoteChangesJsonString (IList<NoteInfo> noteUpdates, int? expectedNewRevision) { Hyena.Json.JsonObject noteChangesObj = new Hyena.Json.JsonObject (); Hyena.Json.JsonArray noteChangesArray = new Hyena.Json.JsonArray (); foreach (NoteInfo note in noteUpdates) noteChangesArray.Add (note.ToUpdateObject ()); noteChangesObj [NoteChangesElementName] = noteChangesArray; if (expectedNewRevision != null) noteChangesObj [LatestSyncRevisionElementName] = expectedNewRevision; // TODO: Handle errors Hyena.Json.Serializer serializer = new Hyena.Json.Serializer (noteChangesObj); // TODO: Log this for debugging? return serializer.Serialize (); }
public Hyena.Json.JsonObject ToUpdateObject () { Hyena.Json.JsonObject noteUpdateObj = new Hyena.Json.JsonObject (); if (string.IsNullOrEmpty (Guid)) throw new InvalidOperationException ("Cannot create a valid JSON representation without a Guid"); noteUpdateObj [GuidElementName] = Guid; if (!string.IsNullOrEmpty (Command)) { noteUpdateObj [CommandElementName] = Command; return noteUpdateObj; } if (Title != null) noteUpdateObj [TitleElementName] = Title; if (NoteContent != null) noteUpdateObj [NoteContentElementName] = NoteContent; if (NoteContentVersion.HasValue) noteUpdateObj [NoteContentVersionElementName] = NoteContentVersion.Value; if (LastChangeDate.HasValue) noteUpdateObj [LastChangeDateElementName] = LastChangeDate.Value.ToString (NoteArchiver.DATE_TIME_FORMAT); if (LastMetadataChangeDate.HasValue) noteUpdateObj [LastMetadataChangeDateElementName] = LastMetadataChangeDate.Value.ToString (NoteArchiver.DATE_TIME_FORMAT); if (CreateDate.HasValue) noteUpdateObj [CreateDateElementName] = CreateDate.Value.ToString (NoteArchiver.DATE_TIME_FORMAT); // TODO: Figure out what we do on client side for this // if (LastSyncRevision.HasValue) // noteUpdateObj [LastSyncRevisionElementName] = LastSyncRevision; if (OpenOnStartup.HasValue) noteUpdateObj [OpenOnStartupElementName] = OpenOnStartup.Value; if (Pinned.HasValue) noteUpdateObj [PinnedElementName] = Pinned.Value; if (Tags != null) { Hyena.Json.JsonArray tagArray = new Hyena.Json.JsonArray (); foreach (string tag in Tags) tagArray.Add (tag); noteUpdateObj [TagsElementName] = tagArray; } return noteUpdateObj; }