コード例 #1
0
        /// <summary>
        /// Downloads a collection of files from S3 and writes ithem to the specified files.
        /// </summary>
        /// <param name="paths">The paths to upload.</param>
        ///  <param name="settings">The <see cref="SyncSettings"/> required to download from Amazon S3.</param>
        public void Download(IList <SyncPath> paths, SyncSettings settings)
        {
            foreach (SyncPath path in paths)
            {
                try
                {
                    DownloadSettings copied = new DownloadSettings()
                    {
                        WorkingDirectory = settings.WorkingDirectory,

                        AccessKey   = settings.AccessKey,
                        SecretKey   = settings.SecretKey,
                        Credentials = settings.Credentials,

                        Region     = settings.Region,
                        BucketName = settings.BucketName,

                        EncryptionMethod = settings.EncryptionMethod,
                        EncryptionKey    = settings.EncryptionKey,
                        EncryptionKeyMD5 = settings.EncryptionKeyMD5
                    };

                    this.Download(path.Path, path.Key, "", copied);
                }
                catch (Exception ex)
                {
                    _Log.Error(ex.Message);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of the <see cref="DownloadSettings" /> class with the current settings.
        /// </summary>
        public DownloadSettings Copy()
        {
            DownloadSettings copy = this.CopyS3Settings(new DownloadSettings());

            copy.ModifiedDate = this.ModifiedDate;

            return(copy);
        }
コード例 #3
0
        /// <summary>
        /// Specifies the date the file was last modified
        /// </summary>
        /// <param name="settings">The Download settings.</param>
        /// <param name="modifiedDate">The modified date.</param>
        /// <returns>The same <see cref="DownloadSettings"/> instance so that multiple calls can be chained.</returns>
        public static DownloadSettings SetModifiedDate(this DownloadSettings settings, DateTime modifiedDate)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.ModifiedDate = modifiedDate;
            return(settings);
        }
コード例 #4
0
        /// <summary>
        /// Opens a stream of the content from Amazon S3
        /// </summary>
        /// <param name="key">The key under which the Amazon S3 object is stored.</param>
        /// <param name="version">The identifier for the specific version of the object to be downloaded, if required.</param>
        /// <param name="settings">The <see cref="DownloadSettings"/> required to download from Amazon S3.</param>
        /// <returns>A stream.</returns>
        public Stream Open(string key, string version, DownloadSettings settings)
        {
            TransferUtility utility = this.GetUtility(settings);
            TransferUtilityOpenStreamRequest request = this.CreateOpenRequest(settings);

            request.Key = key;
            if (!String.IsNullOrEmpty(version))
            {
                request.VersionId = version;
            }

            _Log.Verbose("Opening stream {0} from bucket {1}...", key, settings.BucketName);
            return(utility.OpenStream(request));
        }
コード例 #5
0
        /// <summary>
        /// Get the byte array of the content from Amazon S3
        /// </summary>
        /// <param name="key">The S3 object key.</param>
        /// <param name="version">The S3 object version.</param>
        /// <param name="settings">The download settings.</param>
        /// <returns>A byte array.</returns>
        public byte[] GetBytes(string key, string version, DownloadSettings settings)
        {
            byte[] data;

            using (Stream input = this.Open(key, version, settings))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    input.CopyTo(ms);
                    data = ms.ToArray();
                }

                input.Close();
            }

            return(data);
        }
コード例 #6
0
        private TransferUtilityOpenStreamRequest CreateOpenRequest(DownloadSettings settings)
        {
            TransferUtilityOpenStreamRequest request = new TransferUtilityOpenStreamRequest();

            request.BucketName = settings.BucketName;

            request.ServerSideEncryptionCustomerProvidedKey    = settings.EncryptionKey;
            request.ServerSideEncryptionCustomerProvidedKeyMD5 = settings.EncryptionKeyMD5;
            request.ServerSideEncryptionCustomerMethod         = settings.EncryptionMethod;

            if (!String.IsNullOrEmpty(settings.EncryptionKey))
            {
                request.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256;
            }

            request.ModifiedSinceDate = settings.ModifiedDate;

            return(request);
        }
コード例 #7
0
        /// <summary>
        /// Downloads the content from Amazon S3 and writes it to the specified file.
        /// </summary>
        /// <param name="filePath">The file path of the file to upload.</param>
        /// <param name="key">The key under which the Amazon S3 object is stored.</param>
        /// <param name="version">The identifier for the specific version of the object to be downloaded, if required.</param>
        /// <param name="settings">The <see cref="DownloadSettings"/> required to download from Amazon S3.</param>
        public void Download(FilePath filePath, string key, string version, DownloadSettings settings)
        {
            TransferUtility utility = this.GetUtility(settings);
            TransferUtilityDownloadRequest request = this.CreateDownloadRequest(settings);

            this.SetWorkingDirectory(settings);
            string fullPath = filePath.MakeAbsolute(settings.WorkingDirectory).FullPath;

            request.FilePath = fullPath;
            request.Key      = key;

            if (!String.IsNullOrEmpty(version))
            {
                request.VersionId = version;
            }

            request.WriteObjectProgressEvent += new EventHandler <WriteObjectProgressArgs>(this.WriteObjectProgressEvent);

            _Log.Verbose("Downloading file {0} from bucket {1}...", key, settings.BucketName);
            utility.Download(request);
        }
コード例 #8
0
ファイル: S3Aliases.cs プロジェクト: kcamp/Cake.AWS.S3
 public static async Task<byte[]> GetS3Bytes(this ICakeContext context, string key, DownloadSettings settings)
 {
     return await context.GetS3Bytes(key, "", settings);
 }
コード例 #9
0
ファイル: S3Aliases.cs プロジェクト: kcamp/Cake.AWS.S3
 public static async Task<byte[]> GetS3Bytes(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     return await context.CreateManager().GetBytes(key, version, settings);
 }
コード例 #10
0
ファイル: S3Aliases.cs プロジェクト: kcamp/Cake.AWS.S3
 public static async Task S3Download(this ICakeContext context, FilePath filePath, string key, DownloadSettings settings)
 {
     await context.CreateManager().Download(filePath, key, "", settings);
 }
コード例 #11
0
ファイル: S3Aliases.cs プロジェクト: kcamp/Cake.AWS.S3
 public static async Task<Stream> S3Open(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     return await context.CreateManager().Open(key, version, settings);
 }
コード例 #12
0
 public static byte[] GetS3Bytes(this ICakeContext context, string key, DownloadSettings settings)
 {
     return(context.GetS3Bytes(key, "", settings));
 }
コード例 #13
0
ファイル: S3Manager.cs プロジェクト: SharpeRAD/Cake.AWS.S3
            /// <summary>
            /// Downloads a collection of files from S3 and writes ithem to the specified files.
            /// </summary>
            /// <param name="paths">The paths to upload.</param>
            ///  <param name="settings">The <see cref="SyncSettings"/> required to download from Amazon S3.</param>
            public void Download(IList<SyncPath> paths, SyncSettings settings)
            {
                foreach(SyncPath path in paths)
                {
                    try
                    {
                        DownloadSettings copied = new DownloadSettings()
                        {
                            WorkingDirectory = settings.WorkingDirectory,

                            AccessKey = settings.AccessKey,
                            SecretKey = settings.SecretKey,
                            Credentials = settings.Credentials,

                            Region = settings.Region,
                            BucketName = settings.BucketName,

                            EncryptionMethod = settings.EncryptionMethod,
                            EncryptionKey = settings.EncryptionKey,
                            EncryptionKeyMD5 = settings.EncryptionKeyMD5
                        };

                        this.Download(path.Path, path.Key, "", copied);
                    }
                    catch (Exception ex)
                    {
                        _Log.Error(ex.Message);
                    }
                }
            }
コード例 #14
0
 public static string GetS3String(this ICakeContext context, string key, DownloadSettings settings)
 {
     return(context.GetS3String(key, "", settings));
 }
コード例 #15
0
 public static void S3Download(this ICakeContext context, FilePath filePath, string key, string version, DownloadSettings settings)
 {
     context.CreateManager().Download(filePath, key, version, settings);
 }
コード例 #16
0
ファイル: S3Aliases.cs プロジェクト: SharpeRAD/Cake.AWS.S3
 public static string GetS3String(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     byte[] bytes = context.CreateManager().GetBytes(key, version, settings);
     
     if (bytes != null)
     {
         return Encoding.UTF8.GetString(bytes);
     }
     else
     {
         return "";
     }
 }
コード例 #17
0
ファイル: S3Aliases.cs プロジェクト: SharpeRAD/Cake.AWS.S3
 public static string GetS3String(this ICakeContext context, string key, DownloadSettings settings)
 {
     return context.GetS3String(key, "", settings);
 }
コード例 #18
0
ファイル: S3Manager.cs プロジェクト: SharpeRAD/Cake.AWS.S3
            /// <summary>
            /// Get the byte array of the content from Amazon S3
            /// </summary>
            /// <param name="key">The S3 object key.</param>
            /// <param name="version">The S3 object version.</param>
            /// <param name="settings">The download settings.</param>
            /// <returns>A byte array.</returns>
            public byte[] GetBytes(string key, string version, DownloadSettings settings)
            {
                byte[] data;

                using (Stream input = this.Open(key, version, settings))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        input.CopyTo(ms);
                        data = ms.ToArray();
                    }

                    input.Close();
                }

                return data;
            }
コード例 #19
0
ファイル: S3Manager.cs プロジェクト: SharpeRAD/Cake.AWS.S3
            /// <summary>
            /// Opens a stream of the content from Amazon S3
            /// </summary>
            /// <param name="key">The key under which the Amazon S3 object is stored.</param>
            /// <param name="version">The identifier for the specific version of the object to be downloaded, if required.</param>
            /// <param name="settings">The <see cref="DownloadSettings"/> required to download from Amazon S3.</param>
            /// <returns>A stream.</returns>
            public Stream Open(string key, string version, DownloadSettings settings)
            {
                TransferUtility utility = this.GetUtility(settings);
                TransferUtilityOpenStreamRequest request = this.CreateOpenRequest(settings);

                request.Key = key;
                if (!String.IsNullOrEmpty(version))
                {
                    request.VersionId = version;
                }

                _Log.Verbose("Opening stream {0} from bucket {1}...", key, settings.BucketName);
                return utility.OpenStream(request);
            }
コード例 #20
0
ファイル: S3Manager.cs プロジェクト: SharpeRAD/Cake.AWS.S3
            /// <summary>
            /// Downloads the content from Amazon S3 and writes it to the specified file.
            /// </summary>
            /// <param name="filePath">The file path of the file to upload.</param>
            /// <param name="key">The key under which the Amazon S3 object is stored.</param>
            /// <param name="version">The identifier for the specific version of the object to be downloaded, if required.</param>
            /// <param name="settings">The <see cref="DownloadSettings"/> required to download from Amazon S3.</param>
            public void Download(FilePath filePath, string key, string version, DownloadSettings settings)
            {
                TransferUtility utility = this.GetUtility(settings);
                TransferUtilityDownloadRequest request = this.CreateDownloadRequest(settings);

                this.SetWorkingDirectory(settings);
                string fullPath = filePath.MakeAbsolute(settings.WorkingDirectory).FullPath;

                request.FilePath = fullPath;
                request.Key = key;

                if (!String.IsNullOrEmpty(version))
                {
                    request.VersionId = version;
                }

                request.WriteObjectProgressEvent += new EventHandler<WriteObjectProgressArgs>(this.WriteObjectProgressEvent);

                _Log.Verbose("Downloading file {0} from bucket {1}...", key, settings.BucketName);
                utility.Download(request);
            }
コード例 #21
0
ファイル: S3Aliases.cs プロジェクト: kcamp/Cake.AWS.S3
 public static async Task<string> GetS3String(this ICakeContext context, string key, DownloadSettings settings)
 {
     return await context.GetS3String(key, "", settings);
 }
コード例 #22
0
ファイル: S3Aliases.cs プロジェクト: SharpeRAD/Cake.AWS.S3
 public static Stream S3Open(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     return context.CreateManager().Open(key, version, settings);
 }
コード例 #23
0
ファイル: S3Aliases.cs プロジェクト: kcamp/Cake.AWS.S3
 public static async Task<string> GetS3String(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     byte[] bytes = await context.CreateManager().GetBytes(key, version, settings);
     
     if (bytes != null)
     {
         return Encoding.UTF8.GetString(bytes);
     }
     else
     {
         return "";
     }
 }
コード例 #24
0
ファイル: S3Aliases.cs プロジェクト: SharpeRAD/Cake.AWS.S3
 public static byte[] GetS3Bytes(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     return context.CreateManager().GetBytes(key, version, settings);
 }
コード例 #25
0
 public static Stream S3Open(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     return(context.CreateManager().Open(key, version, settings));
 }
コード例 #26
0
ファイル: S3Aliases.cs プロジェクト: SharpeRAD/Cake.AWS.S3
 public static byte[] GetS3Bytes(this ICakeContext context, string key, DownloadSettings settings)
 {
     return context.GetS3Bytes(key, "", settings);
 }
コード例 #27
0
 public static byte[] GetS3Bytes(this ICakeContext context, string key, string version, DownloadSettings settings)
 {
     return(context.CreateManager().GetBytes(key, version, settings));
 }
コード例 #28
0
ファイル: S3Manager.cs プロジェクト: SharpeRAD/Cake.AWS.S3
            private TransferUtilityOpenStreamRequest CreateOpenRequest(DownloadSettings settings)
            {
                TransferUtilityOpenStreamRequest request = new TransferUtilityOpenStreamRequest();

                request.BucketName = settings.BucketName;

                request.ServerSideEncryptionCustomerProvidedKey = settings.EncryptionKey;
                request.ServerSideEncryptionCustomerProvidedKeyMD5 = settings.EncryptionKeyMD5;
                request.ServerSideEncryptionCustomerMethod = settings.EncryptionMethod;

                if (!String.IsNullOrEmpty(settings.EncryptionKey))
                {
                    request.ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256;
                }

                request.ModifiedSinceDate = settings.ModifiedDate;

                return request;
            }
コード例 #29
0
        public static string GetS3String(this ICakeContext context, string key, string version, DownloadSettings settings)
        {
            byte[] bytes = context.CreateManager().GetBytes(key, version, settings);

            if (bytes != null)
            {
                return(Encoding.UTF8.GetString(bytes));
            }
            else
            {
                return("");
            }
        }
コード例 #30
0
ファイル: S3Aliases.cs プロジェクト: SharpeRAD/Cake.AWS.S3
 public static void S3Download(this ICakeContext context, FilePath filePath, string key, string version, DownloadSettings settings)
 {
     context.CreateManager().Download(filePath, key, version, settings);
 }