Skip to content

Commit

Permalink
added ValidateData option to sample project
Browse files Browse the repository at this point in the history
  • Loading branch information
bezzad committed Dec 23, 2023
1 parent 04a38a1 commit 18f67ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Samples/Downloader.Sample/DownloadItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class DownloadItem
public string FolderPath { get => _folderPath ?? Path.GetDirectoryName(FileName); set => _folderPath = value; }
public string FileName { get; set; }
public string Url { get; set; }
public bool ValidateData { get; set; }
}
3 changes: 2 additions & 1 deletion src/Samples/Downloader.Sample/DownloadList.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[
{
"FileName": "D:\\TestDownload\\LocalFile10GB_Raw.dat",
"Url": "http://localhost:3333/dummyfile/file/size/10737418240"
"Url": "http://localhost:3333/dummyfile/file/size/10737418240",
"ValidateData": true
},
{
"FolderPath": "D:\\TestDownload",
Expand Down
17 changes: 7 additions & 10 deletions src/Samples/Downloader.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,11 @@ private static List<DownloadItem> GetDownloadItems()
{
List<DownloadItem> downloadList = File.Exists(DownloadListFile)
? JsonConvert.DeserializeObject<List<DownloadItem>>(File.ReadAllText(DownloadListFile))
: null;

if (downloadList == null)
{
downloadList = new List<DownloadItem> {
new DownloadItem {
FolderPath = Path.GetTempPath(), Url = "http://ipv4.download.thinkbroadband.com/100MB.zip"
}
};
}
: new List<DownloadItem>();

return downloadList;
}

private static async Task DownloadAll(IEnumerable<DownloadItem> downloadList, CancellationToken cancelToken)
{
foreach (DownloadItem downloadItem in downloadList)
Expand All @@ -140,6 +132,7 @@ private static async Task DownloadAll(IEnumerable<DownloadItem> downloadList, Ca
await DownloadFile(downloadItem).ConfigureAwait(false);
}
}

private static async Task<IDownloadService> DownloadFile(DownloadItem downloadItem)
{
CurrentDownloadConfiguration = GetDownloadConfiguration();
Expand All @@ -157,6 +150,7 @@ private static async Task<IDownloadService> DownloadFile(DownloadItem downloadIt

return CurrentDownloadService;
}

private static void WriteKeyboardGuidLines()
{
Console.Clear();
Expand Down Expand Up @@ -196,6 +190,7 @@ private static void OnDownloadStarted(object sender, DownloadStartedEventArgs e)
WriteKeyboardGuidLines();
ConsoleProgress = new ProgressBar(10000, $"Downloading {Path.GetFileName(e.FileName)} ", ProcessBarOption);
}

private static void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
ConsoleProgress?.Tick(10000);
Expand All @@ -221,13 +216,15 @@ private static void OnDownloadFileCompleted(object sender, AsyncCompletedEventAr
ChildConsoleProgresses.Clear();
ConsoleProgress?.Dispose();
}

private static void OnChunkDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
ChildProgressBar progress = ChildConsoleProgresses.GetOrAdd(e.ProgressId,
id => ConsoleProgress?.Spawn(10000, $"chunk {id}", ChildOption));
progress.Tick((int)(e.ProgressPercentage * 100));
var activeChunksCount = e.ActiveChunks; // Running chunks count
}

private static void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
ConsoleProgress.Tick((int)(e.ProgressPercentage * 100));
Expand Down

0 comments on commit 18f67ed

Please sign in to comment.