Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/ProblemView.cs @ 2375

Last change on this file since 2375 was 2375, checked in by gkronber, 15 years ago

Refactored CEDMA dispatcher and CEDMA server view to allow different modeling scenarios for each variable. #754

File size: 3.7 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Core;
31using HeuristicLab.DataAnalysis;
32using System.Diagnostics;
33using HeuristicLab.CEDMA.Core;
34
35namespace HeuristicLab.CEDMA.Server {
36  public partial class ProblemView : ViewBase {
37    private Dataset dataset;
38
39    public ProblemView(Dataset dataset) {
40      this.dataset = dataset;
41      InitializeComponent();
42      datasetView.Dataset = dataset;
43      dataset.Changed += (sender, args) => UpdateControls();
44      UpdateControls();
45    }
46
47    private void importButton_Click(object sender, EventArgs e) {
48      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
49        DatasetParser parser = new DatasetParser();
50        bool success = false;
51        try {
52          try {
53            parser.Import(openFileDialog.FileName, true);
54            success = true;
55          }
56          catch (DataFormatException ex) {
57            ShowWarningMessageBox(ex);
58            // not possible to parse strictly => clear and try to parse non-strict
59            parser.Reset();
60            parser.Import(openFileDialog.FileName, false);
61            success = true;
62          }
63        }
64        catch (DataFormatException ex) {
65          // if the non-strict parsing also failed then show the exception
66          ShowErrorMessageBox(ex);
67        }
68        if (success) {
69          dataset.Rows = parser.Rows;
70          dataset.Columns = parser.Columns;
71          dataset.Name = parser.ProblemName;
72          dataset.Samples = new double[dataset.Rows * dataset.Columns];
73          Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
74          datasetView.Dataset = dataset;
75
76          for (int i = 0; i < parser.VariableNames.Length; i++) {
77            dataset.SetVariableName(i, parser.VariableNames[i]);
78          }
79
80
81          Refresh();
82        }
83      }
84    }
85
86    private void ShowWarningMessageBox(Exception ex) {
87      MessageBox.Show(ex.Message,
88                      "Warning - " + ex.GetType().Name,
89                      MessageBoxButtons.OK,
90                      MessageBoxIcon.Warning);
91    }
92    private void ShowErrorMessageBox(Exception ex) {
93      MessageBox.Show(BuildErrorMessage(ex),
94                      "Error - " + ex.GetType().Name,
95                      MessageBoxButtons.OK,
96                      MessageBoxIcon.Error);
97    }
98    private string BuildErrorMessage(Exception ex) {
99      StringBuilder sb = new StringBuilder();
100      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
101
102      while (ex.InnerException != null) {
103        ex = ex.InnerException;
104        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
105      }
106      return sb.ToString();
107    }
108
109  }
110}
Note: See TracBrowser for help on using the repository browser.