Example #1
0
        public override void Execute()
        {
            string prefix = string.Empty;

            if (this._request.IsSetKeyPrefix())
            {
                prefix = this._request.KeyPrefix;
                prefix = prefix.Replace(@"\", "/");
                if (prefix.StartsWith("/"))
                {
                    prefix = prefix.Substring(1);
                }

                if (!prefix.EndsWith("/"))
                {
                    prefix += "/";
                }
            }

            string basePath      = new DirectoryInfo(this._request.Directory).FullName;
            string searchPattern = string.IsNullOrEmpty(this._request.SearchPattern) ? "*" : this._request.SearchPattern;

            string[] filePaths = Directory.GetFiles(basePath, searchPattern, this._request.SearchOption);
            this._totalNumberOfFiles = filePaths.Length;

            foreach (string filepath in filePaths)
            {
                this._currentFile = filepath;
                string key = filepath.Substring(basePath.Length);
                key = key.Replace(@"\", "/");
                if (key.StartsWith("/"))
                {
                    key = key.Substring(1);
                }

                key = prefix + key;

                TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest
                {
                    BucketName   = this._request.BucketName,
                    Key          = key,
                    FilePath     = filepath,
                    CannedACL    = this._request.CannedACL,
                    Timeout      = this._request.Timeout,
                    StorageClass = this._request.StorageClass,
                    ServerSideEncryptionMethod = this._request.ServerSideEncryptionMethod
                };
                // metadata
                foreach (string metadaKey in this._request.Metadata.AllKeys)
                {
                    var value = this._request.Metadata[metadaKey];
                    uploadRequest.WithMetadata(metadaKey, value);
                }
                uploadRequest.BeforeRequestEvent  += RequestEventHandler;
                uploadRequest.UploadProgressEvent += new EventHandler <UploadProgressArgs>(uploadProgressEventCallback);

                this._utility.Upload(uploadRequest);
                this._numberOfFilesUploaded++;
            }
        }
        public override void Execute()
        {
            string prefix = string.Empty;
            if (this._request.IsSetKeyPrefix())
            {
                prefix = this._request.KeyPrefix;
                prefix = prefix.Replace(@"\", "/");
                if (prefix.StartsWith("/"))
                    prefix = prefix.Substring(1);

                if (!prefix.EndsWith("/"))
                {
                    prefix += "/";
                }
            }

            string basePath = new DirectoryInfo(this._request.Directory).FullName;
            string searchPattern = string.IsNullOrEmpty(this._request.SearchPattern) ? "*" : this._request.SearchPattern;
            string[] filePaths = Directory.GetFiles(basePath, searchPattern, this._request.SearchOption);
            this._totalNumberOfFiles = filePaths.Length;

            foreach (string filepath in filePaths)
            {
                this._currentFile = filepath;
                string key = filepath.Substring(basePath.Length);
                key = key.Replace(@"\", "/");
                if(key.StartsWith("/"))
                    key = key.Substring(1);

                key = prefix + key;

                TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest
                {
                    BucketName = this._request.BucketName,
                    Key = key,
                    FilePath = filepath,
                    CannedACL = this._request.CannedACL,
                    Timeout = this._request.Timeout,
                    StorageClass = this._request.StorageClass,
                    ServerSideEncryptionMethod = this._request.ServerSideEncryptionMethod
                };
                // metadata
                foreach (string metadaKey in this._request.Metadata.AllKeys)
                {
                    var value = this._request.Metadata[metadaKey];
                    uploadRequest.WithMetadata(metadaKey, value);
                }
                uploadRequest.BeforeRequestEvent += RequestEventHandler;
                uploadRequest.UploadProgressEvent += new EventHandler<UploadProgressArgs>(uploadProgressEventCallback);

                this._utility.Upload(uploadRequest);
                this._numberOfFilesUploaded++;
            }
        }