示例#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);
            }
        }
示例#2
0
        public static void DeleteNote(ISimpleJsonRest web, SimpleNote note)
        {
            if (note.ID == "")
            {
                throw new SimpleNoteAPIException("Cannot delete a not uploaded note");
            }
            note.ModificationDate = DateTimeOffset.Now;

            APIDeleteNoteData data = new APIDeleteNoteData
            {
                deleted = true
            };

            try
            {
                web.PostUpload(data, "note/i/" + note.ID, new[] { 412 });
            }
            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;
            }
        }
示例#3
0
        public static void DeleteNotePermanently(ISimpleJsonRest web, SimpleNote note)
        {
            if (note.ID == "")
            {
                throw new SimpleNoteAPIException("Cannot delete a not uploaded note");
            }

            try
            {
                note.ModificationDate = DateTimeOffset.Now;
                web.DeleteEmpty("note/i/" + note.ID);
            }
            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;
            }
        }
示例#4
0
        public static SimpleNote ChangeExistingNote(ISimpleJsonRest web, SimpleNote note, SimpleNoteConfig cfg, SimpleNoteConnection conn, out bool updated)
        {
            if (note.Deleted)
            {
                throw new SimpleNoteAPIException("Cannot update an already deleted note");
            }
            if (note.ID == "")
            {
                throw new SimpleNoteAPIException("Cannot change a not uploaded note");
            }
            note.ModificationDate = DateTimeOffset.Now;

            APISendNoteData data = new APISendNoteData
            {
                tags             = note.Tags.ToList(),
                content          = note.Content,
                modificationDate = ConvertToEpochDate(note.ModificationDate),
                systemTags       = note.SystemTags.ToList(),
            };

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

                if (r == null)
                {
                    // Statuscode 412 - Empty change

                    updated = false;
                    return((SimpleNote)note.Clone());
                }

                updated = true;
                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;
            }
        }
示例#5
0
        protected override BasicNoteImpl CreateClone()
        {
            var n = new SimpleNote(_id, _config, _hConfig);

            using (n.SuppressDirtyChanges())
            {
                n._tags.Synchronize(_tags.ToList());
                n._content          = _content;
                n._deleted          = _deleted;
                n._shareURL         = _shareURL;
                n._publicURL        = _publicURL;
                n._systemTags       = _systemTags.ToList();
                n._creationDate     = _creationDate;
                n._modificationDate = _modificationDate;
                n._localVersion     = _localVersion;

                return(n);
            }
        }
示例#6
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;
            }
        }