private bool ParseS3Key(string inKey, out Models.EntryType outType, out string outPath, out string outVersion) { outType = Models.EntryType.FILE_VERSION; S3PathBuilder builder = new S3PathBuilder(); builder.LocalRootDirectory = this.LocalRootDirectory; builder.RemoteRootDirectory = this.RemoteRootDirectory; outPath = builder.BuildLocalPath(inKey, out outVersion); return(true); }
public void TestBuildLocalPath() { S3PathBuilder pathBuilder = new S3PathBuilder(); pathBuilder.RemoteRootDirectory = "TELTEC_BKP/HOSTNAME"; pathBuilder.LocalRootDirectory = null; string version = null; string localPath = null; localPath = pathBuilder.BuildLocalPath("TELTEC_BKP/HOSTNAME/c:/teste/a.txt:/20150701143445/a.txt", out version); Assert.AreEqual(localPath, @"c:\teste\a.txt"); Assert.AreEqual(version, @"20150701143445"); localPath = pathBuilder.BuildLocalPath("TELTEC_BKP/HOSTNAME/c:/a.txt:/20150701143446/a.txt", out version); Assert.AreEqual(localPath, @"c:\a.txt"); Assert.AreEqual(version, @"20150701143446"); localPath = pathBuilder.BuildLocalPath("TELTEC_BKP/HOSTNAME/c:/teste/sub_teste/a.txt:/20150701143447/a.txt", out version); Assert.AreEqual(localPath, @"c:\teste\sub_teste\a.txt"); Assert.AreEqual(version, @"20150701143447"); }
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; }