diff --git a/Minio.Api/ApiEndpoints/BucketOperations.cs b/Minio.Api/ApiEndpoints/BucketOperations.cs index 057f2ba7..f101eca1 100644 --- a/Minio.Api/ApiEndpoints/BucketOperations.cs +++ b/Minio.Api/ApiEndpoints/BucketOperations.cs @@ -50,10 +50,44 @@ namespace Minio.Api return bucketList; } + public async Task MakeBucketAsync(string bucketName, string location = "us-east-1") + { + var request = new RestRequest("/" + bucketName, Method.PUT); + // ``us-east-1`` is not a valid location constraint according to amazon, so we skip it. + if (location != "us-east-1") + { + CreateBucketConfiguration config = new CreateBucketConfiguration(location); + request.AddBody(config); + } + var response = await this._client.ExecuteTaskAsync(this._client.NoErrorHandlers, request); + + if (response.StatusCode != HttpStatusCode.OK) + { + this._client.ParseError(response); + } + + } + + public async Task BucketExistsAsync(string bucketName) + { + var request = new RestRequest(bucketName, Method.HEAD); + var response = await this._client.ExecuteTaskAsync(this._client.NoErrorHandlers,request); + + if (response.StatusCode == HttpStatusCode.OK) + { + return true; + } + + var ex = this._client.ParseError(response); + if (ex.GetType() == typeof(BucketNotFoundException)) + { + return false; + } + throw ex; + } + - - diff --git a/Minio.Api/ApiEndpoints/IBucketOperations.cs b/Minio.Api/ApiEndpoints/IBucketOperations.cs index 9e29d95a..31cec4aa 100644 --- a/Minio.Api/ApiEndpoints/IBucketOperations.cs +++ b/Minio.Api/ApiEndpoints/IBucketOperations.cs @@ -8,17 +8,16 @@ namespace Minio.Api public interface IBucketOperations { Task ListBucketsAsync(); - /* + Task MakeBucketAsync(string bucketName, string location= "us-east-1"); Task BucketExistsAsync(string bucketName); - +/* Task RemoveBucketAsync(string bucketName); //returns err in go-sdk <=== Task> ListObjectsAsync(string bucketName, string prefix,bool recursive); - Task> ListIncompleteUploadsAsync(string bucketName,string prefix,bool recursive); -*/ + Task> ListIncompleteUploadsAsync(string bucketName,string prefix,bool recursive);*/ } } \ No newline at end of file diff --git a/Minio.Examples/Class1.cs b/Minio.Examples/Class1.cs deleted file mode 100644 index 45e003f9..00000000 --- a/Minio.Examples/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Minio.Examples -{ - public class Class1 - { - } -} diff --git a/Minio.Examples/ListBuckets.cs b/Minio.Examples/ListBuckets.cs new file mode 100644 index 00000000..b22b30f5 --- /dev/null +++ b/Minio.Examples/ListBuckets.cs @@ -0,0 +1,28 @@ +using System; +using Minio.Api; +using System.Threading; +using System.Threading.Tasks; +using Minio.Api.DataModel; + +namespace Minio.Examples +{ + class ListBuckets + { + static int Main() + { + var minio = new Minio.Api.MinioRestClient("play.minio.io:9000", + "Q3AM3UQ867SPQQA43P2F", + "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" + ).WithSSL(); + var getListBucketsTask = minio.Buckets.ListBucketsAsync(); + + Task.WaitAll(getListBucketsTask); // block while the task completes + var list = getListBucketsTask.Result; + foreach (Bucket bucket in list.Buckets) + { + Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime); + } + return 0; + } + } +} diff --git a/Minio.Examples/MakeBucket.cs b/Minio.Examples/MakeBucket.cs new file mode 100644 index 00000000..e15d5695 --- /dev/null +++ b/Minio.Examples/MakeBucket.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Minio.Examples +{ + public class MakeBucket + { + static int Main() + { + var minio = new Minio.Api.MinioRestClient("play.minio.io:9000", + "Q3AM3UQ867SPQQA43P2F", + "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" + ).WithSSL(); + + Task.WaitAll(minio.Buckets.MakeBucketAsync("bucket-name")); // block while the task completes + Console.ReadLine(); + return 0; + } + } +} diff --git a/Minio.Examples/Minio.Examples.csproj b/Minio.Examples/Minio.Examples.csproj index b25840b8..a4527b68 100644 --- a/Minio.Examples/Minio.Examples.csproj +++ b/Minio.Examples/Minio.Examples.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - 736dcd60-9f86-457d-81d3-284d1a155acb + {736DCD60-9F86-457D-81D3-284D1A155ACB} Library Properties Minio.Examples @@ -30,25 +30,26 @@ 4 - - - - - - - - - - - - - - + + + + + + + + - + + + + + {CC30CADE-342A-4CED-858D-B60200C075B0} + MinioApi + + - - + \ No newline at end of file diff --git a/SimpleTest/Program.cs b/SimpleTest/Program.cs index 9c9740a1..31163c6e 100644 --- a/SimpleTest/Program.cs +++ b/SimpleTest/Program.cs @@ -1,7 +1,4 @@ using System; -using Minio; -using Minio.Api.DataModel; -using Minio.Xml; using System.Threading.Tasks; namespace SimpleTest @@ -9,33 +6,13 @@ namespace SimpleTest class Program { static void Main(string[] args) - { - - //var client = new MinioClient("play.minio.io:9000", - // "Q3AM3UQ867SPQQA43P2F", - // "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"); - - //var buckets = client.ListBuckets(); - //foreach (Minio.Xml.Bucket bucket in buckets) - //{ - // Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime); - //} - - //return 0; + { var minio = new Minio.Api.MinioRestClient("play.minio.io:9000", "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" ).WithSSL(); - //Console.Out.WriteLine(minio); - //try - //{ - // var found = minio.BucketExists("yoyo"); - //} - //catch (Exception e) - //{ - // Console.Out.WriteLine(e.Message); - //} + var getListBucketsTask = minio.Buckets.ListBucketsAsync(); try @@ -51,13 +28,13 @@ namespace SimpleTest { Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime); } - //minio.Buckets.ListBucketsAsync(result => { - // foreach (Bucket bucket in result.Buckets) - // { - // Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime); - // } - //}); + + Task.WaitAll(minio.Buckets.MakeBucketAsync("bucket2")); + var bucketExistTask = minio.Buckets.BucketExistsAsync("bucket2"); + Task.WaitAll(bucketExistTask); + var found = bucketExistTask.Result; + Console.Out.WriteLine("bucket was " + found); Console.ReadLine(); } private static bool HandleBatchExceptions(Exception exceptionToHandle) diff --git a/tatus b/tatus deleted file mode 100644 index f7d1d6ca..00000000 --- a/tatus +++ /dev/null @@ -1,55 +0,0 @@ -commit ad72a3c808ebdb7cb7d3a49cdcf3252b04f6c235 -Merge: 17ed023 1285ced -Author: poornas -Date: Wed Jan 18 16:45:52 2017 -0800 - - Merge branch 'asyncAndErrorHandling' - -commit 17ed0232ce93f97af41c8c1d875001c06dac736b -Merge: 9ee0122 9c72c53 -Author: poornas -Date: Wed Jan 18 16:42:08 2017 -0800 - - Merge branch 'master' of https://github.com/poornas/minio-csharp-sdk - -commit 9c72c532954fa39163f92c34f47f7068b6e2539e -Author: poornas -Date: Wed Jan 18 16:38:57 2017 -0800 - - Initial commit - -commit 1285cedb048f8177dee30451a7b58aebe48e3118 -Author: poornas -Date: Wed Jan 18 14:52:26 2017 -0800 - - async with error handling - -commit ddd53c14fbf47154adb953ea3cb1d5e31d98b589 -Author: poornas -Date: Wed Jan 18 11:51:39 2017 -0800 - - proper async listbuckets call - -commit 9ee0122ee62bee67ae9e69a6d4a8104f25d3faef -Author: poornas -Date: Wed Jan 18 09:48:36 2017 -0800 - - changed listbuckets method to return void - -commit 9baa0e281b715302c4fa9be1952387fa03aab43a -Author: poornas -Date: Tue Jan 17 23:57:23 2017 -0800 - - listbuckets with callback; lots of cleanup to do - -commit 9b0c639e1c08254868f640018c6f9ef7289ba4c7 -Author: poornas -Date: Mon Jan 16 15:28:18 2017 -0800 - - Add project files. - -commit 3a89924eff533e90cbc509f4d786cf624462cffe -Author: poornas -Date: Mon Jan 16 15:28:17 2017 -0800 - - Add .gitignore and .gitattributes.