本文整理汇总了C#中Amazon.S3.AmazonS3Client.BeginGetObject方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.BeginGetObject方法的具体用法?C# AmazonS3Client.BeginGetObject怎么用?C# AmazonS3Client.BeginGetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.BeginGetObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThreadedSyncAndScan
//.........这里部分代码省略.........
//get the delta list
foreach (KeyValuePair<string, SyncItem> kvp in serverhashes)
{
//ignore metadata.
if (kvp.Key == "__Server" || kvp.Key == "__DateGeneratedUTC")
{
;
}
else
{
//Queue downloads
if (!LocalData.HashList.ContainsKey(kvp.Key))
{
//downlaod files that dont exist.
FilesToDownload.Add(kvp.Key);
}
else
{
if (kvp.Value.Hash != LocalData.HashList[kvp.Key].Hash)
{
//download files the dont mathc the hash
FilesToDownload.Add(kvp.Key);
}
else
{
//if we get here the file exist and is right.
//get it out of the hash list so we dont delrte it.
LocalData.HashList.Remove(kvp.Key);
}
}
}
}
//Remove Files if set to
if (Settings.RemoveLocalFileIfNoRemoteFile)
{
AddTextToConsole("Generating list of local files to remove" + Environment.NewLine);
bool shouldDelete = true;
//ensure we didnt delte everything accidentally.
if (LocalData.HashList.Count > Settings.numFilesToRemoveWithNoWarning)
{
shouldDelete = false;
if (MessageBox.Show(LocalData.HashList.Count + " Files Are flagged for deletion." + Environment.NewLine + " Delete them?", "Continue?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
shouldDelete = true;
AddTextToConsole("Deleting Files" + Environment.NewLine);
}
else
{
AddTextToConsole("Files Will NOT be Removed" + Environment.NewLine);
}
}
//remove files
if (shouldDelete && LocalData.HashList.Count >0)
{
foreach (KeyValuePair<string, SyncItem> kvp in LocalData.HashList)
{
AddTextToConsole(" "+ kvp.Key + Environment.NewLine);
File.Delete(Settings.LocalDirectory + kvp.Key);
}
}
}
//DOWNLOADS
AddTextToConsole ("Need to download: " + FilesToDownload.Count +" from " +Settings.DownloadType +Environment.NewLine);
ErrorCount =0;
int tasklimit =10;
int nextFile =0;
GetObjectRequest request;
AmazonS3Client s3 = new AmazonS3Client (Settings.s3IDKey, Settings.s3SecretKey);
while(nextFile < FilesToDownload.Count || DownloadCount >0 ){
if(DownloadCount < tasklimit && nextFile<FilesToDownload.Count){
request = new GetObjectRequest();
request.BucketName = Settings.s3Bucket;
request.Key = FilesToDownload[nextFile].Substring (1);//use substring so we elminate the /
request.Timeout =1000;//wait 1 minute for a response.
AddTextToConsole(" "+(nextFile +1)+"/"+FilesToDownload.Count +" "+request.Key+Environment.NewLine);
s3.BeginGetObject(request,DownloadFile,s3);
nextFile++;
DownloadCount++;
worker.ReportProgress((int)(((float)nextFile) / ((float)FilesToDownload.Count) * 100.0f));
}
}
if (nextFile-ErrorCount < FilesToDownload.Count)
{
AddTextToConsole("WARNING: NOT ALL FILES WERE SUCCESSFULLY DOWNLOADED" + Environment.NewLine + Environment.NewLine);
}
AddTextToConsole("Download queue processed. Check log for any errors"+Environment.NewLine);
}
示例2: Main
//.........这里部分代码省略.........
try {
LocalData = new SyncList (Settings.LocalDirectory);
Console.WriteLine ("hashed:"+LocalData.HashList.Count);
LocalData.saveSyncList (Settings.HashCache);
} catch (Exception ex) {
Console.WriteLine("Problems readin' local directory. Oops\n"+ex.Message);
return;
}
List<string> FilesToDownload = new List<string> ();
//get the delta list
foreach(KeyValuePair<string,SyncItem> kvp in serverhashes){
//ignore metadata.
if (kvp.Key == "__Server" || kvp.Key == "__DateGeneratedUTC") {
;
} else {
//Queue downloads
if (! LocalData.HashList.ContainsKey (kvp.Key)){
//downlaod files that dont exist.
FilesToDownload.Add (kvp.Key);
Console.WriteLine ("New File: " + kvp.Key);
}
else{
if( kvp.Value.Hash != LocalData.HashList [kvp.Key].Hash) {
//download files the dont mathc the hash
FilesToDownload.Add (kvp.Key);
Console.WriteLine (String.Format ("hash mismatch: {0} ;local{2}, remote {1}", kvp.Key, kvp.Value.Hash, LocalData.HashList [kvp.Key].Hash));
}
else{
//if we get here the file exist and is right.
//get it out of the hash list so we dont delrte it.
bool okay = LocalData.HashList.Remove (kvp.Key);
//Console.WriteLine ("File OK: " + kvp.Key+ "okay"+okay);
}
}
}
}
//Remove Files if set to
if(Settings.RemoveLocalFileIfNoRemoteFile){
bool shouldDelete = true;
//ensure we didnt delte everything accidentally.
if (LocalData.HashList.Count > Settings.numFilesToRemoveWithNoWarning) {
shouldDelete = false;
Console.Write (LocalData.HashList.Count + " Files Are flagged for deletion, Remove them (Y/N)");
char key = (char)Console.Read ();
if( key == 'Y' || key == 'y'){
shouldDelete =true;
}
}
//remove files
if(shouldDelete){
foreach(KeyValuePair<string,SyncItem> kvp in LocalData.HashList){
File.Delete(Settings.LocalDirectory+kvp.Key);
Console.WriteLine ("removed: "+kvp.Key);
}
}
}
//DOWNLOADS
Console.WriteLine ("Need to download: " + FilesToDownload.Count +" from " +Settings.DownloadType );
int progress = 0;
int tasklimit =10;
int nextFile =0;
GetObjectRequest request;
AmazonS3Client s3 = new AmazonS3Client (Settings.s3IDKey, Settings.s3SecretKey);
while(nextFile < FilesToDownload.Count || DownloadCount >0 ){
if(DownloadCount < tasklimit && nextFile<FilesToDownload.Count){
request = new GetObjectRequest();
request.BucketName = Settings.s3Bucket;
request.Key = FilesToDownload[nextFile].Substring (1);//use substring so we elminate the /
request.Timeout =1000;//wait 1 minute for a response.
Console.WriteLine(nextFile+"/"+FilesToDownload.Count +" "+request.Key);
s3.BeginGetObject(request,DownloadFile,s3);
nextFile++;
DownloadCount++;
}
}
Console.WriteLine ("Downloaded "+(nextFile-ErrorCount)+"/"+ FilesToDownload.Count +" File");
if (nextFile-ErrorCount != FilesToDownload.Count) {
Console.WriteLine ("WARNING: NOT ALL FILES WERE SUCCESSFULLY DOWNLOADED");
Console.WriteLine (" YOU SHOULD RUN THIS TOOL AGAIN.");
}
Console.WriteLine("Press any key to close.");
Console.ReadKey();
}