本文整理汇总了C#中AmazonS3.ListBuckets方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3.ListBuckets方法的具体用法?C# AmazonS3.ListBuckets怎么用?C# AmazonS3.ListBuckets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AmazonS3
的用法示例。
在下文中一共展示了AmazonS3.ListBuckets方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassInitialize
public static void ClassInitialize(TestContext context)
{
try
{
client = ClientTests.CreateClient();
var buckets = client.ListBuckets();
bucket = buckets.Buckets.First();
}
catch (Exception e)
{
Assert.Inconclusive("prerequisite: unable to create client or bucket. Error: {0}", e.Message);
}
}
示例2: CheckForBucket
public static void CheckForBucket(string itemKey, AmazonS3 s3Client)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
string userBucketName = String.Format(Settings.Default.BucketNameFormat, HttpContext.Current.User.Identity.Name, itemKey);
using (ListBucketsResponse listBucketsResponse = s3Client.ListBuckets())
{
S3Bucket bucket = listBucketsResponse.Buckets.FirstOrDefault(b => b.BucketName == userBucketName);
if (bucket == null)
{
PutBucketRequest putBucketRequest = new PutBucketRequest()
.WithBucketName(userBucketName);
PutBucketResponse putBucketResponse = s3Client.PutBucket(putBucketRequest);
putBucketResponse.Dispose();
}
}
}
}
示例3: Initialize_S3_stuff
public static bool Initialize_S3_stuff()
{
Console.WriteLine("starting Initialize_S3_stuff()");
s3_client = null;
bucketName = null;
try
{
if (!Utils.CFG.ContainsKey("s3_bucketName"))
{
Console.WriteLine("param s3_bucketName is not found in ez3d.config");
return false;
}
s3_client = AWSClientFactory.CreateAmazonS3Client();
// ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
ListBucketsResponse response = s3_client.ListBuckets();
foreach (S3Bucket bucket in response.Buckets)
{
if (bucket.BucketName == (String)Utils.CFG["s3_bucketName"])
{
bucketName = bucket.BucketName;
Console.WriteLine("bucketName =" + bucketName);
}
}
if (bucketName == null)
{
Console.WriteLine("(bucketName == null)");
return false;
}
Console.WriteLine("Initialize_S3_stuff fininshed succefully");
return true;
}
catch (AmazonS3Exception e)
{
Console.WriteLine("AmazonS3Exception caught !!!");
Console.WriteLine(e.Message);
return false;
}
}
示例4: GetBucket
private S3Bucket GetBucket(AmazonS3 client)
{
ListBucketsRequest listRequest = new ListBucketsRequest();
ListBucketsResponse response = client.ListBuckets(listRequest);
return response.Buckets
.Where(candidate => candidate.BucketName == this.BucketName)
.FirstOrDefault();
}
示例5: DoesBucketExist
private bool DoesBucketExist(AmazonS3 client)
{
using (ListBucketsResponse listBucketsResponse = client.ListBuckets())
return (listBucketsResponse.Buckets.Any(b => b.BucketName == BucketName));
}
示例6: CreateBucket
private static void CreateBucket(AmazonS3 client, string bucketname)
{
Console.Out.WriteLine("Checking S3 bucket with name " + bucketname);
ListBucketsResponse response = client.ListBuckets();
bool found = false;
foreach (S3Bucket bucket in response.Buckets)
{
if (bucket.BucketName == bucketname)
{
Console.Out.WriteLine(" Bucket found will not create it.");
found = true;
break;
}
}
if (found == false)
{
Console.Out.WriteLine(" Bucket not found will create it.");
client.PutBucket(new PutBucketRequest().WithBucketName(bucketname));
Console.Out.WriteLine("Created S3 bucket with name " + bucketname);
}
}