Esempio n. 1
0
        public async Task DeleteStorageItem(IDriveScope driveScope, StorageItem item, CancellationToken cancellationToken)
        {
            var drive = await m_globalScope.Drives.GetAsync(item.DriveId, cancellationToken);

            var releasedStats = new SubtreeStatistics();

            try
            {
                await DeleteStorageItemRecursively(driveScope, item, releasedStats);
            }
            finally
            {
                drive.NumberOfFiles    -= releasedStats.NumberOfFiles;
                drive.TotalStorageUsed -= releasedStats.StorageSize;
                await m_globalScope.Drives.UpdateAsync(drive, cancellationToken);
            }
        }
Esempio n. 2
0
        private async Task DeleteStorageItemRecursively(IDriveScope driveScope, StorageItem item, SubtreeStatistics driveStatistics)
        {
            if (item is Folder folder)
            {
                await driveScope.StorageItems.LoadFolderChildren(folder, CancellationToken.None);

                foreach (var folderChild in folder.Children.ToList())
                {
                    await DeleteStorageItemRecursively(driveScope, folderChild, driveStatistics);
                }
            }

            await DeleteBlob(item);

            if (!(item is Folder))
            {
                driveStatistics.StorageSize   += item.Size;
                driveStatistics.NumberOfFiles += 1;
            }
            await driveScope.StorageItems.RemoveAsync(item.Id, CancellationToken.None);
        }