Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/HiveExperimentView.cs @ 4423

Last change on this file since 4423 was 4423, checked in by cneumuel, 14 years ago
  • Refactored HL.Hive.Experiment. JobItems are not called HiveJobs and OptimizerJobs do not contain a hierarchy anymore.
  • Dynamic generation of jobs on a slave are not reflected on the client user interface.
  • Optimizer-Trees are now strictly synchronized with the HiveJob-Trees (also the ComputeInParallel property is taken into account when the Child HiveJobs are created)
  • Improved the way a class can report progress and lock the UI (IProgressReporter, IProgress, Progress, ProgressView)
  • Changes were made to the config-files, so that server and clients work with blade12.hpc.fh-hagenberg.at
  • Lots of small changes and bugfixes
File size: 11.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Windows.Forms;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.PluginInfrastructure;
29using HeuristicLab.Optimization;
30using HeuristicLab.Optimization.Views;
31using HeuristicLab.Hive.Experiment.Properties;
32using System.Threading;
33
34namespace HeuristicLab.Hive.Experiment.Views {
35  /// <summary>
36  /// The base class for visual representations of items.
37  /// </summary>
38  [View("Experiment View")]
39  [Content(typeof(HiveExperiment), true)]
40  public sealed partial class HiveExperimentView : NamedItemView {
41    private ProgressView progressView;
42
43    public new HiveExperiment Content {
44      get { return (HiveExperiment)base.Content; }
45      set { base.Content = value; }
46    }
47
48    /// <summary>
49    /// Initializes a new instance of <see cref="ItemBaseView"/>.
50    /// </summary>
51    public HiveExperimentView() {
52      InitializeComponent();
53      downloadExperimentPanel.Dock = DockStyle.Fill;
54    }
55
56    protected override void DeregisterContentEvents() {
57      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
58      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
59      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
60      Content.Prepared -= new EventHandler(Content_Prepared);
61      Content.Started -= new EventHandler(Content_Started);
62      Content.Paused -= new EventHandler(Content_Paused);
63      Content.Stopped -= new EventHandler(Content_Stopped);
64      Content.IsResultsPollingChanged -= new EventHandler(Content_IsResultsPollingChanged);
65      Content.HiveJobChanged -= new EventHandler(Content_HiveJobChanged);
66      Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);
67      base.DeregisterContentEvents();
68    }
69
70    protected override void RegisterContentEvents() {
71      base.RegisterContentEvents();
72      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
73      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
74      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
75      Content.Prepared += new EventHandler(Content_Prepared);
76      Content.Started += new EventHandler(Content_Started);
77      Content.Paused += new EventHandler(Content_Paused);
78      Content.Stopped += new EventHandler(Content_Stopped);
79      Content.IsResultsPollingChanged += new EventHandler(Content_IsResultsPollingChanged);
80      Content.HiveJobChanged += new EventHandler(Content_HiveJobChanged);
81      Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);
82    }
83
84    protected override void OnContentChanged() {
85      base.OnContentChanged();
86      if (Content == null) {
87        executionTimeTextBox.Text = string.Empty;
88        resourceIdsTextBox.Text = string.Empty;
89        logView.Content = null;
90      } else {
91        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
92        resourceIdsTextBox.Text = Content.ResourceIds;
93        logView.Content = Content.Log;
94      }
95      Content_HiveJobChanged(this, EventArgs.Empty);
96      Content_IsProgressingChanged(this, EventArgs.Empty);
97      SetEnabledStateOfControls();
98    }
99
100    protected override void SetEnabledStateOfControls() {
101      base.SetEnabledStateOfControls();
102      executionTimeTextBox.Enabled = Content != null;
103      experimentNamedItemView.ReadOnly = true;
104      if (Content != null) {
105        this.nameTextBox.ReadOnly = Content.ExecutionState != ExecutionState.Prepared;
106        this.descriptionTextBox.ReadOnly = Content.ExecutionState != ExecutionState.Prepared;
107        this.resourceIdsTextBox.ReadOnly = Content.ExecutionState != ExecutionState.Prepared;
108        this.hiveJobView.ReadOnly = Content.ExecutionState != ExecutionState.Prepared;
109
110        viewExperimentButton.Enabled = Content.GetExperiment() != null;
111
112        this.Locked = Content.ExecutionState == ExecutionState.Started && Content.IsPollingResults;
113        downloadExperimentPanel.Visible = Content.HiveExperimentId != Guid.Empty && Content.GetExperiment() == null;
114      }
115      SetEnabledStateOfExecutableButtons();
116    }
117
118    protected override void OnClosed(FormClosedEventArgs e) {
119      if (Content != null) {
120        if (Content.IsPollingResults)
121          Content.StopResultPolling();
122      }
123      base.OnClosed(e);
124    }
125
126    #region Content Events
127    private void Content_ExecutionStateChanged(object sender, EventArgs e) {
128      if (InvokeRequired)
129        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
130      else
131        SetEnabledStateOfControls();
132    }
133    private void Content_Prepared(object sender, EventArgs e) {
134      if (InvokeRequired)
135        Invoke(new EventHandler(Content_Prepared), sender, e);
136      else {
137        nameTextBox.Enabled = descriptionTextBox.Enabled = true;
138        Locked = false;
139        SetEnabledStateOfControls();
140      }
141    }
142    private void Content_Started(object sender, EventArgs e) {
143      if (InvokeRequired)
144        Invoke(new EventHandler(Content_Started), sender, e);
145      else {
146        nameTextBox.Enabled = descriptionTextBox.Enabled = false;
147        SetEnabledStateOfControls();
148      }
149    }
150    private void Content_Paused(object sender, EventArgs e) {
151      if (InvokeRequired)
152        Invoke(new EventHandler(Content_Paused), sender, e);
153      else {
154        nameTextBox.Enabled = descriptionTextBox.Enabled = true;
155        SetEnabledStateOfControls();
156      }
157    }
158    private void Content_Stopped(object sender, EventArgs e) {
159      if (InvokeRequired)
160        Invoke(new EventHandler(Content_Stopped), sender, e);
161      else {
162        nameTextBox.Enabled = descriptionTextBox.Enabled = true;
163        Locked = false;
164        SetEnabledStateOfControls();
165      }
166    }
167    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
168      if (InvokeRequired)
169        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
170      else
171        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
172    }
173    private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
174      if (InvokeRequired)
175        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
176      else
177        ErrorHandling.ShowErrorDialog(this, e.Value);
178    }
179    private void Content_IsResultsPollingChanged(object sender, EventArgs e) {
180      if (InvokeRequired)
181        Invoke(new EventHandler(Content_IsResultsPollingChanged), sender, e);
182      else {
183        SetEnabledStateOfControls();
184      }
185    }
186    void Content_HiveJobChanged(object sender, EventArgs e) {
187      if (InvokeRequired)
188        Invoke(new EventHandler(Content_HiveJobChanged), sender, e);
189      else {
190        if (Content != null) {
191          hiveJobView.Content = Content.HiveJob;
192          experimentNamedItemView.Content = Content.GetExperiment();
193        } else {
194          hiveJobView.Content = null;
195          experimentNamedItemView.Content = null;
196        }
197        SetEnabledStateOfControls();
198      }
199    }
200    #endregion
201
202    #region Control events
203    private void startButton_Click(object sender, EventArgs e) {
204      Content.Start();
205    }
206    private void pauseButton_Click(object sender, EventArgs e) {
207      Content.Pause();
208    }
209    private void stopButton_Click(object sender, EventArgs e) {
210      Content.Stop();
211    }
212    private void resetButton_Click(object sender, EventArgs e) {
213      Content.Prepare();
214    }
215
216    private void resourceIdsTextBox_Validated(object sender, EventArgs e) {
217      Content.ResourceIds = resourceIdsTextBox.Text;
218    }
219
220    private void newExperimentButton_Click(object sender, EventArgs e) {
221      Content.SetExperiment(new HeuristicLab.Optimization.Experiment());
222    }
223
224    private void openExperimentButton_Click(object sender, EventArgs e) {
225      OpenFileDialog openFileDialog = new OpenFileDialog();
226      openFileDialog.Title = "Open Experimenter";
227      openFileDialog.FileName = "Item";
228      openFileDialog.Multiselect = false;
229      openFileDialog.DefaultExt = "hl";
230      openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
231
232      if (openFileDialog.ShowDialog() == DialogResult.OK) {
233        Content.SetExperiment((HeuristicLab.Optimization.Experiment)ContentManager.Load(openFileDialog.FileName));
234      }
235    }
236
237    private void showExperimentButton_Click(object sender, EventArgs e) {
238      MainFormManager.MainForm.ShowContent(Content.GetExperiment());
239    }
240
241    private void disconnectButton_Click(object sender, EventArgs e) {
242      if (Content != null) {
243        Content.StopResultPolling();
244        SetEnabledStateOfControls();
245      }
246    }
247
248    private void reconnectButton_Click(object sender, EventArgs e) {
249      if (Content != null) {
250        Content.StartResultPolling();
251        SetEnabledStateOfControls();
252      }
253    }
254    #endregion
255
256    #region Helpers
257    private void SetEnabledStateOfExecutableButtons() {
258      if (Content == null) {
259        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = reconnectButton.Enabled = disconnectButton.Enabled = false;
260      } else {
261        startButton.Enabled = Content.GetExperiment() != null && Content.ExecutionState == ExecutionState.Prepared;
262        pauseButton.Enabled = false;
263        stopButton.Enabled = Content.ExecutionState == ExecutionState.Started && Content.IsPollingResults;
264        resetButton.Enabled = false;
265        reconnectButton.Enabled = (Content.ExecutionState == ExecutionState.Started) && !Content.IsPollingResults;
266        disconnectButton.Enabled = (Content.ExecutionState == ExecutionState.Started) && Content.IsPollingResults;
267      }
268    }
269    #endregion
270
271    private void downloadExperimentButton_Click(object sender, EventArgs e) {
272      var invoker = new MethodInvoker(Content.LoadHiveJob);
273      invoker.BeginInvoke((ar) => {
274        try {
275          invoker.EndInvoke(ar);
276        }
277        catch (Exception ex) {
278          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
279        }
280      }, null);
281    }
282
283    private void Content_IsProgressingChanged(object sender, EventArgs e) {
284      if (this.InvokeRequired) {
285        Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
286      } else {
287        if (Content != null && Content.IsProgressing) {
288          SetProgressView();
289        } else {
290          FinishProgressView();
291        }
292      }
293    }
294
295    private void SetProgressView() {
296      if (progressView == null) {
297        progressView = new ProgressView(this, Content.Progress);
298      }
299      progressView.Progress = Content.Progress;
300    }
301
302    private void FinishProgressView() {
303      if (progressView != null) {
304        progressView.Finish();
305        progressView = null;
306        SetEnabledStateOfControls();
307      }
308    }
309  }
310}
Note: See TracBrowser for help on using the repository browser.