public async Task <TaskCompletionType> Upload()
        {
            if (!IsLoggedIn)
            {
                await Login();
            }

            try
            {
                using (var dbstream = fileStore.OpenRead(OneDriveAuthenticationConstants.DB_NAME))
                {
                    var uploadedItem = await OneDriveClient
                                       .Drive
                                       .Root
                                       .ItemWithPath(Path.Combine(OneDriveAuthenticationConstants.BACKUP_FOLDER_NAME,
                                                                  OneDriveAuthenticationConstants.BACKUP_NAME))
                                       .Content
                                       .Request()
                                       .PutAsync <Item>(dbstream);

                    return(uploadedItem != null ? TaskCompletionType.Successful : TaskCompletionType.Unsuccessful);
                }
            }
            catch (OneDriveException ex)
            {
                Insights.Report(ex, Insights.Severity.Error);
                return(TaskCompletionType.Unsuccessful);
            }
        }
示例#2
0
        /// <summary>
        ///     Uploads a copy of the current database.
        /// </summary>
        /// <returns>Returns a TaskCompletionType which indicates if the task was successful or not</returns>
        public async Task <bool> Upload()
        {
            if (OneDriveClient == null)
            {
                OneDriveClient = await oneDriveAuthenticator.LoginAsync();
            }

            await LoadBackupFolder();
            await LoadArchiveFolder();

            await DeleteCleanupOldBackups();
            await ArchiveCurrentBackup();

            using (var dbstream = fileStore.OpenRead(DatabaseConstants.DB_NAME))
            {
                var uploadedItem = await OneDriveClient
                                   .Drive
                                   .Root
                                   .ItemWithPath(Path.Combine(DatabaseConstants.BACKUP_FOLDER_NAME,
                                                              DatabaseConstants.BACKUP_NAME))
                                   .Content
                                   .Request()
                                   .PutAsync <Item>(dbstream);

                return(uploadedItem != null);
            }
        }
示例#3
0
        /// <inheritdoc />
        public async Task <bool> CreateNewBackup()
        {
            if (!connectivity.IsConnected)
            {
                throw new NetworkConnectionException();
            }

            using (var dbstream = fileStore.OpenRead(DatabaseConstants.DB_NAME))
            {
                return(await backupService.Upload(dbstream));
            }
        }
示例#4
0
        private async Task <bool> CreateNewBackup()
        {
            if (!connectivity.IsConnected)
            {
                throw new NetworkConnectionException();
            }

            using (var dbStream = fileStore.OpenRead(DatabaseConstants.DB_NAME))
            {
                return(await cloudBackupService.Upload(dbStream)
                       .ConfigureAwait(false));
            }
        }
示例#5
0
        public override Stream GetAttachment(string id, string attachmentName)
        {
            var entityAttachmentDir = AttachmentsDirectoryPath + "/" + id;
            var attachmentFilePath  = entityAttachmentDir + "/" + attachmentName;

            if (!Exist(id))
            {
                throw new KeyNotFoundNoSQLException();
            }

            if (!fileStore.Exists(attachmentFilePath))
            {
                throw new AttachmentNotFoundNoSQLException();
            }

            return(fileStore.OpenRead(attachmentFilePath));
        }
示例#6
0
        /// <summary>
        ///     Uploads a copy of the current database.
        /// </summary>
        /// <returns>Returns a TaskCompletionType which indicates if the task was successful or not</returns>
        public async Task <bool> Upload()
        {
            if (OneDriveClient.IsAuthenticated)
            {
                await GetBackupFolder();
            }

            using (var dbstream = fileStore.OpenRead(DatabaseConstants.DB_NAME)) {
                var uploadedItem = await OneDriveClient
                                   .Drive
                                   .Root
                                   .ItemWithPath(Path.Combine(DatabaseConstants.BACKUP_FOLDER_NAME,
                                                              DatabaseConstants.BACKUP_NAME))
                                   .Content
                                   .Request()
                                   .PutAsync <Item>(dbstream);

                return(uploadedItem != null);
            }
        }
示例#7
0
        private async Task <List <Session> > GetSessionsAsync(bool forceRefresh = false)
        {
            if (forceRefresh || (DateTime.UtcNow - Settings.LastSyncTime).TotalMinutes >= SessionRefreshAfterMinutes || !_fileStore.Exists(SessionsFileName))
            {
                await DownloadSessionsAsync();
            }
            var sessionData = _fileStore.OpenRead(SessionsFileName);

            var sessions = _jsonConverter.DeserializeObject <Session[]>(sessionData);

#if DEBUG
            foreach (var session in sessions)
            {
                var num = (session.id % 11) + 1;
                session.sessionStartDate = GetRandomSessionTime(num);
                session.sessionTime      = session.sessionStartDate.ToString("hh:mm tt dddd");
                session.startTime        = num.ToString();
            }
#endif

            return(new List <Session>(sessions));
        }
示例#8
0
        public byte[] LoadImage(string name)
        {
            var path = this.fileStore.NativePath(nativePath) + name;

            return(ReadFully(fileStore.OpenRead(path)));
        }