public override RemoteDownloadResult UpdateNoteFromRemote(INote inote)
        {
            using (var web = CreateAuthenticatedClient())
            {
                var note = (NextcloudNote)inote;

                var remote = remoteNotes.FirstOrDefault(p => p.id == note.RemoteID);

                if (remote == null)
                {
                    return(RemoteDownloadResult.DeletedOnRemote);
                }

                if (remote.modified == note.RemoteTimestamp)
                {
                    return(RemoteDownloadResult.UpToDate);
                }

                var unote = NextcloudAPI.GetNoteData(web, note.RemoteID, _config);

                inote.ApplyUpdatedData(unote);

                return(RemoteDownloadResult.Updated);
            }
        }
 public override INote DownloadNote(string id, out bool success)
 {
     using (var web = CreateAuthenticatedClient())
     {
         var d = NextcloudAPI.GetNoteData(web, int.Parse(id), _config);
         success = true;
         return(d);
     }
 }
        public override void StartSync(IRemoteStorageSyncPersistance data, List <INote> localnotes, List <INote> localdeletednotes)
        {
            _data = (NextcloudData)data;

            using (var web = CreateAuthenticatedClient())
            {
                remoteNotes = NextcloudAPI.ListNotes(web);

                _logger.Debug(NextcloudPlugin.Name, string.Format("NextcloudAPI.ListNotes returned {0} elements", remoteNotes.Count));
            }
        }
        public override RemoteUploadResult UploadNoteToRemote(ref INote inote, out INote conflict, out bool keepNoteRemoteDirtyWithConflict, ConflictResolutionStrategy strategy)
        {
            keepNoteRemoteDirtyWithConflict = false;

            using (var web = CreateAuthenticatedClient())
            {
                var note = (NextcloudNote)inote;

                var remote = remoteNotes.FirstOrDefault(p => p.id == note.RemoteID);

                if (remote == null)
                {
                    conflict = null;
                    inote    = NextcloudAPI.UploadNewNote(web, note, _config);
                    return(RemoteUploadResult.Uploaded);
                }
                else
                {
                    if (remote.modified > note.RemoteTimestamp)
                    {
                        if (strategy == ConflictResolutionStrategy.UseClientVersion || strategy == ConflictResolutionStrategy.UseClientCreateConflictFile || strategy == ConflictResolutionStrategy.ManualMerge)
                        {
                            conflict = NextcloudAPI.GetNoteData(web, note.RemoteID, _config);
                            inote    = NextcloudAPI.ChangeExistingNote(web, note, _config);
                            return(RemoteUploadResult.Conflict);
                        }
                        else if (strategy == ConflictResolutionStrategy.UseServerVersion || strategy == ConflictResolutionStrategy.UseServerCreateConflictFile)
                        {
                            conflict = inote.Clone();
                            inote    = NextcloudAPI.GetNoteData(web, note.RemoteID, _config);
                            return(RemoteUploadResult.Conflict);
                        }
                        else
                        {
                            throw new ArgumentException("strategy == " + strategy);
                        }
                    }
                    else
                    {
                        conflict = null;
                        inote    = NextcloudAPI.ChangeExistingNote(web, note, _config);
                        return(RemoteUploadResult.Uploaded);
                    }
                }
            }
        }
        public override void DeleteNote(INote inote)
        {
            using (var web = CreateAuthenticatedClient())
            {
                var note = (NextcloudNote)inote;

                if (note.IsConflictNote)
                {
                    return;
                }

                var remote = remoteNotes.FirstOrDefault(p => p.id == note.RemoteID);

                if (remote != null)
                {
                    NextcloudAPI.DeleteNote(web, note);
                }
            }
        }