public async Task list_objects() { var file1 = "file1.txt"; var file2 = "folder1/file2.txt"; using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings)) { try { // Upload some files var content = Encoding.UTF8.GetBytes("hello, world"); await client.UploadObjectAsync(file1, new MemoryStream(content)); await client.UploadObjectAsync(file2, new MemoryStream(content)); var objects = await client.ListObjectsAsync(); Assert.Contains(objects, o => o.Name == file1); Assert.Contains(objects, o => o.Name == file2); } finally { await client.DeleteObjectAsync(file1); await client.DeleteObjectAsync(file2); } } }
public override void Dispose() { base.Dispose(); var settings = GetGoogleCloudSettings(); if (settings == null) { return; } try { using (var client = new RavenGoogleCloudClient(settings)) { var cloudObjects = client.ListObjectsAsync(settings.RemoteFolderName).GetAwaiter().GetResult(); foreach (var cloudObject in cloudObjects) { try { client.DeleteObjectAsync(cloudObject.Name).GetAwaiter().GetResult(); } catch (Exception) { // ignored } } } } catch (Exception) { // ignored } }
public async Task upload_object_with_metadata() { var fileName = Guid.NewGuid().ToString(); using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings)) { try { await client.UploadObjectAsync( fileName, new MemoryStream(Encoding.UTF8.GetBytes("456")), new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" } }); var obj = await client.GetObjectAsync(fileName); Assert.Equal("value1", obj.Metadata["key1"]); Assert.Equal("value2", obj.Metadata["key2"]); } finally { await client.DeleteObjectAsync(fileName); } } }
public async Task download_objects() { var fileName = Guid.NewGuid().ToString(); using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings)) { try { await client.UploadObjectAsync( fileName, new MemoryStream(Encoding.UTF8.GetBytes("123")) ); var file = new MemoryStream(); await client.DownloadObjectAsync(fileName, file); Assert.Equal("123", Encoding.ASCII.GetString(file.ToArray())); } finally { await client.DeleteObjectAsync(fileName); } } }
public async Task download_objects() { var fileName = Guid.NewGuid().ToString(); using (var client = new RavenGoogleCloudClient(GoogleCloudFactAttribute.GoogleCloudSettings)) { try { await client.UploadObjectAsync( fileName, new MemoryStream(Encoding.UTF8.GetBytes("123")) ); var stream = client.DownloadObject(fileName); using (var sr = new StreamReader(stream)) { Assert.Equal("123", sr.ReadToEnd()); } } finally { await client.DeleteObjectAsync(fileName); } } }
public async Task delete_objects() { var fileName = Guid.NewGuid().ToString(); using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings)) { await client.UploadObjectAsync( fileName, new MemoryStream(Encoding.UTF8.GetBytes("123")) ); await client.DeleteObjectAsync(fileName); Assert.Empty(await client.ListObjectsAsync()); } }
public async Task uploading_objects() { var fileName = Guid.NewGuid().ToString(); using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings)) { try { await client.UploadObjectAsync( fileName, new MemoryStream(Encoding.UTF8.GetBytes("123")) ); } finally { await client.DeleteObjectAsync(fileName); } } }
public async Task delete_objects() { var fileName = Guid.NewGuid().ToString(); using (var client = new RavenGoogleCloudClient(GoogleCloudFactAttribute.GoogleCloudSettings)) { await client.UploadObjectAsync( fileName, new MemoryStream(Encoding.UTF8.GetBytes("123")) ); var fileExists = await WaitForValueAsync(() => IsFileNameInCloudObjects(client, fileName), true); Assert.True(fileExists); await client.DeleteObjectAsync(fileName); fileExists = await WaitForValueAsync(() => IsFileNameInCloudObjects(client, fileName), false); Assert.False(fileExists); } }
private static async Task DeleteObjects(GoogleCloudSettings settings) { if (settings == null) { return; } try { using (var client = new RavenGoogleCloudClient(settings, DefaultBackupConfiguration)) { var all = await client.ListObjectsAsync(prefix : settings.RemoteFolderName); foreach (var obj in all) { await client.DeleteObjectAsync(obj.Name); } } } catch (Exception) { // ignored } }