本文整理汇总了C#中Amazon.S3.Model.ListObjectsRequest类的典型用法代码示例。如果您正苦于以下问题:C# ListObjectsRequest类的具体用法?C# ListObjectsRequest怎么用?C# ListObjectsRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListObjectsRequest类属于Amazon.S3.Model命名空间,在下文中一共展示了ListObjectsRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RefreshAssetList
public void RefreshAssetList()
{
string SecretKey = null;
string PublicKey = null;
AmazonS3Client Client = new AmazonS3Client(PublicKey, SecretKey);
ListObjectsRequest Request = new ListObjectsRequest
{
BucketName = "assets.minecraft.net",
};
ListObjectsResponse Result;
List<Release> releases = new List<Release>();
do
{
Result = Client.ListObjects(Request);
foreach (S3Object o in Result.S3Objects)
{
string IsSnapshot = "Release";
if(!o.Key.Contains("minecraft.jar")) continue;
if (Regex.IsMatch(o.Key, "[0-9][0-9]w[0-9][0-9]")) IsSnapshot = "Snapshot";
else if (o.Key.Contains("pre")) IsSnapshot = "Pre-release";
releases.Add(new Release { Version = o.Key.Split('/')[0],
Size = (o.Size / 1024).ToString() + "KB",
Uploaded = DateTime.Parse(o.LastModified),
Type = IsSnapshot,
Key = o.Key} );
}
}
while (Result.IsTruncated);
releases.Sort(new Comparison<Release>((x, y) => DateTime.Compare(y.Uploaded, x.Uploaded)));
_Releases.Clear();
foreach (Release r in releases)
{
_Releases.Add(r);
}
Client.Dispose();
Result.Dispose();
}
开发者ID:tman0,项目名称:MCLauncher2,代码行数:40,代码来源:SnapshotDownloader.xaml.cs
示例2: ListFiles
public GitBinFileInfo[] ListFiles()
{
var remoteFiles = new List<GitBinFileInfo>();
var client = GetClient();
var listRequest = new ListObjectsRequest();
listRequest.BucketName = _bucketName;
ListObjectsResponse listResponse;
do {
listResponse = client.ListObjects(listRequest);
if (listResponse.S3Objects.Any())
{
var keys = listResponse.S3Objects.Select(o => new GitBinFileInfo(o.Key, o.Size));
remoteFiles.AddRange(keys);
listRequest.Marker = remoteFiles[remoteFiles.Count - 1].Name;
}
}
while (listResponse.IsTruncated);
return remoteFiles.ToArray();
}
开发者ID:jubanka,项目名称:git-bin,代码行数:26,代码来源:S3Remote.cs
示例3: SetupInitial
public override void SetupInitial() {
// This is a chance to do heavy stuff, but in a thread
// Obtain a full list of the bucket. Helps a lot later
ListObjectsRequest listRequest = new ListObjectsRequest() {
BucketName = this.bucket,
Prefix = this.prefix
};
ListObjectsResponse listResponse;
this.files = new List<string>();
this.folders = new List<string>();
// This needs fixing, but somewhere else
this.folders.Add("");
try {
do {
listResponse = client.ListObjects(listRequest);
foreach (S3Object obj in listResponse.S3Objects) {
if (obj.Key.EndsWith("/") && obj.Size == 0)
this.folders.Add(obj.Key.TrimEnd(new char[] { '/' }).Substring(this.prefix.Length));
else
this.files.Add(obj.Key.Substring(this.prefix.Length));
}
listRequest.Marker = listResponse.NextMarker;
} while (listResponse.NextMarker != null);
}
catch (AmazonS3Exception ex) {
string message = ex.Message;
// Clarify this error
if (ex.ErrorCode == "SignatureDoesNotMatch")
message += "\n\nThis can be caused by an invalid S3 secret key credential.";
throw new IOException(message);
}
catch (System.Net.WebException e) { throw new IOException(e.Message); }
}
开发者ID:modulexcite,项目名称:backer_upper,代码行数:35,代码来源:S3Backend.cs
示例4: ListFiles
public static IEnumerable<string> ListFiles(string bucketName, string accessKeyID, string secretAccessKey)
{
List<string> fileNames = new List<string>();
try
{
var s3Client = new AmazonS3Client(accessKeyID, secretAccessKey, Amazon.RegionEndpoint.USEast1);
ListObjectsRequest request = new ListObjectsRequest
{
BucketName = bucketName
};
while (request != null)
{
ListObjectsResponse response = s3Client.ListObjects(request);
foreach (S3Object entry in response.S3Objects)
{
fileNames.Add(entry.Key);
}
if (response.IsTruncated)
{
request.Marker = response.NextMarker;
}
else
{
request = null;
}
}
}
catch (Exception e)
{
}
return fileNames;
}
开发者ID:CJMarsland,项目名称:xaml-sdk,代码行数:35,代码来源:AmazonS3Utilities.cs
示例5: FileExists
/// <summary>Determine if our file already exists in the specified S3 bucket</summary>
/// <returns>True if the file already exists in the specified bucket</returns>
public bool FileExists(string fileKey)
{
bool retVal = false;
using (Client)
{
try
{
ListObjectsRequest request = new ListObjectsRequest
{
BucketName = BucketName
};
using (var response = Client.ListObjects(request))
{
foreach (var file in response.S3Objects)
{
//Project.Log(Level.Info, "File: " + file.Key);
if (file.Key.Equals(fileKey))
{
retVal = true;
}
}
}
}
catch (AmazonS3Exception ex)
{
ShowError(ex);
}
}
return retVal;
}
开发者ID:lfagan,项目名称:Amazon-AWS-NAnt-Tasks,代码行数:34,代码来源:S3CoreFileTask.cs
示例6: FileExists
/// <summary>Determine if our file already exists in the specified S3 bucket</summary>
/// <returns>True if the file already exists in the specified bucket</returns>
public bool FileExists(string fileKey)
{
using (Client)
{
try
{
ListObjectsRequest request = new ListObjectsRequest
{
BucketName = BucketName
};
using (var response = Client.ListObjects(request))
{
foreach (var file in response.S3Objects)
{
if (file.Key.Equals(fileKey))
{
return true;
}
}
}
}
catch (AmazonS3Exception ex)
{
ShowError(ex);
}
}
return false;
}
开发者ID:lfagan,项目名称:Amazon-AWS-NAnt-Tasks,代码行数:31,代码来源:S3CopyFileTask.cs
示例7: TestCleanup
public void TestCleanup()
{
try
{
var objRequest = new ListObjectsRequest()
{
BucketName = this.bucketName
};
using (var objResponse = client.ListObjects(objRequest))
{
var delRequest = new DeleteObjectsRequest()
{
BucketName = this.bucketName,
Quiet = true
};
delRequest.AddKeys(objResponse.S3Objects.Select(o => new KeyVersion(o.Key)).ToArray());
using (var delResponse = client.DeleteObjects(delRequest))
{
}
}
var deleteRequest = new DeleteBucketRequest()
{
BucketName = this.bucketName
};
using (var deleteResponse = client.DeleteBucket(deleteRequest)) { }
}
catch (Exception ex)
{
this.TestContext.WriteLine("Warning: Could not cleanup bucket: {0}. {1}", this.bucketName, ex);
}
}
开发者ID:pbutlerm,项目名称:dataservices-sdk-dotnet,代码行数:34,代码来源:FileAccessTests.cs
示例8: ListAsync
public async Task<IReadOnlyDictionary<string, string>> ListAsync(string name, CancellationToken cancellationToken)
{
var files = new Dictionary<string, string>();
var request = new ListObjectsRequest
{
BucketName = _pathManager.Bucket,
Prefix = _pathManager.GetTreeNamePrefix(name)
};
for (;;)
{
var response = await AmazonS3.ListObjectsAsync(request, cancellationToken).ConfigureAwait(false);
foreach (var s3Object in response.S3Objects)
{
var key = _pathManager.GetKeyFromTreeNamePath(name, s3Object.Key);
files[key] = s3Object.ETag;
}
if (!response.IsTruncated)
return files;
request.Marker = response.NextMarker;
}
}
开发者ID:henricj,项目名称:AwsDedupSync,代码行数:27,代码来源:S3Links.cs
示例9: ListAllObjectsAsync
public static async Task<IList<S3Object>> ListAllObjectsAsync(
this AmazonS3 client, ListObjectsRequest request, CancellationToken ct)
{
string token = null;
var result = new List<S3Object>();
do
{
var req = new ListObjectsRequest
{
BucketName = request.BucketName,
Delimiter = request.Delimiter,
InputStream = request.InputStream,
MaxKeys = request.MaxKeys,
Prefix = request.Prefix,
Marker = token
};
using (ListObjectsResponse response = await client.ListObjectsAsync(req).ConfigureAwait(false))
{
result.AddRange(response.S3Objects);
token = response.NextMarker;
}
} while (token != null && !ct.IsCancellationRequested);
return result;
}
开发者ID:glueckkanja,项目名称:yas4,代码行数:27,代码来源:AwsExtensionsAsync.cs
示例10: ListNames
public string[] ListNames()
{
ListObjectsRequest request = new ListObjectsRequest();
request.BucketName = BucketName;
// removed: using() / mh
ListObjectsResponse response = _client.ListObjects(request);
return response.S3Objects.Select(s3o => s3o.Key).ToArray();
}
开发者ID:TonyAbell,项目名称:spark,代码行数:9,代码来源:AmazonS3Storage.cs
示例11: Index
//public ActionResult Save() {
// var path = Request.QueryString["image"];
// if (!string.IsNullOrEmpty(path)) {
// using(var client = new WebClient()) {
// using(var stream = new MemoryStream(client.DownloadData(new Uri(path)))) {
// var request = new PutObjectRequest();
// request.WithBucketName(_settings.BucketName)
// .WithCannedACL(S3CannedACL.PublicRead)
// .WithContentType(MimeMapping.GetMimeMapping(path))
// .WithKey("Images/" + Request.QueryString["title"] + Path.GetExtension(path)).InputStream = stream;
// _client.PutObject(request);
// }
// }
// }
// return View();
//}
public ActionResult Index()
{
ViewBag.Class = "dashboard";
var request = new ListObjectsRequest { BucketName = _settings.BucketName };
var model = _client.ListObjects(request);
return View(model.S3Objects);
}
开发者ID:dasheddot,项目名称:BrickPile,代码行数:25,代码来源:LibraryController.cs
示例12: TestAllFilesExistAndModifiedInOutput
public void TestAllFilesExistAndModifiedInOutput()
{
try
{
Init();
ListObjectsRequest inputFileObjects;
String fileKey = null;
inputFileObjects = new ListObjectsRequest
{
BucketName = DataTransformer.InputBucketName
};
ListObjectsResponse listResponse;
do
{
listResponse = DataTransformer.s3ForStudentBuckets.ListObjects(inputFileObjects);
foreach (S3Object obj in listResponse.S3Objects)
{
fileKey = obj.Key;
GetObjectRequest request = new GetObjectRequest()
{
BucketName = DataTransformer.OutputBucketName,
Key = fileKey
};
GetObjectResponse response = DataTransformer.s3ForStudentBuckets.GetObject(request);
StreamReader reader = new StreamReader(response.ResponseStream);
string content = reader.ReadToEnd();
if(!content.Contains(DataTransformer.JsonComment))
{
Assert.Fail("Failure - Input file not transformed; output file does not contain JSON comment. " + fileKey);
}
}
// Set the marker property
inputFileObjects.Marker = listResponse.NextMarker;
} while (listResponse.IsTruncated);
}
catch (AmazonServiceException ase)
{
Console.WriteLine("Error Message: " + ase.Message);
Console.WriteLine("HTTP Status Code: " + ase.StatusCode);
Console.WriteLine("AWS Error Code: " + ase.ErrorCode);
Console.WriteLine("Error Type: " + ase.ErrorType);
Console.WriteLine("Request ID: " + ase.RequestId);
}
catch (AmazonClientException ace)
{
Console.WriteLine("Error Message: " + ace.Message);
}
}
开发者ID:honux77,项目名称:aws-training-demo,代码行数:56,代码来源:DataTransformerTests.cs
示例13: StateExists
public bool StateExists(string appId, string key)
{
var listObjectsRequest = new ListObjectsRequest
{
BucketName = ConfigurationManager.AppSettings["BucketName"],
Prefix = string.Format("{0}/{1}", appId, key),
};
var response = WebApiApplication.AmazonS3Client.ListObjects(listObjectsRequest);
return response.S3Objects.Count == 1;
}
开发者ID:kohashi,项目名称:photon.webhooks.turnbased.waws,代码行数:12,代码来源:Amazon.cs
示例14: Execute
/// <summary>
/// Executes the task.
/// </summary>
/// <returns>True if the task executed successfully, false otherwise.</returns>
public override bool Execute()
{
ListObjectsRequest request = new ListObjectsRequest()
.WithBucketName(BucketName)
.WithPrefix(this.Prefix)
.WithMaxKeys(1);
using (ListObjectsResponse response = Client.ListObjects(request))
{
Exists = response.S3Objects != null && response.S3Objects.Count > 0;
}
return true;
}
开发者ID:ChadBurggraf,项目名称:tasty,代码行数:18,代码来源:S3PrefixExists.cs
示例15: ExportAndImport
private static void ExportAndImport(string folder,CloudBlobContainer container, AmazonS3 s3)
{
var listRequest = new ListObjectsRequest{
BucketName = ConfigurationManager.AppSettings["S3Bucket"],
}.WithPrefix(folder);
Console.WriteLine("Fetching all S3 object in " + folder);
var s3response = s3.ListObjects(listRequest);
//Checking if container exists, and creating it if not
if (container.CreateIfNotExists()) {
Console.WriteLine("Creating the blob container");
}
foreach (var s3Item in s3response.S3Objects)
{
if (s3Item.Key == folder) {
continue;
}
if (s3Item.Key.EndsWith("/"))
{
ExportAndImport(s3Item.Key, container, s3);
continue;
}
Console.WriteLine("---------------------------------------------------");
var blockBlob = container.GetBlockBlobReference(s3Item.Key);
Console.WriteLine("Blob: " + blockBlob.Uri.AbsoluteUri);
var id = blockBlob.StartCopyFromBlob(new Uri("http://" + awsServiceUrl + "/" + s3Bucket + "/" + HttpUtility.UrlEncode(s3Item.Key)), null, null, null);
bool continueLoop = true;
while (continueLoop && id == string.Empty)
{
var copyState = blockBlob.CopyState;
if (copyState != null)
{
var percentComplete = copyState.BytesCopied / copyState.TotalBytes;
Console.WriteLine("Status of blob copy...." + copyState.Status + " " + copyState.TotalBytes + " of " + copyState.BytesCopied + "bytes copied. " + string.Format("{0:0.0%}", percentComplete));
if (copyState.Status != CopyStatus.Pending)
{
continueLoop = false;
}
}
System.Threading.Thread.Sleep(1000);
}
}
}
开发者ID:postback,项目名称:amazon-s3-to-azure-storage,代码行数:49,代码来源:Program.cs
示例16: DeleteContainerAsync
public async Task DeleteContainerAsync(string containerName)
{
var objectsRequest = new ListObjectsRequest
{
BucketName = _bucket,
Prefix = containerName,
MaxKeys = 100000
};
var keys = new List<KeyVersion>();
try
{
do
{
var objectsResponse = await _s3Client.ListObjectsAsync(objectsRequest);
keys.AddRange(objectsResponse.S3Objects
.Select(x => new KeyVersion() { Key = x.Key, VersionId = null }));
// If response is truncated, set the marker to get the next set of keys.
if (objectsResponse.IsTruncated)
{
objectsRequest.Marker = objectsResponse.NextMarker;
}
else
{
objectsRequest = null;
}
} while (objectsRequest != null);
if (keys.Count > 0)
{
var objectsDeleteRequest = new DeleteObjectsRequest()
{
BucketName = _bucket,
Objects = keys
};
await _s3Client.DeleteObjectsAsync(objectsDeleteRequest);
}
}
catch (AmazonS3Exception asex)
{
throw asex.ToStorageException();
}
}
开发者ID:2020IP,项目名称:TwentyTwenty.Storage,代码行数:47,代码来源:AmazonStorageProvider.cs
示例17: S3DeleteItemsFolder
public void S3DeleteItemsFolder(string bucketName, string serverFolder)
{
//ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingNetSDK.html
int count = 0;
using (var client = new AmazonS3Client(this.AcesssKey, this.SecretKey, this.Region))
{
ListObjectsRequest request = new ListObjectsRequest
{
BucketName = bucketName,
MaxKeys = 10,
Prefix = serverFolder
};
do
{
ListObjectsResponse response = client.ListObjects(request);
// Process response
foreach (S3Object entry in response.S3Objects)
{
if (entry.Key == serverFolder || entry.Key == string.Format("{0}/", serverFolder) || entry.Key == string.Format("/{0}", serverFolder))
continue; //Folder
count++;
//System.Diagnostics.Debug.WriteLine(string.Format("AwsS3 -- key = {0} size = {1} / {2} items read", entry.Key, entry.Size.ToString("#,##0"), count.ToString("#,##0")));
this.S3DeleteItem(bucketName, entry.Key);
Console.WriteLine(string.Format("{0} -- {1} items deleted", entry.Key, count.ToString("#,##0")));
}
// If response is truncated, set the marker to get the next
// set of keys.
if (response.IsTruncated)
{
request.Marker = response.NextMarker;
}
else
{
request = null;
}
} while (request != null);
}
}
开发者ID:educoutinho,项目名称:AmazonAwsS3Test,代码行数:46,代码来源:AwsClient.cs
示例18: DeleteAllBucketItems
public static void DeleteAllBucketItems(string bucketName)
{
using (var client = new AmazonS3Client(Settings.AccessKey, Settings.Secret))
{
var request = new ListObjectsRequest
{
BucketName = bucketName
};
var response = client.ListObjects(request);
foreach (var entry in response.S3Objects)
{
client.DeleteObject(bucketName, entry.Key);
}
}
}
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:17,代码来源:Repository.cs
示例19: GetFiles
public IEnumerable<FileData> GetFiles(string parentVirtualPath) {
var request = new ListObjectsRequest()
.WithBucketName(this.bucketName)
.WithPrefix(FixPathForS3(parentVirtualPath))
.WithDelimiter(@"/");
IEnumerable<FileData> files;
using (var response = this.s3.ListObjects(request)) {
files = response.S3Objects.Where(file => file.Size > 0).Select(file => new FileData {
VirtualPath = FixPathForN2(file.Key),
Name = file.Key.Substring(file.Key.LastIndexOf('/') + 1),
Length = file.Size,
Created = DateTime.Parse(file.LastModified),
Updated = DateTime.Parse(file.LastModified)
});
}
return files;
}
开发者ID:njmube,项目名称:N2.S3FileSystem,代码行数:18,代码来源:S3FileSystem.cs
示例20: DeleteBucketRecursive
/// <summary>
/// Deletes all keys in a given bucket, then deletes the bucket itself.
/// </summary>
/// <param name="client">The client to use.</param>
/// <param name="bucketName">The bucket to delete.</param>
public static void DeleteBucketRecursive(this AmazonS3 client, string bucketName)
{
while(true)
{
// attempt to delete the bucket
try
{
var deleteRequest = new DeleteBucketRequest()
{
BucketName = bucketName
};
using (var deleteResponse = client.DeleteBucket(deleteRequest))
{
// deletion was successful
return;
}
}
catch (AmazonS3Exception ex)
{
if (ex.ErrorCode != "BucketNotEmpty") throw ex;
}
var objRequest = new ListObjectsRequest()
{
BucketName = bucketName
};
using (var objResponse = client.ListObjects(objRequest))
{
var delRequest = new DeleteObjectsRequest()
{
BucketName = bucketName,
Quiet = true
};
// select the objects to delete (up to the supported limit of 1000)
var objToDelete = objResponse.S3Objects.Take(1000).Select(o => new KeyVersion(o.Key));
delRequest.AddKeys(objToDelete.ToArray());
using (var delResponse = client.DeleteObjects(delRequest))
{
}
}
}
}
开发者ID:pbutlerm,项目名称:dataservices-sdk-dotnet,代码行数:49,代码来源:Utility.cs
注:本文中的Amazon.S3.Model.ListObjectsRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论