Exemplo n.º 1
0
        private async Task DeleteCleanupOldBackupsAsync()
        {
            logManager.Info("Cleanup old backups.");

            if (GraphServiceClient == null)
            {
                throw new GraphClientNullException();
            }

            IDriveItemChildrenCollectionPage archiveBackups = await GraphServiceClient.Drive
                                                              .Items[ArchiveFolder?.Id]
                                                              .Children
                                                              .Request()
                                                              .GetAsync();

            if (archiveBackups.Count < BACKUP_ARCHIVE_COUNT)
            {
                return;
            }

            DriveItem oldestBackup = archiveBackups.OrderByDescending(x => x.CreatedDateTime).Last();

            await GraphServiceClient.Drive
            .Items[oldestBackup?.Id]
            .Request()
            .DeleteAsync();
        }
Exemplo n.º 2
0
        private async Task DeleteCleanupOldBackups()
        {
            IDriveItemChildrenCollectionPage archiveBackups = await GraphServiceClient.Drive
                                                                                      .Items[ArchiveFolder?.Id]
                                                                                      .Children
                                                                                      .Request()
                                                                                      .GetAsync();

            if (archiveBackups.Count < 5) return;
            DriveItem oldestBackup = archiveBackups.OrderByDescending(x => x.CreatedDateTime).Last();

            await GraphServiceClient.Drive
                                    .Items[oldestBackup?.Id]
                                    .Request()
                                    .DeleteAsync();
        }
Exemplo n.º 3
0
        private async Task RestoreArchivedBackupInCaseOfErrorAsync()
        {
            logManager.Info("Restore archived Backup.");

            if (GraphServiceClient == null)
            {
                throw new GraphClientNullException();
            }

            IDriveItemChildrenCollectionPage archivedBackups = await GraphServiceClient.Drive
                                                               .Items[ArchiveFolder?.Id]
                                                               .Children
                                                               .Request()
                                                               .GetAsync();

            if (!archivedBackups.Any())
            {
                logManager.Info("No backups found.");
                return;
            }

            DriveItem lastBackup = archivedBackups.OrderByDescending(x => x.CreatedDateTime).First();

            DriveItem?appRoot = await GraphServiceClient
                                .Me
                                .Drive
                                .Special
                                .AppRoot
                                .Request()
                                .GetAsync();

            var updateItem = new DriveItem
            {
                ParentReference = new ItemReference {
                    Id = appRoot.Id
                },
                Name = DatabaseConstants.BACKUP_NAME
            };

            await GraphServiceClient
            .Drive
            .Items[lastBackup.Id]
            .Request()
            .UpdateAsync(updateItem);
        }