private async void OnDownloadCourseAsync()
        {
            try
            {
                IsDownloading      = true;
                _cancellationToken = new CancellationTokenSource();

                var downloadingProgress = new Progress <CourseDownloadingProgressArguments>();
                downloadingProgress.ProgressChanged += (s, e) =>
                {
                    DownloadingProgress = e.ClipProgress;
                    CurrentAction       = e.CurrentAction;
                    DownloadingCourse   = e.ClipName;
                };

                var timeoutProgress = new Progress <int>();
                timeoutProgress.ProgressChanged += (s, e) =>
                {
                    CurrentTimeout = e;
                };

                var coursesToDownload = CurrentDisplayedFilteredCourses.Where(c => c.CheckedForDownloading);
                foreach (var course in coursesToDownload)
                {
                    await _courseService.DownloadAsync(course.Id, downloadingProgress, timeoutProgress, _cancellationToken.Token);
                }
                IsDownloading = false;
            }
            catch (Exception exc)
            {
                Messenger.Send(new ExceptionThrownMessage(exc.Message));
            }
        }
Ejemplo n.º 2
0
        private async void OnDownloadCourseAsync()
        {
            try
            {
                IsDownloading      = true;
                _cancellationToken = new CancellationTokenSource();

                var downloadingProgress = new Progress <CourseDownloadingProgressArguments>();
                downloadingProgress.ProgressChanged += (s, e) =>
                {
                    DownloadingProgress = e.ClipProgress;
                    CurrentAction       = e.CurrentAction;
                    DownloadingCourse   = e.ClipName;
                };

                var timeoutProgress = new Progress <int>();
                timeoutProgress.ProgressChanged += (s, e) =>
                {
                    CurrentTimeout = e;
                };

                var coursesToDownload = CurrentDisplayedFilteredCourses.Where(c => c.CheckedForDownloading);
                foreach (var course in coursesToDownload)
                {
                    string tableOfContent = await _courseService.GetCourseTableOfContentAsync(course.Id, _cancellationToken.Token);

                    string destinationFolder        = _configProvider.DownloadsPath;
                    string validBaseCourseDirectory = $"{_courseService.GetBaseCourseDirectoryName(destinationFolder, course.Title)}";

                    _courseMetadataService.WriteTableOfContent(validBaseCourseDirectory, tableOfContent);
                    _courseMetadataService.WriteDescription(validBaseCourseDirectory, course.Description);
                    await _courseService.DownloadAsync(course.Id, downloadingProgress, timeoutProgress, _cancellationToken.Token);

                    course.CheckedForDownloading = false;
                    --NumberOfSelectedCourses;
                }
                IsDownloading = false;
            }
            catch (OperationCanceledException exc)
            {
                Messenger.Send(new ExceptionThrownMessage(Resources.YouCanceledDownloading));
            }
            catch (JsonSerializationException exc)
            {
                Messenger.Send(new ExceptionThrownMessage(exc.Message));
            }
            catch (JsonException exc)
            {
                Messenger.Send(new ExceptionThrownMessage(exc.Message));
            }
            catch (Exception exc)
            {
                Messenger.Send(new ExceptionThrownMessage(exc.Message));
            }
        }