public override void Start() { Assert.IsFalse(IsRunning); Assert.IsNotNull(Synchronization); Assert.IsNotNull(Synchronization.StorageAccount); Assert.AreEqual(Models.EStorageAccountType.AmazonS3, Synchronization.StorageAccountType); AmazonS3AccountRepository dao = new AmazonS3AccountRepository(); Models.AmazonS3Account s3account = dao.GetForReadOnly(Synchronization.StorageAccount.Id); // // Dispose and recycle previous objects, if needed. // if (TransferAgent != null) { TransferAgent.Dispose(); } if (TransferListControl != null) { TransferListControl.ClearTransfers(); } if (SyncAgent != null) { SyncAgent.Dispose(); } // // Setup agents. // AWSCredentials awsCredentials = new BasicAWSCredentials(s3account.AccessKey, s3account.SecretKey); TransferAgentOptions options = new TransferAgentOptions { UploadChunkSizeInBytes = Teltec.Everest.Settings.Properties.Current.UploadChunkSize * 1024 * 1024, }; TransferAgent = new S3TransferAgent(options, awsCredentials, s3account.BucketName, CancellationTokenSource.Token); TransferAgent.RemoteRootDir = TransferAgent.PathBuilder.CombineRemotePath("TELTEC_BKP", s3account.Hostname); RemoteObjects = new List <ListingObject>(4096); // Avoid small resizes without compromising memory. SyncAgent = new CustomSynchronizationAgent(TransferAgent); RegisterEventHandlers(Synchronization); Report.PlanType = "synchronization"; Report.PlanName = "No plan"; Report.BucketName = s3account.BucketName; Report.HostName = Synchronization.StorageAccount.Hostname; Report.SyncResults = SyncAgent.Results; // // Start the sync. // DoSynchronization(SyncAgent, Synchronization, Options); }
public override void Start() { Assert.IsFalse(IsRunning); Assert.IsNotNull(Restore); Assert.IsNotNull(Restore.RestorePlan.StorageAccount); Assert.AreEqual(Models.EStorageAccountType.AmazonS3, Restore.RestorePlan.StorageAccountType); AmazonS3AccountRepository dao = new AmazonS3AccountRepository(); Models.AmazonS3Account s3account = dao.GetForReadOnly(Restore.RestorePlan.StorageAccount.Id); // // Dispose and recycle previous objects, if needed. // if (TransferAgent != null) { TransferAgent.Dispose(); } if (TransferListControl != null) { TransferListControl.ClearTransfers(); } if (RestoreAgent != null) { RestoreAgent.Dispose(); } if (Versioner != null) { Versioner.Dispose(); } // // Setup agents. // AWSCredentials awsCredentials = new BasicAWSCredentials(s3account.AccessKey, s3account.SecretKey); TransferAgentOptions options = new TransferAgentOptions { UploadChunkSizeInBytes = Teltec.Everest.Settings.Properties.Current.UploadChunkSize * 1024 * 1024, }; TransferAgent = new S3TransferAgent(options, awsCredentials, s3account.BucketName, CancellationTokenSource.Token); TransferAgent.RemoteRootDir = TransferAgent.PathBuilder.CombineRemotePath("TELTEC_BKP", Restore.RestorePlan.StorageAccount.Hostname); RestoreAgent = new CustomRestoreAgent(TransferAgent); RestoreAgent.Results.Monitor = TransferListControl; Versioner = new RestoreFileVersioner(CancellationTokenSource.Token); RegisterResultsEventHandlers(Restore, RestoreAgent.Results); Report.PlanType = "restore"; Report.PlanName = Restore.RestorePlan.Name; Report.BucketName = s3account.BucketName; Report.HostName = Restore.RestorePlan.StorageAccount.Hostname; Report.TransferResults = RestoreAgent.Results; Helper = new BaseOperationHelper(Restore.RestorePlan); // // Start the restore. // DoRestore(RestoreAgent, Restore, Options); }
private void btnStart_Click(object sender, EventArgs e) { if (IsRunning) { return; } IsRunning = true; CancellationTokenSource = new CancellationTokenSource(); var options = new TransferAgentOptions { UploadChunkSizeInBytes = 1 * 1024 * 1024, }; string accessKey = txtAccessKey.Text.Trim(); string secretKey = txtSecretKey.Text.Trim(); string bucketName = txtBucketName.Text.Trim(); BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); string localFilePath = txtFilePath.Text; bool fileInformed = !string.IsNullOrEmpty(localFilePath); bool fileExists = fileInformed && FileManager.FileExists(localFilePath); if (!fileInformed || !fileExists) { string message = ""; if (!fileInformed) { message = "You have to inform a file for upload"; } else if (!fileExists) { message = string.Format("The informed file does not exist: {0}", localFilePath); } MessageBox.Show(message, "Oops!", MessageBoxButtons.OK, MessageBoxIcon.Error); IsRunning = false; return; } #if true string remoteFilePath = typeof(UploadPerfTestControl).Name + ".DELETE_ME"; #else S3PathBuilder pathBuilder = new S3PathBuilder(); string remoteFilePath = pathBuilder.BuildRemotePath(localFilePath); #endif long fileSize = FileManager.UnsafeGetFileSize(localFilePath); BlockPerfStats stats = new BlockPerfStats(); S3TransferAgent xferAgent = new S3TransferAgent(options, credentials, bucketName, CancellationTokenSource.Token); xferAgent.UploadFileStarted += (object sender1, TransferFileProgressArgs e1) => { stats.Begin(); }; xferAgent.UploadFileCanceled += (object sender1, TransferFileProgressArgs e1) => { stats.End(); string message = "Canceled file upload"; MessageBox.Show(message, "Transfer canceled", MessageBoxButtons.OK, MessageBoxIcon.Information); }; xferAgent.UploadFileFailed += (object sender1, TransferFileProgressArgs e1) => { stats.End(); string message = string.Format("Failed to upload file: {0}\n{1}", e1.Exception.GetType().Name, e1.Exception.Message); MessageBox.Show(message, "Transfer failed", MessageBoxButtons.OK, MessageBoxIcon.Error); }; xferAgent.UploadFileCompleted += (object sender1, TransferFileProgressArgs e1) => { stats.End(); string message = string.Format( "Took {0} to upload {1}", TimeSpanUtils.GetReadableTimespan(stats.Duration), FileSizeUtils.FileSizeToString(fileSize) ); MessageBox.Show(message, "Transfer completed", MessageBoxButtons.OK, MessageBoxIcon.Information); }; //xferAgent.UploadFileProgress += (object sender1, TransferFileProgressArgs e1) => //{ // // ... //}; xferAgent.UploadFile(localFilePath, remoteFilePath, null); IsRunning = false; }
private async Task <List <string> > RetrieveAccountConfigurations() { // Renew cancellation token if was already used. if (CancellationTokenSource.IsCancellationRequested) { CancellationTokenSource.Dispose(); CancellationTokenSource = new CancellationTokenSource(); } // // Setup agents. // AWSCredentials awsCredentials = new BasicAWSCredentials(_account.AccessKey, _account.SecretKey); TransferAgentOptions options = new TransferAgentOptions(); ITransferAgent transferAgent = new S3TransferAgent(options, awsCredentials, _account.BucketName, CancellationTokenSource.Token); transferAgent.RemoteRootDir = transferAgent.PathBuilder.CombineRemotePath("TELTEC_BKP"); List <string> remoteObjects = new List <string>(16); // Avoid small resizes without compromising memory. // Register event handlers. transferAgent.ListingProgress += (object sender2, ListingProgressArgs e2) => { foreach (var obj in e2.Objects) { string[] parts = obj.Key.Split(S3PathBuilder.RemoteDirectorySeparatorChar); int count = parts.Length; if (count > 2) { remoteObjects.Add(parts[count - 2]); } } }; transferAgent.ListingFailed += (object sender2, ListingProgressArgs e2) => { //var message = string.Format("Failed: {0}", e2.Exception != null ? e2.Exception.Message : "Unknown reason"); //logger.Warn(message); }; try { Task task = Task.Run(() => { transferAgent.List(transferAgent.RemoteRootDir, false, null); }); await task; } catch (OperationCanceledException) { throw; } catch (Exception) { throw; } finally { } return(remoteObjects); }