Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBExperimentUploadView.cs @ 7580

Last change on this file since 7580 was 7580, checked in by ascheibe, 12 years ago

#1174 added view for uploading existing runs from an experiment

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Clients.Access;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.Optimization;
30
31namespace HeuristicLab.Clients.OKB.RunCreation {
32  [View("OKBExperimentUpload View")]
33  [Content(typeof(Experiment), false)]
34  public partial class OKBExperimentUploadView : ItemView {
35    public new Experiment Content {
36      get { return (Experiment)base.Content; }
37      set { base.Content = value; }
38    }
39
40    List<OKBRunConfigSelectionView> runConfigViews = new List<OKBRunConfigSelectionView>();
41    private List<Problem> problems = new List<Problem>();
42    private List<Algorithm> algorithms = new List<Algorithm>();
43
44    public OKBExperimentUploadView() {
45      InitializeComponent();
46      tableLayoutPanel.RowCount = 0;
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content == null) {
52        ClearRuns();
53      } else {
54        DisplayRuns();
55      }
56    }
57
58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60      RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing);
61      RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed);
62    }
63
64    protected override void DeregisterContentEvents() {
65      RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing);
66      RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed);
67      base.DeregisterContentEvents();
68    }
69
70    private void DisplayError(Exception ex) {
71      PluginInfrastructure.ErrorHandling.ShowErrorDialog("An error occured while retrieving algorithm and problem information from the OKB.", ex);
72    }
73
74    private void DisplayRuns() {
75      if (RunCreationClient.Instance.Algorithms == null || RunCreationClient.Instance.Algorithms.Count() == 0) {
76        RunCreationClient.Instance.RefreshAsync(DisplayError);
77      } else {
78        CreateUI();
79      }
80    }
81
82    private void CreateUI() {
83      problems.AddRange(RunCreationClient.Instance.Problems);
84      algorithms.AddRange(RunCreationClient.Instance.Algorithms);
85
86      foreach (var run in Content.Runs) {
87        OKBRunConfigSelectionView orcsv = new OKBRunConfigSelectionView(run, algorithms, problems);
88        runConfigViews.Add(orcsv);
89        tableLayoutPanel.Controls.Add(orcsv);
90      }
91    }
92
93    private void ClearRuns() {
94      foreach (var runConfigView in runConfigViews) {
95        runConfigView.Hide();
96        tableLayoutPanel.Controls.Remove(runConfigView);
97        runConfigView.Dispose();
98      }
99      runConfigViews.Clear();
100    }
101
102    private void RunCreationClient_Refreshing(object sender, EventArgs e) {
103      if (InvokeRequired) {
104        Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e);
105      } else {
106        //TODO: display loading dialog
107        Cursor = Cursors.AppStarting;
108        Enabled = false;
109      }
110    }
111    private void RunCreationClient_Refreshed(object sender, EventArgs e) {
112      if (InvokeRequired) {
113        Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e);
114      } else {
115        CreateUI();
116
117        Enabled = true;
118        SetEnabledStateOfControls();
119        Cursor = Cursors.Default;
120      }
121    }
122
123    private void btnUpload_Click(object sender, EventArgs e) {
124      foreach (var runConfigView in runConfigViews) {
125        if (runConfigView.UploadToOKB()) {
126          //TODO: show progress
127          OKBRun run = new OKBRun(runConfigView.GetSelectedAlgorithm().Id, runConfigView.GetSelectedProblem().Id, runConfigView.ExperimentRun, UserInformation.Instance.User.Id);
128          try { run.Store(); }
129          catch (Exception ex) {
130            PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", ex);
131          }
132        }
133      }
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.