示例#1
0
        private void UpdateDuration(SyncOperationStatus status)
        {
            Assert.IsNotNull(RunningOperation);
            var duration = !status.IsEnded() || !RunningOperation.FinishedAt.HasValue
                                ? DateTime.UtcNow - RunningOperation.StartedAt.Value
                                : RunningOperation.FinishedAt.Value - RunningOperation.StartedAt.Value;

            lblDuration.Text = TimeSpanUtils.GetReadableTimespan(duration);
        }
示例#2
0
        private void LogEnd()
        {
            logger.Info(
#if DEBUG
                "{0}:{1}:{2} - ENDED {3} - TOOK {4}",
#else
                "{2} - ENDED {3} - TOOK {4}",
#endif
                SourceFilePath, SourceLineNumberCreated, MemberName, Identifier,
                TimeSpanUtils.GetReadableTimespan(Duration));
        }
示例#3
0
        private void UpdateDuration(Commands.OperationStatus status)
        {
            // Prevent a NPE when accessing `CurrentOperation.StartedAt` below.
            if (!CurrentOperation.GotInitialInfo)
            {
                return;
            }

            // Calculate duration.
            var duration = !status.IsEnded() || !CurrentOperation.FinishedAt.HasValue
                                ? DateTime.UtcNow - CurrentOperation.StartedAt.Value
                                : CurrentOperation.FinishedAt.Value - CurrentOperation.StartedAt.Value;

            lblDuration.Text = TimeSpanUtils.GetReadableTimespan(duration);
        }
示例#4
0
        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;
        }