private async Task PreparingFilesAsync() { syncStateDialog.Label = "Authenticating..."; syncStateDialog.Show(MainPage.UserPrefs.IsReadNightMode); syncInstance.InitInstance(); await syncInstance.AuthenciateAccount(); syncStateDialog.Label = "Preparing files..."; mainPage.Collection.SaveAndCommit(); await syncInstance.InitSyncFolderIfNeeded(); await PrepareForSyncing(); }
public async Task StartSync() { try { SetSyncLabel("Sync collection to AnkiWeb..."); syncStateDialog.Show(); GetHostKeyFromVault(); server = new RemoteServer(hostKey); server.OnHttpProgressEvent += OnServerHttpProgressEvent; client = new AnkiCore.Sync.Syncer(mainPage.Collection, server); var results = await client.Sync(); await WaitForCloseSyncStateDialog(); if (results == null) { await UIHelper.ShowMessageDialog("No respone from the server! Either your connection or the server did not work properly."); return; } else if (results[0] == "badAuth") { //Include for completeness purpose. //We should not run into this, as the app only logins when user changed sync service await UIHelper.ShowMessageDialog("AnkiWeb ID or password was incorrect. Please try to log in again."); return; } else if (results[0] == "clockOff") { await UIHelper.ShowMessageDialog("Syncing requires the clock on your computer to be set correctly. Please fix the clock and try again."); return; } else if (results[0] == "basicCheckFailed" || results[0] == "sanityCheckFailed" || results[0] == "sanityCheckError") { await UIHelper.ShowMessageDialog("Your collection is in an inconsistent state.\n" + "Please run \"Check Collection\" or \"Force Full Sync\", then try again."); return; } else if (results[0] == "fullSync") { await ConfirmAndStartFullSync(); MainPage.UserPrefs.IsFullSyncRequire = false; await ShowAnkiWebReturnMessageIfHas(results); return; } else if (results[0] == "noChanges" || results[0] == "success") { SetSyncLabel("Finished."); syncStateDialog.Show(); if (results[0] == "success") { await NavigateToDeckSelectPage(); } else { await Task.Delay(250); } MainPage.UserPrefs.IsFullSyncRequire = false; await WaitForCloseSyncStateDialog(); await ShowAnkiWebReturnMessageIfHas(results); return; } else if (results[0] == "serverAbort") { await UIHelper.ShowMessageDialog("Server aborted."); return; } else { await UIHelper.ShowMessageDialog("Unknown sync return code."); return; } } catch (HttpSyncerException ex) { await WaitForCloseSyncStateDialog(); await UIHelper.ShowMessageDialog("AnkiWeb Sync: " + ex.Message); } catch (PasswordVaulException ex) { await WaitForCloseSyncStateDialog(); await UIHelper.ShowMessageDialog("AnkiWeb Sync: " + ex.Message); } catch (FileLoadException ex) { await WaitForCloseSyncStateDialog(); await UIHelper.ShowMessageDialog("AnkiWeb Sync: " + ex.Message); } catch (Exception ex) { await WaitForCloseSyncStateDialog(); await UIHelper.ShowMessageDialog("AnkiWeb Sync: " + ex.Message + "\n" + ex.StackTrace); } finally { syncStateDialog.Close(); } }