private Tuple <IRemoteStorageSyncPersistance, List <INote>, int, int> DoSync(RemoteStorageAccount acc, AlephLogger log) { var data = SelectedProvider.CreateEmptyRemoteSyncData(); var conn = acc.Plugin.CreateRemoteStorageConnection(PluginManagerSingleton.Inst.GetProxyFactory().Build(), acc.Config, new HierarchyEmulationConfig(false, "\\", '\\')); var resultNotes = new ConcurrentQueue <INote>(); var resultErrors = new ConcurrentQueue <string>(); int fullCount; Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Connect to remote"; }); conn.StartSync(data, new List <INote>(), new List <INote>()); { Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "List notes from remote"; }); var missing = conn.ListMissingNotes(new List <INote>()); fullCount = missing.Count; Application.Current.Dispatcher.Invoke(() => { CanAbort = !acc.Plugin.SupportsNewDownloadMultithreading || missing.Count < AppSettings.DEFAULT_INITIALDOWNLOAD_PARALLELISM_THRESHOLD; }); SynchronizationThread.ExecuteInParallel( log, "InitialDownloadNewNotes", acc.Plugin.SupportsNewDownloadMultithreading, missing, AppSettings.DEFAULT_INITIALDOWNLOAD_PARALLELISM_LEVEL, AppSettings.DEFAULT_INITIALDOWNLOAD_PARALLELISM_THRESHOLD, (e, xnoteid) => { resultErrors.Enqueue(xnoteid); return(true); }, xnoteid => { var msg = $"Download Note {resultNotes.Count}/{missing.Count}"; Application.Current.Dispatcher.Invoke(() => { SyncInfoText = msg; }); var note = conn.DownloadNote(xnoteid, out var isnewnote); if (isnewnote) { note.SetLocalDirty("Set Note LocalDirty=true after download in Startupmode"); note.ResetRemoteDirty("Set Note RemoteDirty=false after download in Startupmode"); resultNotes.Enqueue(note); } else { log.Warn("Sync_FirstStart", $"Download new note {{id:'{xnoteid}'}} returned false"); } }); } Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Finish synchronization"; }); conn.FinishSync(out var _); return(Tuple.Create(data, resultNotes.ToList(), resultErrors.Count, fullCount)); }
private Tuple <IRemoteStorageSyncPersistance, List <INote> > DoSync(RemoteStorageAccount acc, AlephLogger log) { var data = SelectedProvider.CreateEmptyRemoteSyncData(); var conn = acc.Plugin.CreateRemoteStorageConnection(PluginManagerSingleton.Inst.GetProxyFactory().Build(), acc.Config, new HierachyEmulationConfig(false, "\\", '\\')); var resultNotes = new List <INote>(); Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Connect to remote"; }); conn.StartSync(data, new List <INote>(), new List <INote>()); { Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "List notes from remote"; }); var missing = conn.ListMissingNotes(new List <INote>()); int idx = 0; foreach (var xnoteid in missing) { var noteid = xnoteid; idx++; try { string msg = $"Download Note {idx}/{missing.Count}"; Application.Current.Dispatcher.Invoke(() => { SyncInfoText = msg; }); var note = conn.DownloadNote(noteid, out var isnewnote); if (isnewnote) { note.SetLocalDirty("Set Note LocalDirty=true after download in Startupmode"); note.ResetRemoteDirty("Set Note RemoteDirty=false after download in Startupmode"); resultNotes.Add(note); } else { log.Warn("Sync_FirstStart", string.Format("Download new note {{id:'{0}'}} returned false", noteid)); } } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new Exception(string.Format("Could not download new note '{0}' on remote cause of {1}", noteid, e.Message)); } } } Application.Current.Dispatcher.Invoke(() => { SyncInfoText = "Finish synchronization"; }); conn.FinishSync(); return(Tuple.Create(data, resultNotes)); }