private async Task WriteFileToDiskParallelAsync(List <MarketoFile> fileResult, string saveRootPath, IProgress <ProgressReportModel> progress, CancellationToken cancellationToken) { ProgressReportModel report = new ProgressReportModel(); int processedNum = 0; var po = new ParallelOptions { CancellationToken = cancellationToken }; await Task.Run(() => { Parallel.ForEach(fileResult, po, (file) => { string fileName = Path.Combine(saveRootPath, file.Name); FileDownloader.DownFile(file.Url, fileName); if (po.CancellationToken.IsCancellationRequested) { return; } processedNum += 1; report.PercentageComplete = (processedNum * 100) / fileResult.Count; report.File = file; progress.Report(report); }); }); }
private static void WriteFileToDisk(GetFilesResponse fileResult, string saveRootPath) { if (fileResult?.Result == null) return; foreach (MarketoFile file in fileResult?.Result) { string fileName = Path.Combine(saveRootPath, file.Name); FileDownloader.DownFile(file.Url, fileName); Console.WriteLine(file?.Url); } }
private void WriteFileToDisk(string folderId, List <MarketoFile> fileResult, string saveRootPath, IProgress <ProgressReportModel> progress, CancellationToken cancellationToken) { ProgressReportModel report = new ProgressReportModel(); int processedNum = 0; foreach (var file in fileResult) { string fileName = Path.Combine(saveRootPath, file.Name); FileDownloader.DownFile(file.Url, fileName); cancellationToken.ThrowIfCancellationRequested(); processedNum += 1; report.PercentageComplete = (processedNum * 100) / fileResult.Count; report.File = file; progress.Report(report); } }