コード例 #1
0
ファイル: TransferInfo.cs プロジェクト: ChadBurggraf/sthreeql
 /// <summary>
 /// Initializes a new instance of the TransferInfo class.
 /// </summary>
 /// <param name="info">The existing <see cref="TransferInfo"/> to construct this instance from.</param>
 public TransferInfo(TransferInfo info)
 {
     if (info != null)
     {
         this.BytesTransferred = info.BytesTransferred;
         this.FileName = info.FileName;
         this.FileSize = info.FileSize;
     }
 }
コード例 #2
0
ファイル: RestoreTask.cs プロジェクト: ChadBurggraf/sthreeql
 /// <summary>
 /// Fires an event for this instance.
 /// </summary>
 /// <param name="handler">The event handler to fire.</param>
 /// <param name="info">The <see cref="TransferInfo"/> to create the event arguments with, if applicable.</param>
 private void Fire(EventHandler<RestoreDatabaseTargetEventArgs> handler, TransferInfo info)
 {
     if (handler != null)
     {
         handler(this, CreateEventArgs(this, info));
     }
 }
コード例 #3
0
ファイル: RestoreTask.cs プロジェクト: ChadBurggraf/sthreeql
        /// <summary>
        /// Downloads the latest backup set from the Aws service.
        /// </summary>
        /// <param name="compressor">The compresor to use when decompressing the downloaded file.</param>
        /// <returns>The path to the downloaded and decompressed backup file.</returns>
        public string DownloadBackup(ICompressor compressor)
        {
            S3Object latest = this.GetLatestBackupItem();
            string path = latest.Key;

            if (!String.IsNullOrEmpty(this.Target.AwsPrefix) && path.StartsWith(this.Target.AwsPrefix, StringComparison.OrdinalIgnoreCase))
            {
                path = path.Substring(this.Target.AwsPrefix.Length);

                if (path.StartsWith("/", StringComparison.Ordinal))
                {
                    path = path.Substring(1);
                }
            }

            path = Path.Combine(TempDir, path);
            string fileName = Path.GetFileName(path);

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            TransferInfo info = new TransferInfo()
            {
                BytesTransferred = 0,
                FileName = fileName,
                FileSize = 0
            };

            using (TransferUtility transfer = new TransferUtility(S3Client))
            {
                TransferUtilityDownloadRequest request = new TransferUtilityDownloadRequest()
                    .WithBucketName(AwsConfig.BucketName)
                    .WithFilePath(path)
                    .WithKey(latest.Key);

                request.WriteObjectProgressEvent += (sender, e) =>
                {
                    info.BytesTransferred = e.TransferredBytes;
                    info.FileSize = e.TotalBytes;
                    this.Fire(this.TransferProgress, new TransferInfo(info));
                };

                this.Fire(this.TransferStart, new TransferInfo(info));
                transfer.Download(request);
            }

            this.Fire(this.TransferComplete, new TransferInfo(info));

            this.Fire(this.DecompressStart);
            string decompressedPath = compressor.Decompress(path);
            this.Fire(this.DecompressComplete);

            File.Delete(path);

            return decompressedPath;
        }
コード例 #4
0
ファイル: RestoreTask.cs プロジェクト: ChadBurggraf/sthreeql
 /// <summary>
 /// Creates a new <see cref="RestoreDatabaseTargetEventArgs"/> instance.
 /// </summary>
 /// <param name="task">The <see cref="RestoreTask"/> to create the arguments with.</param>
 /// <param name="info">The <see cref="TransferInfo"/> to create the arguments with, if applicable.</param>
 /// <returns>The created event arguments.</returns>
 public static RestoreDatabaseTargetEventArgs CreateEventArgs(RestoreTask task, TransferInfo info)
 {
     return new RestoreDatabaseTargetEventArgs()
     {
         CatalogName = task.Target.CatalogName,
         Name = task.Target.Name,
         RestoreCatalogName = task.Target.RestoreCatalogName,
         RestorePath = task.Target.RestorePath,
         Transfer = info
     };
 }
コード例 #5
0
ファイル: BackupTask.cs プロジェクト: ChadBurggraf/sthreeql
        /// <summary>
        /// Uploads the backup set to Aws.
        /// </summary>
        /// <param name="path">The path of the compressed backup to upload.</param>
        public void UploadBackup(string path)
        {
            string fileName = Path.GetFileName(path);

            if (!String.IsNullOrEmpty(this.Target.AwsPrefix))
            {
                fileName = this.Target.AwsPrefix.EndsWith("/", StringComparison.Ordinal) ?
                    this.Target.AwsPrefix + fileName :
                    this.Target.AwsPrefix + "/" + fileName;
            }

            TransferInfo info = new TransferInfo()
            {
                BytesTransferred = 0,
                FileName = fileName,
                FileSize = new FileInfo(path).Length
            };

            using (TransferUtility transfer = new TransferUtility(S3Client))
            {
                TransferUtilityUploadRequest request = new TransferUtilityUploadRequest()
                    .WithCannedACL(S3CannedACL.Private)
                    .WithBucketName(AwsConfig.BucketName)
                    .WithFilePath(path)
                    .WithKey(fileName)
                    .WithTimeout(-1);

                request.UploadProgressEvent += (sender, e) =>
                {
                    info.BytesTransferred = e.TransferredBytes;
                    this.Fire(this.TransferProgress, new TransferInfo(info));
                };

                this.Fire(this.TransferStart, new TransferInfo(info));
                transfer.Upload(request);
            }

            this.Fire(this.TransferComplete, new TransferInfo(info));
        }
コード例 #6
0
ファイル: BackupTask.cs プロジェクト: ChadBurggraf/sthreeql
 /// <summary>
 /// Creates a new <see cref="DatabaseTargetEventArgs"/> instance.
 /// </summary>
 /// <param name="task">The <see cref="BackupTask"/> to create the arguments with.</param>
 /// <param name="info">The <see cref="TransferInfo"/> to create the arguments with, if applicable.</param>
 /// <returns>The created event arguments.</returns>
 public static DatabaseTargetEventArgs CreateEventArgs(BackupTask task, TransferInfo info)
 {
     return new DatabaseTargetEventArgs()
     {
         CatalogName = task.Target.CatalogName,
         Name = task.Target.Name,
         Transfer = info
     };
 }