public static async Task UpdateBucketAsync(IAccount account, Ess3Bucket bucket, CancellationToken token) { ListObjectsV2Response?response = await List.ObjectsAsync(account, bucket, token).ConfigureAwait(true); // ConfigAwait must remain true if (response is null) { return; } if (response.HttpStatusCode != HttpStatusCode.OK) { return; } var ess3Objects = response.S3Objects.Select(o => Ess3Factory.Create(o)).ToList(); var files = ess3Objects.Where(o => o is Ess3File).Cast <Ess3File>(); var directories = ess3Objects.Where(o => o is Ess3Directory).Cast <Ess3Directory>(); PutEveryDirectoryIntoParentDirectory(directories); PutEveryFileIntoParentDirectory(files, directories); // adding dirs then files in this way "sorts" the dirs first // this means we don't need to sort in the GUI foreach (Ess3Directory each in directories.Where(d => Ess3Factory.IsBucketLevel(d))) { bucket.Add(each); } foreach (Ess3File each in files.Where(f => Ess3Factory.IsBucketLevel(f))) { bucket.Add(each); } }
public void BucketSize_Calculation() { Random random = new Random(Environment.TickCount % 17); Int64 fileSize1 = (Int64)random.Next(10, Int32.MaxValue - 1); Int64 fileSize2 = (Int64)random.Next(10, Int32.MaxValue - 1); Int64 fileSize3 = (Int64)random.Next(10, Int32.MaxValue - 1); Int64 fileSize4 = (Int64)random.Next(10, Int32.MaxValue - 1); var file1 = new Ess3File(new S3Object { Size = fileSize1, Key = "file1" }); var file2 = new Ess3File(new S3Object { Size = fileSize2, Key = "file2" }); var file3 = new Ess3File(new S3Object { Size = fileSize3, Key = "file3" }); var file4 = new Ess3File(new S3Object { Size = fileSize4, Key = "file4" }); var directory1 = new Ess3Directory { Key = "dir1" }; var directory2 = new Ess3Directory { Key = "dir2" }; var directory3 = new Ess3Directory { Key = "dir3" }; directory1.Add(file1); directory2.Add(file2); directory3.Add(file3); directory2.Add(directory3); directory1.Add(directory2); var bucket = new Ess3Bucket("bucket", DateTime.Now); bucket.Add(directory1); bucket.Add(file4); Int64 expected = fileSize1 + fileSize2 + fileSize3 + fileSize4; Int64 actual = bucket.Size; Assert.AreEqual(expected, actual, "bucket has {0} objects ({1}, {2}, {3}, {4})", bucket.Ess3Objects.Count, fileSize1, fileSize2, fileSize3, fileSize4); }