/*******************************************************************************
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* AWS SDK for .NET
* API Version: 2006-03-01
*
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;
using Amazon.S3.Model;
using Amazon.Util;
using System.Globalization;
namespace Amazon.S3.Transfer
{
///
/// Request object for downloading a directory with the TransferUtility.
///
public class TransferUtilityDownloadDirectoryRequest
{
private string bucketName;
private string s3Directory;
private string localDirectory;
private bool downloadFilesConcurrently = false;
private DateTime? modifiedSinceDate;
private DateTime? unmodifiedSinceDate;
private DateTime? modifiedSinceDateUtc;
private DateTime? unmodifiedSinceDateUtc;
private bool disableSlashCorrection = false;
///
/// Gets or sets the name of the bucket.
///
///
/// The name of the bucket.
///
public string BucketName
{
get { return this.bucketName; }
set { this.bucketName = value; }
}
///
/// Gets whether or not the bucket name is set.
///
///
/// A value of true if the bucket name is set.
/// Otherwise, returns false.
///
internal bool IsSetBucketName()
{
return !System.String.IsNullOrEmpty(this.bucketName);
}
///
/// Gets or sets the local directory where objects from Amazon S3 will be downloaded.
/// If the directory doesn't exist, it will be created.
///
///
/// The local directory where objects from Amazon S3 will be downloaded.
///
public string LocalDirectory
{
get { return this.localDirectory; }
set { this.localDirectory = value; }
}
///
/// Gets whether or not the LocalDirectory property is set.
///
///
/// A value of true if LocalDirectory property is set.
/// Otherwise, returns false.
///
internal bool IsSetLocalDirectory()
{
return !System.String.IsNullOrEmpty(this.localDirectory);
}
///
/// Gets or sets the Amazon S3 directory to download from.
/// This is translated to a key prefix; keys that have this prefix will be
/// downloaded.
///
/// The TransferUtility will automatically add a / to the end when listing objects for
/// to be downloaded. This treats S3Directory field as a virtual S3 directory. In some use
/// cases the added / slash can be undesirable. To prevent the TransferUtility from adding
/// the / at the end set the DisableSlashCorrection property to true.
///
public string S3Directory
{
get { return this.s3Directory; }
set { this.s3Directory = value; }
}
///
/// Gets whether or not the S3Directory property is set.
///
///
/// A value of true if S3Directory property is set.
/// Otherwise, returns false.
///
internal bool IsSetS3Directory()
{
return !System.String.IsNullOrEmpty(this.s3Directory);
}
///
///
/// This property is deprecated. This property doesn't honor the DateTimeKind, please
/// use ModifiedSinceDateUtc instead.
///
/// Gets or sets the ModifiedSinceDate property.
/// Only objects that have been modified since this date will be
/// downloaded.
///
///
/// The ModifiedSinceDate property.
///
[Obsolete("This property doesn't honor the DateTimeKind, please use ModifiedSinceDateUtc instead.", false)]
public DateTime ModifiedSinceDate
{
get { return this.modifiedSinceDate.GetValueOrDefault(); }
set { this.modifiedSinceDate = value; }
}
///
/// Checks if ModifiedSinceDate property is set.
///
/// A value of true if ModifiedSinceDate property is set.
/// Otherwise, returns false.
internal bool IsSetModifiedSinceDate()
{
return modifiedSinceDate.HasValue;
}
///
/// Gets or sets the ModifiedSinceDateUtc property.
/// Only objects that have been modified since this date will be
/// downloaded.
///
///
/// The ModifiedSinceDateUtc property.
///
public DateTime ModifiedSinceDateUtc
{
get { return this.modifiedSinceDateUtc.GetValueOrDefault(); }
set { this.modifiedSinceDateUtc = value; }
}
///
/// Checks if ModifiedSinceDateUtc property is set.
///
/// A value of true if ModifiedSinceDateUtc property is set.
/// Otherwise, returns false.
internal bool IsSetModifiedSinceDateUtc()
{
return modifiedSinceDateUtc.HasValue;
}
///
///
/// This property is deprecated. This property doesn't honor the DateTimeKind, please
/// use UnmodifiedSinceDateUtc instead.
///
/// Gets or sets the UnmodifiedSinceDate property.
/// Only objects that have not been modified since this date will be downloaded.
///
///
/// The UnmodifiedSinceDate property.
///
[Obsolete("This property doesn't honor the DateTimeKind, please use UnmodifiedSinceDateUtc instead.", false)]
public DateTime UnmodifiedSinceDate
{
get { return this.unmodifiedSinceDate.GetValueOrDefault(); }
set { this.unmodifiedSinceDate = value; }
}
///
/// Checks if UnmodifiedSinceDate property is set.
///
/// true if UnmodifiedSinceDate property is set.
internal bool IsSetUnmodifiedSinceDate()
{
return unmodifiedSinceDate.HasValue;
}
///
/// Gets or sets the UnmodifiedSinceDateUtc property.
/// Only objects that have not been modified since this date will be downloaded.
///
///
/// The UnmodifiedSinceDateUtc property.
///
public DateTime UnmodifiedSinceDateUtc
{
get { return this.unmodifiedSinceDateUtc.GetValueOrDefault(); }
set { this.unmodifiedSinceDateUtc = value; }
}
///
/// Checks if UnmodifiedSinceDateUtc property is set.
///
/// true if UnmodifiedSinceDateUtc property is set.
internal bool IsSetUnmodifiedSinceDateUtc()
{
return unmodifiedSinceDateUtc.HasValue;
}
///
/// Gets or sets the DownloadFilesConcurrently property.
/// Specifies if multiple files will be downloaded concurrently.
/// The number of concurrent web requests used is controlled
/// by the TransferUtilityConfig.ConcurrencyLevel property.
///
#if BCL45 || NETSTANDARD
public
#else
internal
#endif
bool DownloadFilesConcurrently
{
get { return this.downloadFilesConcurrently; }
set { this.downloadFilesConcurrently = value; }
}
///
/// If this is set to true then the TransferUtility will not ensure the S3Directory property has a trailing / for a virtual S3 directory.
/// The default value is false.
///
public bool DisableSlashCorrection
{
get { return this.disableSlashCorrection; }
set { this.disableSlashCorrection = value; }
}
///
/// The event for DownloadedDirectoryProgressEvent notifications. All
/// subscribers will be notified when a new progress
/// event is raised.
///
/// The DownloadedDirectoryProgressEvent is fired as data
/// is downloaded from Amazon S3. The delegates attached to the event
/// will be passed information detailing how much data
/// has been downloaded as well as how much will be downloaded.
///
///
///
/// Subscribe to this event if you want to receive
/// DownloadedDirectoryProgressEvent notifications. Here is how:
/// 1. Define a method with a signature similar to this one:
///
/// private void displayProgress(object sender, DownloadDirectoryProgressArgs args)
/// {
/// Console.WriteLine(args);
/// }
///
/// 2. Add this method to the DownloadedDirectoryProgressEvent delegate's invocation list
///
/// TransferUtilityDownloadDirectoryRequest request = new TransferUtilityDownloadDirectoryRequest();
/// request.DownloadedDirectoryProgressEvent += displayProgress;
///
///
public event EventHandler DownloadedDirectoryProgressEvent;
internal void OnRaiseProgressEvent(DownloadDirectoryProgressArgs downloadDirectoryProgress)
{
AWSSDKUtils.InvokeInBackground(DownloadedDirectoryProgressEvent, downloadDirectoryProgress, this);
}
}
///
/// Encapsulates the information needed to provide
/// transfer progress to subscribers of the DownloadDirectory
/// event.
///
public class DownloadDirectoryProgressArgs : EventArgs
{
///
/// Constructs a new instance of DownloadDirectoryProgressArgs.
///
///
/// The number of files downloaded.
///
///
/// The total number of files to download.
///
///
/// The current file being downloaded
///
///
/// The number of transferred bytes for the current file.
///
///
/// The size of the current file in bytes.
///
public DownloadDirectoryProgressArgs(int numberOfFilesDownloaded, int totalNumberOfFiles,
string currentFile, long transferredBytesForCurrentFile, long totalNumberOfBytesForCurrentFile)
{
this.NumberOfFilesDownloaded = numberOfFilesDownloaded;
this.TotalNumberOfFiles = totalNumberOfFiles;
this.CurrentFile = currentFile;
this.TransferredBytesForCurrentFile = transferredBytesForCurrentFile;
this.TotalNumberOfBytesForCurrentFile = totalNumberOfBytesForCurrentFile;
}
///
/// Constructs a new instance of DownloadDirectoryProgressArgs.
///
///
/// The number of files downloaded.
///
///
/// The total number of files to download.
///
///
/// The bytes transferred across all files being downloaded.
///
///
/// The total number of bytes across all files being downloaded.
///
///
/// The current file being downloaded.
///
///
/// The number of transferred bytes for the current file.
///
///
/// The size of the current file in bytes.
///
public DownloadDirectoryProgressArgs(int numberOfFilesDownloaded, int totalNumberOfFiles, long transferredBytes, long totalBytes,
string currentFile, long transferredBytesForCurrentFile, long totalNumberOfBytesForCurrentFile)
{
this.NumberOfFilesDownloaded = numberOfFilesDownloaded;
this.TotalNumberOfFiles = totalNumberOfFiles;
this.TransferredBytes = transferredBytes;
this.TotalBytes = totalBytes;
this.CurrentFile = currentFile;
this.TransferredBytesForCurrentFile = transferredBytesForCurrentFile;
this.TotalNumberOfBytesForCurrentFile = totalNumberOfBytesForCurrentFile;
}
///
/// Gets or sets the total number of files.
///
/// The total number of files.
public int TotalNumberOfFiles { get; set; }
///
/// Gets or sets the number of files downloaded so far.
///
/// The number of files downloaded.
public int NumberOfFilesDownloaded { get; set; }
///
/// Gets or sets the total number of bytes across all files being downloaded.
///
/// The total number of bytes across all files being downloaded.
public long TotalBytes { get; set; }
///
/// Gets or sets the bytes transferred across all files being downloaded.
///
/// The bytes transferred across all files being downloaded.
public long TransferredBytes { get; set; }
#if BCL45
///
/// Gets or sets the current file being downloaded.
///
///
/// This property is only valid if DownloadDirectory is used without enabling concurrent file downloads (by default concurrent download is disabled).
/// If concurrent file downloads are enabled by setting TransferUtilityDownloadDirectoryRequest.DownloadFilesConcurrently to true, this property
/// will return null.
///
/// The current file being downloaded.
#else
///
/// Gets or sets the current file being downloaded.
///
/// The current file being downloaded.
#endif
public string CurrentFile { get; set; }
#if BCL45
///
/// Gets or sets the transferred bytes for the current file.
///
///
/// This property is only valid if DownloadDirectory is used without enabling concurrent file downloads (by default concurrent download is disabled).
/// If concurrent file downloads are enabled by setting TransferUtilityDownloadDirectoryRequest.DownloadFilesConcurrently to true, this property
/// will return 0.
///
/// The transferred bytes for the current file.
#else
///
/// Gets or sets the transferred bytes for the current file.
///
/// The transferred bytes for the current file.
#endif
public long TransferredBytesForCurrentFile { get; set; }
#if BCL45
///
/// Gets or sets the total number of bytes for the current file.
///
///
/// This property is only valid if DownloadDirectory is used without enabling concurrent file downloads (by default concurrent download is disabled).
/// If concurrent file downloads are enabled by setting TransferUtilityDownloadDirectoryRequest.DownloadFilesConcurrently to true, this property
/// will return 0.
///
/// The total number of bytes for the current file.
#else
///
/// Gets or sets the total number of bytes for the current file.
///
/// The total number of bytes for the current file.
#endif
public long TotalNumberOfBytesForCurrentFile { get; set; }
///
/// The string representation of this instance of DownloadDirectoryProgressArgs.
///
/// The string representation of this instance of DownloadDirectoryProgressArgs.
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "Total Files: {0}, Downloaded Files {1}, Total Bytes: {2}, Transferred Bytes: {3}",
this.TotalNumberOfFiles, this.NumberOfFilesDownloaded, this.TotalBytes, this.TransferredBytes);
}
}
}