/// <summary> /// This function loads the data from the database into the fields and update the user interface /// </summary> /// <author>Thomas Meents, Bernhard Bruns</author> private void LoadDataFromDatabase() { string connectionName = DBWorker.GetConnectionName(); Dispatcher.BeginInvoke((Action)(() => { MiningInfo.BBCode += "\nLoading data from " + connectionName; MiningInfoScrollViewer.ScrollToEnd(); })); if (MainWindow.MatrixSelection.SelectionHasChangedSinceLastLoading || EventSelectionModel.GetInstance().SelectionHasChangedSinceLastLoading) { foreach (Field field in MainWindow.MatrixSelection.MatrixFields) { if (_cancellationToken.IsCancellationRequested) { break; } DBConnectionHelpers.LoadFactsInField(field); Dispatcher.BeginInvoke((Action)(() => { ProgressBar.Value += 1; })); } MainWindow.MatrixSelection.SelectionHasChangedSinceLastLoading = false; EventSelectionModel.GetInstance().SelectionHasChangedSinceLastLoading = false; } }
/// <summary> /// Set the calculation controls while threading /// </summary> private void SetCalculationControlsInThread() { Dispatcher.BeginInvoke((Action)(() => { MiningInfo.BBCode += "\nMining completed!"; MiningInfoScrollViewer.ScrollToEnd(); StartCalculationButton.Content = "Continue"; StartCalculationButton.Click -= StartCalculationClick; StartCalculationButton.Click += ContinueClick; StartCalculationButton.IsEnabled = true; CancelCalculationButton.IsEnabled = false; ProgressBar.Visibility = Visibility.Hidden; Cursor = Cursors.Arrow; })); }
/// <summary> /// Initialize the Mining (set controls etc.) /// </summary> private void InitializeCalculation() { Cursor = Cursors.Wait; ProgressBar.Visibility = Visibility.Visible; _cancellationTokenSource = new CancellationTokenSource(); _cancellationToken = _cancellationTokenSource.Token; _parallelOption = new ParallelOptions(); _parallelOption.CancellationToken = _cancellationTokenSource.Token; _parallelOption.MaxDegreeOfParallelism = System.Environment.ProcessorCount; _isMinerRunning = true; StartCalculationButton.IsEnabled = false; CancelCalculationButton.IsEnabled = true; MiningInfo.BBCode += "\nStart mining..."; MiningInfoScrollViewer.ScrollToEnd(); }
/// <summary> /// Start the miner on a list of fields and save the results in a dictionary /// </summary> /// <param name="fields"></param> /// <author>Bernhard Bruns</author> public void Mine(List <Field> fields) { int fieldCounter = 1; Parallel.ForEach(fields, field => { try { field.ResetInformation(); IMiner iMiner = MinerFactory.CreateMiner(MinerSettings.MinerName, field); ProcessModel resultingProcessModel = iMiner.Mine(); // Save petrinet in the field object field.ProcessModel = resultingProcessModel; Dispatcher.BeginInvoke((Action)(() => { MiningInfo.BBCode += "\n[b]Mining field " + fieldCounter++ + " of " + fields.Count + "[/b]" + "\n[color=#00E600]Successfully mined.[/color]"; MiningInfoScrollViewer.ScrollToEnd(); })).Wait(); } catch (ArgumentNullException Ex) { Dispatcher.BeginInvoke((Action)(() => { MiningInfo.BBCode += "\n[b]Mining field " + fieldCounter++ + " of " + fields.Count + "[/b]" + "\nERROR: Parameter " + Ex.ParamName + " was not given:\n" + Ex.Message; MiningInfoScrollViewer.ScrollToEnd(); })).Wait(); } catch (Exception Ex) { Dispatcher.BeginInvoke((Action)(() => { MiningInfo.BBCode += "\n[b]Mining field " + fieldCounter++ + " of " + fields.Count + "[/b]" + "\n[color=#FF0000]ERROR: [/color]" + Ex.Message; MiningInfoScrollViewer.ScrollToEnd(); })).Wait(); } finally { Dispatcher.BeginInvoke((Action)(() => { ProgressBar.Value += 1; })).Wait(); _parallelOption.CancellationToken.ThrowIfCancellationRequested(); } }); }