public FoldersPickerControl(List <OneDriveStorageFolder> folders, OneDriveStorageFolder rootFolder) { this.InitializeComponent(); _graphFolders = folders; _graphCurrentFolder = _graphRootFolder = rootFolder; }
private void LstFolder_ItemClick(object sender, ItemClickEventArgs e) { SelectedGraphFolder = e.ClickedItem as OneDriveStorageFolder; }
public static async Task <OneDriveStorageFolder> OpenFolderPicker(string title, OneDriveStorageFolder rootFolder) { FoldersPickerControl folderPicker = new FoldersPickerControl(await rootFolder.GetFoldersAsync(100), rootFolder); ContentDialog dialog = new ContentDialog { Content = folderPicker, Title = title, PrimaryButtonText = "Ok" }; if (await dialog.ShowAsync() == ContentDialogResult.Primary) { return(folderPicker.SelectedGraphFolder); } else { return(null); } }
private async Task SigninAsync(int indexProvider, string appClientId) { if (!await Tools.CheckInternetConnectionAsync()) { return; } Shell.Current.DisplayWaitRing = true; bool succeeded = false; try { // OnlineId if (indexProvider == 0) { Services.OneDrive.OneDriveService.Instance.Initialize(); } else if (indexProvider == 1) { Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Msa, OneDriveScopes.OfflineAccess | OneDriveScopes.ReadWrite); } else if (indexProvider == 2) { Services.OneDrive.OneDriveService.Instance.Initialize(appClientId, AccountProviderType.Adal); } else if (indexProvider == 3) { Services.OneDrive.OneDriveService.GraphInstance.Initialize(appClientId, DelegatedPermissionScopes.Text.Split(' ')); } if (indexProvider == 3) { if (!await Services.OneDrive.OneDriveService.GraphInstance.LoginAsync()) { throw new Exception("Unable to sign in"); } _graphCurrentFolder = _graphRootFolder = await Services.OneDrive.OneDriveService.GraphInstance.RootFolderForMeAsync(); OneDriveItemsList.ItemsSource = await _graphRootFolder.GetItemsAsync(20); } else { if (!await Services.OneDrive.OneDriveService.Instance.LoginAsync()) { throw new Exception("Unable to sign in"); } _currentFolder = _rootFolder = await Services.OneDrive.OneDriveService.Instance.RootFolderAsync(); OneDriveItemsList.ItemsSource = _rootFolder.GetItemsAsync(); } succeeded = true; } catch (ServiceException serviceEx) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { Shell.Current.DisplayWaitRing = false; } if (succeeded) { FilesBox.Visibility = Visibility.Visible; UserBox.Visibility = Visibility.Visible; ClientIdBox.Visibility = Visibility.Collapsed; ClientIdHelper.Visibility = Visibility.Collapsed; LogOutButton.Visibility = Visibility.Visible; ConnectButton.Visibility = Visibility.Collapsed; menuButton.Visibility = Visibility.Visible; BackButton.Visibility = Visibility.Visible; } else { FilesBox.Visibility = Visibility.Collapsed; UserBox.Visibility = Visibility.Collapsed; ClientIdBox.Visibility = Visibility.Visible; ClientIdHelper.Visibility = Visibility.Visible; LogOutButton.Visibility = Visibility.Collapsed; ConnectButton.Visibility = Visibility.Visible; menuButton.Visibility = Visibility.Collapsed; BackButton.Visibility = Visibility.Collapsed; } }
private void LstFolder_ItemClick(object sender, ItemClickEventArgs e) { _destinationFolder = e.ClickedItem as OneDriveStorageFolder; }
private async Task <bool> decideWhetherCloudOrDeviceHasNewerData(List <StorageFile> goalDataToSync, OneDriveStorageFolder rootFolder, long cloudSyncDateInTicks) { bool isDeviceNewerThanCloud = false; List <OneDriveStorageFile> cloudData = await onedrive.getCloudDataFiles(rootFolder); for (int i = 0; i < 3; i++) { var dataFileProperties = await goalDataToSync[i].GetBasicPropertiesAsync(); if (dataFileProperties.DateModified.Ticks > cloudSyncDateInTicks) { isDeviceNewerThanCloud = true; } } return(isDeviceNewerThanCloud); }
private async Task SigninAsync(string appClientId) { if (!await Tools.CheckInternetConnectionAsync()) { return; } SampleController.Current.DisplayWaitRing = true; bool succeeded = false; try { // Converged app authentication // Get the selected Delegated Permissions var scopes = DelegatedPermissions.SelectedItems as string[]; // If the user hasn't selected a scope then set it to FilesReadAll if (scopes == null) { scopes = new string[] { MicrosoftGraphScope.FilesReadAll }; } OneDriveService.Instance.Initialize(appClientId, scopes, null, null); if (!await OneDriveService.Instance.LoginAsync()) { throw new Exception("Unable to sign in"); } _graphCurrentFolder = _graphRootFolder = await OneDriveService.Instance.RootFolderForMeAsync(); OneDriveItemsList.ItemsSource = await _graphRootFolder.GetItemsAsync(20); OneDriveItemsList.Visibility = Visibility.Visible; succeeded = true; } catch (ServiceException serviceEx) { await OneDriveSampleHelpers.DisplayOneDriveServiceExceptionAsync(serviceEx); } catch (Exception ex) { await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message); TrackingManager.TrackException(ex); } finally { SampleController.Current.DisplayWaitRing = false; } if (succeeded) { FilesBox.Visibility = Visibility.Visible; UserBox.Visibility = Visibility.Visible; ClientIdBox.Visibility = Visibility.Collapsed; ClientIdHelper.Visibility = Visibility.Collapsed; LogOutButton.Visibility = Visibility.Visible; ConnectButton.Visibility = Visibility.Collapsed; menuButton.Visibility = Visibility.Visible; BackButton.Visibility = Visibility.Visible; } else { FilesBox.Visibility = Visibility.Collapsed; UserBox.Visibility = Visibility.Collapsed; ClientIdBox.Visibility = Visibility.Visible; ClientIdHelper.Visibility = Visibility.Visible; LogOutButton.Visibility = Visibility.Collapsed; ConnectButton.Visibility = Visibility.Visible; menuButton.Visibility = Visibility.Collapsed; BackButton.Visibility = Visibility.Collapsed; } }
private async Task <bool> downloadDataFromCloud(OneDriveStorageFolder rootFolder, OneDriveStorageFolder imageFolder, List <StorageFile> goalDataToSync, List <OneDriveStorageFile> cloudData) { //Outline: Download and replace all goal data and images. Update the imagePath of each goal in case the user changes user name //on another computer (Things happen). You'll create a relativeUri using the images you've downloaded. Then you save one last time and update var localFolder = ApplicationData.Current.LocalFolder; retrieveGoalDataFromCloud(localFolder, cloudData); syncStatusTextBlock.Text = "Removing old data from your current device"; List <StorageFile> newImageData = new List <StorageFile>(); bool imageFolderIsEmpty = await onedrive.checkIfImageFolderIsEmpty(imageFolder); if (!imageFolderIsEmpty) { newImageData = await retrievegoalImageDataFromCloud(imageFolder, localFolder); } updateImageUriForNewGoalData(newImageData, localFolder); syncStatusTextBlock.Text = "Sync Complete!"; return(true); }
private async void uploadDataToCloud(OneDriveStorageFolder rootFolder, List <StorageFile> goalDataToSync, OneDriveStorageFolder imageFolder) { foreach (var dataFile in goalDataToSync) { using (var localStream = await dataFile.OpenReadAsync()) { showProgeressRing(); var fileCreated = await rootFolder.CreateFileAsync(dataFile.Name, CreationCollisionOption.ReplaceExisting, localStream); } } List <StorageFile> imagesToSync = await goal.getImagesReadyForSyncing(); syncStatusTextBlock.Text = "Syncing Goal Image Data"; foreach (var image in imagesToSync) { using (var localStream = await image.OpenReadAsync()) { showProgeressRing(); var fileCreated = await imageFolder.UploadFileAsync(image.Name, localStream, CreationCollisionOption.ReplaceExisting, 320 * 3 * 1024); } } syncStatusTextBlock.Text = "Sync Complete!"; showSuccessImage(); hideProgressRing(); }
public async static void writeCurrentTimeToStatusFile(DateTime lastTimeSynced, OneDriveStorageFolder rootFolder) { //Gonna make the status file in tempoary folder, write lastTimeSynced in there then replace the one in the cloud with the one created in temporay folder. var fileToUpload = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("status.txt", CreationCollisionOption.ReplaceExisting); long dateAsTicks = lastTimeSynced.Ticks; string dateAsTicksString = dateAsTicks.ToString(); System.IO.File.WriteAllText(fileToUpload.Path, dateAsTicksString); if (fileToUpload != null) { using (var localStream = await fileToUpload.OpenReadAsync()) { var fileCreated = await rootFolder.CreateFileAsync(fileToUpload.Name, CreationCollisionOption.ReplaceExisting, localStream); } } await fileToUpload.DeleteAsync(StorageDeleteOption.PermanentDelete); }
public async static void CreateStatusFile(OneDriveStorageFolder rootFolder) { await rootFolder.CreateFileAsync("status.txt", CreationCollisionOption.ReplaceExisting); }
public async static Task <List <OneDriveStorageFile> > CreateDataFilesForSyncing(OneDriveStorageFolder rootFolder) { var cloudGoalData = await rootFolder.CreateFileAsync("golaso.json"); var cloudCompletedGoalData = await rootFolder.CreateFileAsync("noGolaso.json"); var cloudHistoryData = await rootFolder.CreateFileAsync("history.json"); bool areFilesUploaded = false; do { long uploadStatus = await rootFolder.GetUploadStatusAsync(); if (uploadStatus == 100) { areFilesUploaded = true; } } while (areFilesUploaded == false); return(new List <OneDriveStorageFile> { cloudGoalData, cloudCompletedGoalData, cloudHistoryData }); }