private async Task SychronizeFolder(ResourceInfo resourceInfo) { if (resourceInfo == null) { return; } var syncInfo = SyncDbUtils.GetFolderSyncInfoByPath(resourceInfo.Path); StorageFolder folder; try { Task <ContentDialogResult> firstRunDialog = null; if (syncInfo == null) { // try to Get parent or initialize syncInfo = SyncDbUtils.GetFolderSyncInfoBySubPath(resourceInfo.Path); if (syncInfo == null) { // Initial Sync syncInfo = new FolderSyncInfo() { Path = resourceInfo.Path }; var folderPicker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.Desktop }; folderPicker.FileTypeFilter.Add(".txt"); StorageFolder newFolder = await folderPicker.PickSingleFolderAsync(); if (newFolder == null) { return; } StorageApplicationPermissions.FutureAccessList.AddOrReplace(syncInfo.AccessListKey, newFolder); IReadOnlyList <IStorageItem> subElements = await newFolder.GetItemsAsync(); NextcloudClient.NextcloudClient client = await ClientService.GetClient(); var remoteElements = await client.List(resourceInfo.Path); if (subElements.Count > 0 && remoteElements.Count > 0) { var dialogNotEmpty = new ContentDialog { Title = _resourceLoader.GetString("SyncFoldersNotEmptyWarning"), Content = new TextBlock() { Text = _resourceLoader.GetString("SyncFoldersNotEmptyWarningDetail"), TextWrapping = TextWrapping.WrapWholeWords, Margin = new Thickness(0, 20, 0, 0) }, PrimaryButtonText = _resourceLoader.GetString("OK"), SecondaryButtonText = _resourceLoader.GetString("Cancel") }; var dialogResult = await _dialogService.ShowAsync(dialogNotEmpty); if (dialogResult != ContentDialogResult.Primary) { return; } } folder = newFolder; SyncDbUtils.SaveFolderSyncInfo(syncInfo); StartDirectoryListing(); // This is just to update the menu flyout - maybe there is a better way var dialog = new ContentDialog { Title = _resourceLoader.GetString("SyncStarted"), Content = new TextBlock() { Text = _resourceLoader.GetString("SyncStartedDetail"), TextWrapping = TextWrapping.WrapWholeWords, Margin = new Thickness(0, 20, 0, 0) }, PrimaryButtonText = _resourceLoader.GetString("OK") }; firstRunDialog = _dialogService.ShowAsync(dialog); } else { string subPath = resourceInfo.Path.Substring(syncInfo.Path.Length); StorageFolder tempFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(syncInfo.AccessListKey); foreach (string foldername in subPath.Split('/')) { if (foldername.Length > 0) { tempFolder = await tempFolder.GetFolderAsync(foldername); } } folder = tempFolder; } } else { folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(syncInfo.AccessListKey); // TODO catch exceptions } SyncService service = new SyncService(folder, resourceInfo, syncInfo); await service.StartSync(); if (firstRunDialog != null) { await firstRunDialog; } } catch (Exception e) { // ERROR Maybe AccessList timed out. Debug.WriteLine(e.Message); } }