Skip to content

Commit

Permalink
Merge pull request #47 from kerrlabajo/feat/download
Browse files Browse the repository at this point in the history
Download Feature
  • Loading branch information
kerrlabajo authored May 12, 2024
2 parents 40096d1 + 1090101 commit b0c06b6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
43 changes: 27 additions & 16 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 39 additions & 3 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,12 +595,17 @@ private async void btnFetchOutput_Click(object sender, EventArgs e)
{
outputListComboBox.Items.Clear();
outputKey = $"users/{USERNAME}/training-jobs/{jobName[0]}/output/output.tar.gz";

outputListComboBox.SelectedText = jobName[1];
foreach (var obj in jobName)
{
outputListComboBox.Items.Add(obj);
}
}
else
{
outputListComboBox.Items.Add("No items");
btnDownloadModel.Enabled = false;
}
}
catch (Exception ex)
{
Expand All @@ -622,7 +627,7 @@ private void outputListComboBox_SelectedValueChanged(object sender, EventArgs e)
{
string trainingJobOuputs = outputListComboBox.GetItemText(outputListComboBox.SelectedItem);
outputKey = $"users/{USERNAME}/training-jobs/{trainingJobOuputs}/output/output.tar.gz";
modelKey = $"users/ {USERNAME} /training-jobs/{trainingJobOuputs}/output/model.tar.gz";
modelKey = $"users/{USERNAME}/training-jobs/{trainingJobOuputs}/output/model.tar.gz";
btnDownloadModel.Enabled = true;
}
else
Expand Down Expand Up @@ -944,6 +949,33 @@ public void UpdateTrainingStatus(string status, string description)
MessageBox.Show($"Error: {ex.Message}");
}
}
public void UpdateDownloadStatus(int percentage)
{
try
{
if (this.InvokeRequired)
{
if (percentage >= downloadProgressBar.Minimum && percentage <= downloadProgressBar.Maximum)
{
this.Invoke(new Action(() => UpdateDownloadStatus(percentage)));
return;
}
}

downloadProgressBar.Value = percentage;

if(percentage >= 100)
downloadProgressBar.Value = 0;
}
catch (ObjectDisposedException)
{
Console.WriteLine("Main form is closed. Cannot update download progress bar.");
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}");
}
}

public void DisplayLogMessage(string logMessage)
{
Expand Down Expand Up @@ -1011,7 +1043,7 @@ private async void btnFetchDatasets_Click(object sender, EventArgs e)
{
List<string> datasets = await AWS_Helper.GetAvailableDatasetsList(s3Client, SAGEMAKER_BUCKET);

if (datasets != null)
if (datasets != null && datasets.Count > 0)
{
datasetListComboBox.Items.Clear();

Expand All @@ -1020,6 +1052,10 @@ private async void btnFetchDatasets_Click(object sender, EventArgs e)
datasetListComboBox.Items.Add(obj);
}
}
else
{
datasetListComboBox.Items.Add("No items");
}
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions Functions/AWS_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public static async Task<List<string>> GetTrainingJobOutputList(AmazonS3Client s
var response = await s3Client.ListObjectsV2Async(new ListObjectsV2Request
{
BucketName = bucketName,
Prefix = "training-jobs"
Prefix = $"users/{UserConnectionInfo.UserName}/training-jobs",
});

return response.S3Objects
.Select(o => new { Key = o.Key.Split('/')[1], Date = ExtractDateFromKey(o.Key) })
.Select(o => new { Key = o.Key.Split('/')[3], Date = ExtractDateFromKey(o.Key) })
.OrderByDescending(o => o.Date)
.Select(o => o.Key)
.Distinct()
Expand Down
4 changes: 3 additions & 1 deletion Functions/FileTransferUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ private static void ConfigureProgressTracking(TransferUtilityDownloadRequest dow

downloadRequest.WriteObjectProgressEvent += (sender, args) =>
{
int percentage = (int)(args.TransferredBytes * 100 / args.TotalBytes);
int percentage = args.PercentDone;
if (!cancellationToken.IsCancellationRequested)
{
UIUpdater.UpdateTrainingStatus($"Downloading Files from S3", $"Downloading {args.TransferredBytes}/{args.TotalBytes} - {percentage}%");

UIUpdater.UpdateDownloadStatus(percentage);
}

};
Expand Down
1 change: 1 addition & 0 deletions Functions/IUIUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public interface IUIUpdater
void UpdateTrainingStatus(string status, string description);
void DisplayLogMessage(string logMessage);
string ConvertAnsiToRtf(string ansiText);
void UpdateDownloadStatus(int percentage);
}
}

0 comments on commit b0c06b6

Please sign in to comment.