Esempio n. 1
0
        private static SimpleNote GetNoteFromQuery(APIResultNoteData r, ISimpleJsonRest c, string id, SimpleNoteConfig cfg, SimpleNoteConnection conn)
        {
            try
            {
                var n = new SimpleNote(id, cfg, conn.HConfig);
                using (n.SuppressDirtyChanges())
                {
                    n.Deleted          = r.deleted;
                    n.ShareURL         = r.shareURL;
                    n.PublicURL        = r.publishURL;
                    n.SystemTags       = r.systemTags;
                    n.Content          = r.content;
                    n.ModificationDate = ConvertFromEpochDate(r.modificationDate);
                    n.CreationDate     = ConvertFromEpochDate(r.creationDate);
                    n.LocalVersion     = int.Parse(c.GetResponseHeader("X-Simperium-Version"));
                    n.Tags.Synchronize(r.tags);
                };

                return(n);
            }
            catch (RestException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new SimpleNoteAPIException("SimpleNote API returned unexpected note data", e);
            }
        }
Esempio n. 2
0
        public static SimpleNote UploadNewNote(ISimpleJsonRest web, SimpleNote note, SimpleNoteConfig cfg, SimpleNoteConnection conn)
        {
            note.Deleted          = false;
            note.CreationDate     = DateTimeOffset.Now;
            note.ModificationDate = DateTimeOffset.Now;

            APIResultNoteData data = new APIResultNoteData
            {
                tags             = note.Tags.ToList(),
                deleted          = false,
                shareURL         = note.ShareURL,
                publishURL       = note.PublicURL,
                systemTags       = note.SystemTags,
                content          = note.Content,
                creationDate     = ConvertToEpochDate(note.CreationDate),
                modificationDate = ConvertToEpochDate(note.ModificationDate),
            };

            try
            {
                var r = web.PostTwoWay <APIResultNoteData>(data, "note/i/" + note.ID, "response=1");

                return(GetNoteFromQuery(r, web, note.ID, cfg, conn));
            }
            catch (RestStatuscodeException e1)
            {
                if (e1.StatusCode == 400 && !string.IsNullOrWhiteSpace(e1.HTTPContent))
                {
                    var req = web.ParseJsonOrNull <APIBadRequest>(e1.HTTPContent);
                    if (req != null)
                    {
                        throw new SimpleNoteAPIException($"Server returned status 400.\nField: '{req.field}'.\nMessage: '{req.message}'", e1);
                    }
                }

                throw;
            }
        }