Exemple #1
0
        /// <summary>
        /// Creates and starts a task for each sheet in the batch.
        /// Results of those tasks are awaited and later outputted.
        /// The progress dialog monitors the process and is able to cancel it too.
        /// </summary>
        async void ProcessBatchAsync()
        {
            evaluationStartTime = DateTime.Now;

            // initialize the progress dialog
            progressDialog.SetTotalTasks(GetNumberOfSheetsInBatch());

            Evaluator             evaluator = new Evaluator(batch.Parameters);
            List <Task <Result> > tasks     = new List <Task <Result> >();

            foreach (var categoryBatch in batch.CategoryBatches.Values)
            {
                foreach (var sheetFilename in categoryBatch.SheetFilenames)
                {
                    Task <Result> sheetTask = new Task <Result>(
                        () => {
                        var result = evaluator.Evaluate(sheetFilename, categoryBatch.CorrectAnswers, categoryBatch.CategoryName, batch.Year);
                        progressDialog.IncrementProgressBarValue();
                        return(result);
                    },
                        progressDialog.GetCancellationToken()
                        );
                    tasks.Add(sheetTask);
                    sheetTask.Start();
                }
            }

            try
            {
                Result[] results = await Task.WhenAll(tasks);

                evaluationEndTime = DateTime.Now;
                progressDialog.SetProgressLabel(ProgressBarState.Saving);

                await OutputResultsDB(results);

                FinishJob(false);
            }
            catch (Exception ex) when(ex is TaskCanceledException || ex is OperationCanceledException ||
                                      ex is DbUpdateException || ex is DbUpdateConcurrencyException)
            {
                FinishJob(true);
            }
        }
Exemple #2
0
        private void evaluateButton_Click(object sender, EventArgs e)
        {
            if (categoryConfigurations.Count == 0)
            {
                MessageBox.Show(Properties.Resources.ErrorTextNoCategoriesConfigured, Properties.Resources.ErrorCaptionGeneral,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (MessageBox.Show(Properties.Resources.PromptTextEvaluationStart, Properties.Resources.PromptCaptionEvaluationStart,
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            // reset the category batches in the final klokan batch
            klokanBatch.CategoryBatches = new Dictionary <string, KlokanCategoryBatch>();

            // save all included batches into the final klokan batch
            foreach (var pair in categoryConfigurations)
            {
                if (pair.Value.isIncluded)
                {
                    klokanBatch.CategoryBatches[pair.Key] = pair.Value.batch;
                }
            }

            if (klokanBatch.CategoryBatches.Count == 0)
            {
                MessageBox.Show(Properties.Resources.ErrorTextNoCategoriesSelected, Properties.Resources.ErrorCaptionGeneral,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // assign the chosen year
            klokanBatch.Year = (int)(yearComboBox.SelectedItem);

            // assign the chosen parameters
            klokanBatch.Parameters = chosenParameters;

            ProgressDialog progressDialog = new ProgressDialog(new CancellationTokenSource());

            progressDialog.SetProgressLabel(ProgressBarState.Evaluating);

            var jobScheduler = new JobScheduler(klokanBatch, progressDialog);

            // new thread created, so that all tasks in it are planned in the threadpool and not in the WinForms synchronization context
            Thread thread = new Thread(jobScheduler.Run);

            thread.IsBackground = true;
            thread.Start();

            progressDialog.StartPosition = FormStartPosition.CenterScreen;
            progressDialog.ShowDialog();
        }
Exemple #3
0
        private void evaluateButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(Properties.Resources.PromptTextEvaluationStart, Properties.Resources.PromptCaptionEvaluationStart,
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            List <TestKlokanInstance> testInstances = new List <TestKlokanInstance>();

            // get all available test instances
            using (var testDB = new KlokanTestDBContext())
            {
                var allScansQuery = from scan in testDB.Scans
                                    select scan;

                foreach (var scan in allScansQuery)
                {
                    bool[,,] studentExpectedValues;
                    bool[,,] answerExpectedValues;
                    TableArrayHandling.DbSetToAnswers(new List <KlokanTestDBExpectedAnswer>(scan.ExpectedValues), out studentExpectedValues, out answerExpectedValues);

                    TestKlokanInstance testInstance = new TestKlokanInstance {
                        ScanId = scan.ScanId,
                        Image  = scan.Image,
                        StudentExpectedValues = studentExpectedValues,
                        AnswerExpectedValues  = answerExpectedValues
                    };

                    testInstances.Add(testInstance);
                }
            }

            if (testInstances.Count == 0)
            {
                MessageBox.Show(Properties.Resources.InfoTextNoTestItems, Properties.Resources.InfoCaptionNoTestItems,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            TestKlokanBatch testBatch = new TestKlokanBatch {
                Parameters    = chosenParameters,
                TestInstances = testInstances
            };

            ProgressDialog progressDialog = new ProgressDialog(new CancellationTokenSource());

            progressDialog.SetProgressLabel(ProgressBarState.Evaluating);

            var jobScheduler = new JobScheduler(testBatch, progressDialog);

            // new thread created, so that all tasks in it are planned in the threadpool and not in the WinForms synchronization context
            Thread thread = new Thread(jobScheduler.Run);

            thread.IsBackground = true;
            thread.Start();

            progressDialog.StartPosition = FormStartPosition.CenterScreen;
            progressDialog.ShowDialog();

            PopulateDataView();
            ShowAverageCorrectness();
        }