예제 #1
0
        private async Task ExtractAndDownloadAsync(List <Extractor> extractors)
        {
            lblCurrentCourse.Text   = $"Extracting Courses (1/{extractors.Count})";
            progressBarCourses.Step = 100 / extractors.Count;
            await SaveConfig();

            var courses = new List <Course>();

            foreach (var extractor in extractors)
            {
                var course = await ExtractCourse(extractor);

                if (course is null)
                {
                    return;
                }
                courses.Add(course);
                IncrementlblCurrentCourse();
            }

            progressBarCourses.Value           = progressBarCourses.Maximum;
            progressBarExtractor.Style         = ProgressBarStyle.Continuous;
            progressBarExtractor.Value         = progressBarExtractor.Maximum;
            lblCurrentCourse.Text              = "Courses Extracted Successfully";
            lblCurrentExtractionOperation.Text = $"Extracted Courses({extractors.Count}/{extractors.Count})";
            UC_CourseExtractorStatus.Status    = CourseStatus.Finished;

            var downloaderForm = new DownloaderForm(courses, new DirectoryInfo(txtCourseDirectory.Text), _font);

            UC_CourseDownloaderStatus.Status = CourseStatus.Running;
            try
            {
                downloaderForm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"A fatal error occured while downloading the course.\nCheck the logs for more info", "Unknown Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.Error(ex, "An fatal error occured while downloading the course");
                UC_CourseDownloaderStatus.Status   = CourseStatus.Failed;
                lblCurrentExtractionOperation.Text = "Course Download Failed";
                return;
            }

            if (downloaderForm.DownloaderStatus == CourseStatus.Finished)
            {
                UC_CourseDownloaderStatus.Status = CourseStatus.Finished;
                MessageBox.Show("Course Downloaded Successfully :)", "Hooray", MessageBoxButtons.OK, MessageBoxIcon.Information);
                lblCurrentExtractionOperation.Text = "Course Downloaded Successfully";
            }
            else
            {
                UC_CourseDownloaderStatus.Status   = CourseStatus.Failed;
                lblCurrentExtractionOperation.Text = "Course Download Failed";
            }
        }
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            UpdateUI(() => EnableControls(false));
            SaveConfig();
            var course = ExtractCourse();

            if (course is null)
            {
                return;
            }
            var downloaderForm = new DownloaderForm(course, new DirectoryInfo(txtCourseDirectory.Text), _font);

            UpdateUI(() => UC_CourseDownloaderStatus.Status = CourseStatus.Running);
            try
            {
                downloaderForm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"An fatal error occured while downloading the course.\nCheck the logs for more info", "Unknown Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.Error(ex, "An fatal error occured while downloading the course");
                Extractor.KillDrivers();
                UpdateUI(() =>
                {
                    UC_CourseDownloaderStatus.Status = CourseStatus.Failed;
                    lblCurrentOperation.Text         = "Course Download Failed";
                });
            }

            UpdateUI(() =>
            {
                if (downloaderForm.DownloaderStatus == CourseStatus.Finished)
                {
                    UC_CourseDownloaderStatus.Status = CourseStatus.Finished;
                    MessageBox.Show("Course Downloaded Successfully :)", "Hooray", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lblCurrentOperation.Text = "Course Downloaded Successfully";
                }
                else
                {
                    UC_CourseDownloaderStatus.Status = CourseStatus.Failed;
                    lblCurrentOperation.Text         = "Course Download Failed";
                }
            });
        }