Пример #1
0
        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
            });
        }
Пример #2
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();
        }
Пример #3
0
        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);
        }
Пример #4
0
        /// <summary>
        /// Upload simple file.
        /// </summary>
        /// <param name="folder">The destination folder</param>
        /// <returns>Task to support await of async call.</returns>
        public static async Task UploadSimpleFileAsync(OneDriveStorageFolder folder)
        {
            Shell.Current.DisplayWaitRing = true;

            try
            {
                if (folder != null)
                {
                    var selectedFile = await OpenLocalFileAsync();

                    if (selectedFile != null)
                    {
                        using (var localStream = await selectedFile.OpenReadAsync())
                        {
                            var fileCreated = await folder.CreateFileAsync(selectedFile.Name, CreationCollisionOption.GenerateUniqueName, localStream);
                        }
                    }
                }
            }
            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;
            }
        }
Пример #5
0
 public async static void CreateStatusFile(OneDriveStorageFolder rootFolder)
 {
     await rootFolder.CreateFileAsync("status.txt", CreationCollisionOption.ReplaceExisting);
 }