Browse Source

Add bucketexistAsync and makebucketAsync calls.

pull/129/head
poornas 9 years ago
parent
commit
71fb11749b
  1. 38
      Minio.Api/ApiEndpoints/BucketOperations.cs
  2. 7
      Minio.Api/ApiEndpoints/IBucketOperations.cs
  3. 12
      Minio.Examples/Class1.cs
  4. 28
      Minio.Examples/ListBuckets.cs
  5. 23
      Minio.Examples/MakeBucket.cs
  6. 38
      Minio.Examples/Minio.Examples.csproj
  7. 39
      SimpleTest/Program.cs
  8. 55
      tatus

38
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<bool> 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;
}

7
Minio.Api/ApiEndpoints/IBucketOperations.cs

@ -8,17 +8,16 @@ namespace Minio.Api
public interface IBucketOperations
{
Task<ListAllMyBucketsResult> ListBucketsAsync();
/*
Task MakeBucketAsync(string bucketName, string location= "us-east-1");
Task<bool> BucketExistsAsync(string bucketName);
/*
Task RemoveBucketAsync(string bucketName); //returns err in go-sdk <===
Task<IEnumerable<Item>> ListObjectsAsync(string bucketName, string prefix,bool recursive);
Task<IEnumerable<Upload>> ListIncompleteUploadsAsync(string bucketName,string prefix,bool recursive);
*/
Task<IEnumerable<Upload>> ListIncompleteUploadsAsync(string bucketName,string prefix,bool recursive);*/
}
}

12
Minio.Examples/Class1.cs

@ -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
{
}
}

28
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;
}
}
}

23
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;
}
}
}

38
Minio.Examples/Minio.Examples.csproj

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>736dcd60-9f86-457d-81d3-284d1a155acb</ProjectGuid>
<ProjectGuid>{736DCD60-9F86-457D-81D3-284D1A155ACB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Minio.Examples</RootNamespace>
@ -30,25 +30,26 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>
<Reference Include="Microsoft.CSharp"/>
<Reference Include="System.Data"/>
<Reference Include="System.Net.Http"/>
<Reference Include="System.Xml"/>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="MakeBucket.cs" />
<Compile Include="ListBuckets.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Minio.Api\MinioApi.csproj">
<Project>{CC30CADE-342A-4CED-858D-B60200C075B0}</Project>
<Name>MinioApi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
@ -57,5 +58,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

39
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)

55
tatus

@ -1,55 +0,0 @@
commit ad72a3c808ebdb7cb7d3a49cdcf3252b04f6c235
Merge: 17ed023 1285ced
Author: poornas <k.poorna@gmail.com>
Date: Wed Jan 18 16:45:52 2017 -0800
Merge branch 'asyncAndErrorHandling'
commit 17ed0232ce93f97af41c8c1d875001c06dac736b
Merge: 9ee0122 9c72c53
Author: poornas <k.poorna@gmail.com>
Date: Wed Jan 18 16:42:08 2017 -0800
Merge branch 'master' of https://github.com/poornas/minio-csharp-sdk
commit 9c72c532954fa39163f92c34f47f7068b6e2539e
Author: poornas <poornas@users.noreply.github.com>
Date: Wed Jan 18 16:38:57 2017 -0800
Initial commit
commit 1285cedb048f8177dee30451a7b58aebe48e3118
Author: poornas <k.poorna@gmail.com>
Date: Wed Jan 18 14:52:26 2017 -0800
async with error handling
commit ddd53c14fbf47154adb953ea3cb1d5e31d98b589
Author: poornas <k.poorna@gmail.com>
Date: Wed Jan 18 11:51:39 2017 -0800
proper async listbuckets call
commit 9ee0122ee62bee67ae9e69a6d4a8104f25d3faef
Author: poornas <k.poorna@gmail.com>
Date: Wed Jan 18 09:48:36 2017 -0800
changed listbuckets method to return void
commit 9baa0e281b715302c4fa9be1952387fa03aab43a
Author: poornas <k.poorna@gmail.com>
Date: Tue Jan 17 23:57:23 2017 -0800
listbuckets with callback; lots of cleanup to do
commit 9b0c639e1c08254868f640018c6f9ef7289ba4c7
Author: poornas <k.poorna@gmail.com>
Date: Mon Jan 16 15:28:18 2017 -0800
Add project files.
commit 3a89924eff533e90cbc509f4d786cf624462cffe
Author: poornas <k.poorna@gmail.com>
Date: Mon Jan 16 15:28:17 2017 -0800
Add .gitignore and .gitattributes.
Loading…
Cancel
Save