Beispiel #1
0
        private async void uploadDataToCloud(OneDriveStorageFolder rootFolder, OneDriveStorageFolder imageFolder, List <StorageFile> goalDataToSync, List <OneDriveStorageFile> cloudData)
        {
            syncStatusTextBlock.Text = "Replacing old data from cloud";

            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();
        }
Beispiel #2
0
        /// <summary>
        /// Upload large file.
        /// </summary>
        /// <param name="folder">The destination folder</param>
        /// <returns>Task to support await of async call.</returns>
        public static async Task UploadLargeFileAsync(OneDriveStorageFolder folder)
        {
            try
            {
                if (folder != null)
                {
                    var selectedFile = await OpenLocalFileAsync();

                    if (selectedFile != null)
                    {
                        using (var localStream = await selectedFile.OpenReadAsync())
                        {
                            Shell.Current.DisplayWaitRing = true;

                            // If the file exceed the Maximum size (ie 4MB)
                            var largeFileCreated = await folder.UploadFileAsync(selectedFile.Name, localStream, CreationCollisionOption.GenerateUniqueName, 320 * 1024);
                        }
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);
            }
            catch (ServiceException graphEx)
            {
                await OneDriveSampleHelpers.DisplayMessageAsync(graphEx.Error.Message);
            }
            catch (Exception ex)
            {
                await OneDriveSampleHelpers.DisplayMessageAsync(ex.Message);

                TrackingManager.TrackException(ex);
            }
            finally
            {
                Shell.Current.DisplayWaitRing = false;
            }
        }