Exemplo n.º 1
0
        public override void Dispose()
        {
            base.Dispose();

            var s3Settings = _isCustom ? CustomS3FactAttribute.S3Settings : AmazonS3FactAttribute.S3Settings;

            if (s3Settings == null)
            {
                return;
            }

            try
            {
                using (var s3Client = new RavenAwsS3Client(s3Settings, DefaultConfiguration))
                {
                    var cloudObjects  = s3Client.ListObjects($"{s3Settings.RemoteFolderName}/{_remoteFolderName}/", string.Empty, false, includeFolders: true);
                    var pathsToDelete = cloudObjects.FileInfoDetails.Select(x => x.FullPath).ToList();

                    s3Client.DeleteMultipleObjects(pathsToDelete);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
Exemplo n.º 2
0
        public override void Dispose()
        {
            base.Dispose();

            var s3Settings = GetS3Settings();

            if (s3Settings == null)
            {
                return;
            }

            try
            {
                using (var s3Client = new RavenAwsS3Client(s3Settings))
                {
                    var cloudObjects  = s3Client.ListObjectsAsync(s3Settings.RemoteFolderName, string.Empty, false).GetAwaiter().GetResult();
                    var pathsToDelete = cloudObjects.FileInfoDetails.Select(x => x.FullPath).ToList();

                    s3Client.DeleteMultipleObjects(pathsToDelete);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
Exemplo n.º 3
0
        protected override async Task DeleteFolders(List <string> folders)
        {
            // deleting multiple objects is limited to 1000 in a single batch
            const int numberOfObjectsInBatch = 1000;
            var       objectsToDelete        = new List <string>();

            foreach (var folder in folders)
            {
                string filesContinuationToken = null;

                do
                {
                    // delete all objects in that folder
                    var objects = await _client.ListObjects(folder, null, false, continuationToken : filesContinuationToken);

                    foreach (var file in objects.FileInfoDetails)
                    {
                        if (objectsToDelete.Count == numberOfObjectsInBatch)
                        {
                            await _client.DeleteMultipleObjects(objectsToDelete);

                            objectsToDelete.Clear();
                        }

                        objectsToDelete.Add(file.FullPath);
                    }

                    filesContinuationToken = objects.ContinuationToken;

                    CancellationToken.ThrowIfCancellationRequested();
                } while (filesContinuationToken != null);
            }

            if (objectsToDelete.Count > 0)
            {
                await _client.DeleteMultipleObjects(objectsToDelete);
            }
        }