Example #1
0
        public override void StartSync(IRemoteStorageSyncPersistance idata, List <INote> ilocalnotes, List <INote> localdeletednotes)
        {
            StandardNoteAPI.Logger = _logger;

            using (var web = CreateAuthenticatedClient())
            {
                var data = (StandardNoteData)idata;

                var localnotes = ilocalnotes.Cast <StandardFileNote>().ToList();

                var upNotes  = localnotes.Where(NeedsUpload).ToList();
                var delNotes = localdeletednotes.Cast <StandardFileNote>().ToList();
                var delTags  = data.GetUnusedTags(localnotes.ToList());

                _syncResult = StandardNoteAPI.Sync(web, this, _token, _config, data, localnotes, upNotes, delNotes, delTags);

                _logger.Debug(StandardNotePlugin.Name, "StandardFile sync finished.",
                              string.Format("upload:[notes={8} deleted={9}]" + "\r\n" + "download:[note:[retrieved={0} deleted={1} saved={2} conflicts={3} errors={4}] tags:[retrieved={5} saved={6} unsaved={7}]]",
                                            _syncResult.retrieved_notes.Count,
                                            _syncResult.deleted_notes.Count,
                                            _syncResult.saved_notes.Count,
                                            _syncResult.conflict_notes.Count,
                                            _syncResult.error_notes.Count,
                                            _syncResult.retrieved_tags.Count,
                                            _syncResult.saved_tags.Count,
                                            _syncResult.unsaved_tags.Count,
                                            upNotes.Count,
                                            delNotes.Count));
            }
        }
Example #2
0
 public void WriteSyncData(IRemoteStorageSyncPersistance data)
 {
     lock (_lockSaveSyncData)
     {
         WriteSyncData(data, _pathLocalData);
     }
 }
Example #3
0
        private void OnPluginChanged()
        {
            ConfigurationValidated = false;
            ValidationResultData   = null;
            ValidationResultNotes  = null;

            if (SelectedProvider != null)
            {
                Account = new RemoteStorageAccount(Guid.NewGuid(), SelectedProvider, SelectedProvider.CreateEmptyRemoteStorageConfiguration());
            }
            else
            {
                Account = null;
            }

            if (_syncThread != null && _syncThread.IsAlive)
            {
                _syncThread.Abort();
            }
            if (_progressThread != null && _progressThread.IsAlive)
            {
                _progressThread.Abort();
            }

            SyncProgress = 0;
            SyncInfoText = string.Empty;
        }
Example #4
0
        public override void StartSync(IRemoteStorageSyncPersistance data, List <INote> localnotes, List <INote> localdeletednotes)
        {
            _syncScan = FileSystemUtil
                        .EnumerateFilesDeep(_config.Folder, _config.SearchDepth)
                        .Where(p => (Path.GetExtension(p) ?? "").ToLower() == "." + _config.Extension.ToLower())
                        .ToList();

            _logger.Debug(FilesystemPlugin.Name, string.Format("Found {0} note files in directory scan", _syncScan.Count));
        }
Example #5
0
        private void WriteSyncData(IRemoteStorageSyncPersistance data, string pathData)
        {
            var tempPath = Path.GetTempFileName();

            var x = new XDocument(data.Serialize());

            using (var file = File.OpenWrite(tempPath)) x.Save(file);

            File.Copy(tempPath, pathData, true);
            File.Delete(tempPath);
        }
        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));
            }
        }
Example #7
0
        public override void StartSync(IRemoteStorageSyncPersistance data, List <INote> localnotes, List <INote> localdeletednotes)
        {
            _data = (SimpleNoteData)data;

            using (var web = CreateAuthenticatedClient())
            {
                buckets = SimpleNoteAPI.ListBuckets(web);

                _logger.Debug(
                    SimpleNotePlugin.Name,
                    string.Format("SimpleNoteAPI.ListBuckets returned {0} elements", buckets.index.Count),
                    string.Join(Environment.NewLine, buckets.index.Select(b => b.id + " (" + b.v + ")")));
            }
        }
        private bool NeedsUploadReal(StandardFileTagRef tagref, IRemoteStorageSyncPersistance idata)
        {
            var data = (StandardNoteData)idata;

            if (tagref.UUID == null)
            {
                return(true);                                 // contains not-linked tagref
            }
            if (!data.Tags.Any(p => p.UUID == tagref.UUID))
            {
                return(true);                                                        // contains tagref that references missing tag
            }
            return(false);
        }
Example #9
0
        public void ApplyNewAccountData(RemoteStorageAccount acc, IRemoteStorageSyncPersistance data, List <INote> notes)
        {
            var localFolder = Path.Combine(_pathLocalBase, acc.ID.ToString("B"));
            var localData   = Path.Combine(_pathLocalBase, acc.ID.ToString("B") + ".xml");

            if (!Directory.Exists(localFolder))
            {
                _logger.Info("Repository", "Create local note folder: " + localFolder);
                Directory.CreateDirectory(localFolder);
            }

            WriteSyncData(data, localData);

            foreach (var n in notes)
            {
                SaveNote(n, localFolder, false);
            }
        }
Example #10
0
        public void OnAccountChanged()
        {
            ConfigurationValidated = false;
            ValidationResultData   = null;
            ValidationResultNotes  = null;

            if (_syncThread != null && _syncThread.IsAlive)
            {
                _syncThread.Abort();
            }
            if (_progressThread != null && _progressThread.IsAlive)
            {
                _progressThread.Abort();
            }

            SyncProgress = 0;
            SyncInfoText = string.Empty;
        }
        private bool NeedsUploadReal(INote inote, IRemoteStorageSyncPersistance idata)
        {
            var note = (StandardFileNote)inote;

            if (note.IsConflictNote)
            {
                return(false);
            }

            if (!note.IsRemoteSaved)
            {
                return(true);
            }
            if (note.InternalTags.Any(p => NeedsUploadReal(p, idata)))
            {
                return(true);
            }

            return(false);
        }
        public override void StartSync(IRemoteStorageSyncPersistance data, List <INote> localnotes, List <INote> localdeletednotes)
        {
            _data = (EvernoteData)data;

            RefreshToken();

            TTransport noteStoreTransport = new THttpClient(new Uri(@"https://sandbox.evernote.com/shard/s1/notestore"));            //TODO use url from OAuth
            TProtocol  noteStoreProtocol  = new TBinaryProtocol(noteStoreTransport);

            nsClient = new NoteStore.Client(noteStoreProtocol);

            var state = nsClient.getSyncState(_token);

            if (_data.SyncStateUpdateCount != state.UpdateCount)
            {
                _logger.Debug(EvernotePlugin.Name, string.Format("Remote has changed SyncState: {0} -> '{1}'", _data.SyncStateUpdateCount, state.UpdateCount));

                NoteFilter filter = new NoteFilter();
                filter.Order = (int)NoteSortOrder.UPDATED;

                NotesMetadataResultSpec spec = new NotesMetadataResultSpec();
                spec.IncludeUpdateSequenceNum = true;

                bucket = nsClient.findNotesMetadata(_token, filter, 0, 9999, spec);

                _data.SyncStateUpdateCount = state.UpdateCount;
            }
            else
            {
                _logger.Debug(EvernotePlugin.Name, "Remote has not changed - no need for download - SyncState := " + state.UpdateCount);

                bucket = null;
            }

            remoteDirty = false;
        }
Example #13
0
 public override void StartSync(IRemoteStorageSyncPersistance data, List <INote> localnotes, List <INote> localdeletednotes)
 {
     // ok
 }
 public abstract void StartSync(IRemoteStorageSyncPersistance data, List <INote> localnotes, List <INote> localdeletednotes);
Example #15
0
        public void StartSync()
        {
            if (SelectedProvider == null)
            {
                return;
            }
            if (Account == null)
            {
                return;
            }

            if (_syncThread != null && _syncThread.IsAlive)
            {
                _syncThread.Abort();
            }
            if (_progressThread != null && _progressThread.IsAlive)
            {
                _progressThread.Abort();
            }

            SyncInfoText = "Starting Synchronization";
            var acc = new RemoteStorageAccount(Account.ID, Account.Plugin, Account.Config);

            _syncThread = new Thread(() =>
            {
                try
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        IsValidating = true;

                        ConfigurationValidated = false;
                        ValidationResultData   = null;
                        ValidationResultNotes  = null;

                        SyncProgress = 0;
                        SyncInfoText = string.Empty;

                        CanAbort = true;
                    });

                    var r = DoSync(acc, App.Logger);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigurationValidated = true;
                        ValidationResultData   = r.Item1;
                        ValidationResultNotes  = r.Item2;
                        SyncProgress           = r.Item3 == 0 ? -100 : -66;
                        SyncInfoText           = r.Item3 == 0 ? string.Empty : $"({r.Item3}/{r.Item4} notes had download errors)";
                    });
                }
                catch (ThreadAbortException)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigurationValidated = false;
                        ValidationResultData   = null;
                        ValidationResultNotes  = null;
                        SyncProgress           = 0;
                        SyncInfoText           = string.Empty;
                    });
                    return;
                }
                catch (Exception e)
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigurationValidated = false;
                        ValidationResultData   = null;
                        ValidationResultNotes  = null;
                        SyncProgress           = -66;
                        SyncInfoText           = string.Empty;
                    });
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        SyncProgress = -66;
                        SyncErrorDialog.Show(_owner, e);
                    }));
                }
                finally
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        IsValidating = false;
                        SyncInfoText = string.Empty;
                    }));
                }
            });
            _progressThread = new Thread(() =>
            {
                Thread.Sleep(350);
                for (;;)
                {
                    if (!_syncThread.IsAlive)
                    {
                        break;
                    }
                    Thread.Sleep(150);
                    Application.Current.Dispatcher.Invoke(() => { SyncProgress++; });
                }
                Application.Current.Dispatcher.Invoke(() =>
                {
                    if (ConfigurationValidated)
                    {
                        SyncProgress = -100;
                    }
                    else
                    {
                        SyncProgress = -66;
                    }
                    SyncInfoText = string.Empty;
                });
            });

            _syncThread.Start();
            _progressThread.Start();
        }
        public override void StartSync(IRemoteStorageSyncPersistance idata, List <INote> ilocalnotes, List <INote> localdeletednotes)
        {
            StandardNoteAPI.Logger = _logger;

            _immediateResync = false;

            var data = (StandardNoteData)idata;

            try
            {
                using (var web = CreateAuthenticatedClient(data))
                {
                    var localnotes = ilocalnotes.Cast <StandardFileNote>().ToList();

                    var upNotes  = localnotes.Where(p => NeedsUploadReal(p, idata)).ToList();
                    var delNotes = localdeletednotes.Cast <StandardFileNote>().ToList();
                    var delTags  = data.GetUnusedTags(localnotes.ToList());

                    if (int.Parse(data.SessionData.Version) >= 4 && !data.ItemsKeys.Any(p => p.Version == data.SessionData.Version))
                    {
                        _logger.Warn(StandardNotePlugin.Name, "Repository doesn't have any matching items_key's - trying to get one");
                        StandardNoteAPI.SyncToEnsureItemsKeys(web, this, _config, data);
                    }

                    _syncResult      = StandardNoteAPI.Sync(web, this, _config, data, localnotes, upNotes, delNotes, delTags);
                    _lastUploadBatch = upNotes.Select(p => p.ID).ToList();

                    _logger.Debug(StandardNotePlugin.Name, "StandardFile sync finished.",
                                  $"upload:\n" +
                                  $"[\n" +
                                  $"    notes   = {upNotes.Count}\n" +
                                  $"    deleted = {delNotes.Count}\n" +
                                  $"]\n" +
                                  $"\n" +
                                  $"download:\n" +
                                  $"[\n" +
                                  $"    note:\n" +
                                  $"    [\n" +
                                  $"        retrieved      = {_syncResult.retrieved_notes.Count}\n" +
                                  $"        deleted        = {_syncResult.deleted_notes.Count}\n" +
                                  $"        saved          = {_syncResult.saved_notes.Count}\n" +
                                  $"        sync_conflicts = {_syncResult.syncconflict_notes.Count}\n" +
                                  $"        uuid_conflicts = {_syncResult.uuidconflict_notes.Count}\n" +
                                  $"    ]\n" +
                                  $"    tags:\n" +
                                  $"    [\n" +
                                  $"        retrieved      = {_syncResult.retrieved_tags.Count}\n" +
                                  $"        deleted        = {_syncResult.deleted_tags.Count}\n" +
                                  $"        saved          = {_syncResult.saved_tags.Count}\n" +
                                  $"        sync_conflicts = {_syncResult.syncconflict_tags.Count}\n" +
                                  $"        uuid_conflicts = {_syncResult.uuidconflict_tags.Count}\n" +
                                  $"    ]\n" +
                                  $"    items_keys:\n" +
                                  $"    [\n" +
                                  $"        retrieved      = {_syncResult.retrieved_keys.Count}\n" +
                                  $"        deleted        = {_syncResult.deleted_keys.Count}\n" +
                                  $"        saved          = {_syncResult.saved_keys.Count}\n" +
                                  $"        sync_conflicts = {_syncResult.syncconflict_keys.Count}\n" +
                                  $"        uuid_conflicts = {_syncResult.uuidconflict_keys.Count}\n" +
                                  $"    ]\n" +
                                  $"]");
                }
            }
            catch (RestStatuscodeException e)
            {
                if (e.StatusCode == 401)
                {
                    _logger.Warn(StandardNotePlugin.Name,
                                 "Reset Token (401 statuscode)",
                                 $"Exception    := {e.GetType()}\n" +
                                 $"Message      := {e.Message}\n" +
                                 $"Source       := {e.Source}\n" +
                                 $"StatusCode   := {e.StatusCode}\n" +
                                 $"StatusPhrase := {e.StatusPhrase}\n" +
                                 $"StackTrace   := \n{e.StackTrace}\n" +
                                 $"HTTPContent  := \n{e.HTTPContent}\n");

                    data.SessionData = null;
                }

                throw;
            }
        }