[2193] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Core;
|
---|
| 31 | using HeuristicLab.DataAnalysis;
|
---|
| 32 | using System.Diagnostics;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.CEDMA.Server {
|
---|
| 35 | public partial class ProblemView : ViewBase {
|
---|
[2375] | 36 | private Dataset dataset;
|
---|
[2193] | 37 |
|
---|
[2375] | 38 | public ProblemView(Dataset dataset) {
|
---|
| 39 | this.dataset = dataset;
|
---|
[2193] | 40 | InitializeComponent();
|
---|
[2375] | 41 | datasetView.Dataset = dataset;
|
---|
| 42 | dataset.Changed += (sender, args) => UpdateControls();
|
---|
[2193] | 43 | UpdateControls();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | private void importButton_Click(object sender, EventArgs e) {
|
---|
| 47 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 48 | DatasetParser parser = new DatasetParser();
|
---|
| 49 | bool success = false;
|
---|
| 50 | try {
|
---|
| 51 | try {
|
---|
| 52 | parser.Import(openFileDialog.FileName, true);
|
---|
| 53 | success = true;
|
---|
| 54 | }
|
---|
| 55 | catch (DataFormatException ex) {
|
---|
| 56 | ShowWarningMessageBox(ex);
|
---|
| 57 | // not possible to parse strictly => clear and try to parse non-strict
|
---|
| 58 | parser.Reset();
|
---|
| 59 | parser.Import(openFileDialog.FileName, false);
|
---|
| 60 | success = true;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | catch (DataFormatException ex) {
|
---|
| 64 | // if the non-strict parsing also failed then show the exception
|
---|
| 65 | ShowErrorMessageBox(ex);
|
---|
| 66 | }
|
---|
| 67 | if (success) {
|
---|
| 68 | dataset.Rows = parser.Rows;
|
---|
| 69 | dataset.Columns = parser.Columns;
|
---|
| 70 | dataset.Name = parser.ProblemName;
|
---|
| 71 | dataset.Samples = new double[dataset.Rows * dataset.Columns];
|
---|
| 72 | Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
|
---|
[2375] | 73 | datasetView.Dataset = dataset;
|
---|
[2193] | 74 |
|
---|
[2285] | 75 | for (int i = 0; i < parser.VariableNames.Length; i++) {
|
---|
| 76 | dataset.SetVariableName(i, parser.VariableNames[i]);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[2375] | 79 |
|
---|
[2193] | 80 | Refresh();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | private void ShowWarningMessageBox(Exception ex) {
|
---|
| 86 | MessageBox.Show(ex.Message,
|
---|
| 87 | "Warning - " + ex.GetType().Name,
|
---|
| 88 | MessageBoxButtons.OK,
|
---|
| 89 | MessageBoxIcon.Warning);
|
---|
| 90 | }
|
---|
| 91 | private void ShowErrorMessageBox(Exception ex) {
|
---|
| 92 | MessageBox.Show(BuildErrorMessage(ex),
|
---|
| 93 | "Error - " + ex.GetType().Name,
|
---|
| 94 | MessageBoxButtons.OK,
|
---|
| 95 | MessageBoxIcon.Error);
|
---|
| 96 | }
|
---|
| 97 | private string BuildErrorMessage(Exception ex) {
|
---|
| 98 | StringBuilder sb = new StringBuilder();
|
---|
| 99 | sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
| 100 |
|
---|
| 101 | while (ex.InnerException != null) {
|
---|
| 102 | ex = ex.InnerException;
|
---|
| 103 | sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
|
---|
| 104 | }
|
---|
| 105 | return sb.ToString();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | }
|
---|
| 109 | }
|
---|