Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/HiveJobView.cs @ 6006

Last change on this file since 6006 was 5793, checked in by cneumuel, 14 years ago

#1233

  • implemented correct downloading of paused jobs. its now also possible to change parameters and resume a algorithm
  • removed Prepare() calls in ExperimentManager and in slave, as it prevents corrent resuming of paused jobs
  • made events in ItemTreeView be invoked in the correct thread
  • reduced log output in ExperimentManager
File size: 9.0 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.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Clients.Hive.Views {
29  [View("HiveJob View")]
30  [Content(typeof(HiveJob), true)]
31  public partial class HiveJobView : ItemView {
32    public new HiveJob Content {
33      get { return (HiveJob)base.Content; }
34      set {
35        if (base.Content != value) {
36          base.Content = value;
37        }
38      }
39    }
40
41    public HiveJobView() {
42      InitializeComponent();
43    }
44
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47      Content.OptimizerJobChanged += new EventHandler(Content_OptimizerJobChanged);
48      Content.JobChanged += new EventHandler(Content_JobChanged);
49      Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
50    }
51
52    protected override void DeregisterContentEvents() {
53      Content.OptimizerJobChanged -= new EventHandler(Content_OptimizerJobChanged);
54      Content.JobChanged -= new EventHandler(Content_JobChanged);
55      Content.JobStateChanged -= new EventHandler(Content_JobStateChanged);
56      base.DeregisterContentEvents();
57    }
58
59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      if (Content != null && Content.Job != null) {
62        logView.Content = Content.OptimizerJob.Log;
63        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
64      } else {
65        logView.Content = null;
66        computeInParallelCheckBox.Checked = false;
67      }
68      Content_OptimizerJobChanged(this, EventArgs.Empty);
69      Content_JobChanged(this, EventArgs.Empty);
70      Content_JobStateChanged(this, EventArgs.Empty);
71    }
72
73    protected void Content_OptimizerJobChanged(object sender, EventArgs e) {
74      RegisterJobEvents();
75      Job_OptimizerChanged(this, e);
76    }
77
78    protected void Job_OptimizerChanged(object sender, EventArgs e) {
79      if (Content != null && Content.Job != null && Content.OptimizerJob.Optimizer != null) {
80        optimizerNamedItemView.Content = Content.OptimizerJob.Optimizer;
81        runCollectionViewHost.Content = Content.OptimizerJob.Optimizer.Runs;
82      } else {
83        optimizerNamedItemView.Content = null;
84        runCollectionViewHost.Content = null;
85      }
86    }
87
88    private void RegisterJobEvents() {
89      if (Content != null && Content.Job != null) {
90        Content.OptimizerJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);
91        Content.OptimizerJob.OptimizerChanged += new EventHandler(Job_OptimizerChanged);
92      }
93    }
94
95    private void DeregisterJobEvents() {
96      if (Content != null && Content.Job != null) {
97        Content.OptimizerJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);
98        Content.OptimizerJob.OptimizerChanged -= new EventHandler(Job_OptimizerChanged);
99      }
100    }
101
102    #region Content Events
103    private void Content_JobChanged(object sender, EventArgs e) {
104      if (InvokeRequired) {
105        Invoke(new EventHandler(Content_JobChanged), sender, e);
106      } else {
107        if (Content != null && Content.Job != null) {
108          this.jobIdTextBox.Text = Content.Job.Id.ToString();
109          this.dateCreatedTextBox.Text = Content.Job.DateCreated.HasValue ? Content.Job.DateCreated.ToString() : string.Empty;
110          this.priorityTextBox.Text = Content.Job.Priority.ToString();
111          this.coresNeededTextBox.Text = Content.Job.CoresNeeded.ToString();
112          this.memoryNeededTextBox.Text = Content.Job.MemoryNeeded.ToString();
113        } else {
114          this.jobIdTextBox.Text = string.Empty;
115          this.dateCreatedTextBox.Text = string.Empty;
116          this.priorityTextBox.Text = string.Empty;
117          this.coresNeededTextBox.Text = string.Empty;
118          this.memoryNeededTextBox.Text = string.Empty;
119        }
120      }
121    }
122
123    private void Content_JobStateChanged(object sender, EventArgs e) {
124      if (InvokeRequired) {
125        Invoke(new EventHandler(Content_JobStateChanged), sender, e);
126      } else {
127        if (Content != null && Content.Job != null) {
128          this.stateTextBox.Text = Content.Job.State.ToString();
129          this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString();
130          this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString();
131          this.exceptionTextBox.Text = Content.Job.CurrentStateLog != null ? Content.Job.CurrentStateLog.Exception : string.Empty;
132          this.lastUpdatedTextBox.Text = Content.Job.LastJobDataUpdate.ToString();
133          if (Content.OptimizerJob.ComputeInParallel) {
134            this.stateLogViewHost.Content = new StateLogListList(
135                this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog)
136              ));
137          } else {
138            this.stateLogViewHost.Content = new StateLogList(Content.Job.StateLog);
139          }
140        } else {
141          this.stateTextBox.Text = string.Empty;
142          this.executionTimeTextBox.Text = string.Empty;
143          this.dateCalculatedText.Text = string.Empty;
144          this.dateFinishedTextBox.Text = string.Empty;
145          this.exceptionTextBox.Text = string.Empty;
146          this.stateLogViewHost.Content = null;
147          this.lastUpdatedTextBox.Text = string.Empty;
148        }
149        SetEnabledStateOfControls();
150      }
151    }
152
153    protected override void SetEnabledStateOfControls() {
154      base.SetEnabledStateOfControls();
155      this.jobIdTextBox.ReadOnly = true;
156      this.stateTextBox.ReadOnly = true;
157      this.executionTimeTextBox.ReadOnly = true;
158      this.dateCreatedTextBox.ReadOnly = true;
159      this.dateCalculatedText.ReadOnly = true;
160      this.dateFinishedTextBox.ReadOnly = true;
161      this.exceptionTextBox.ReadOnly = true;
162      this.lastUpdatedTextBox.ReadOnly = true;
163
164      this.priorityTextBox.ReadOnly = this.ReadOnly;
165      this.coresNeededTextBox.ReadOnly = this.ReadOnly;
166      this.memoryNeededTextBox.ReadOnly = this.ReadOnly;
167      this.computeInParallelCheckBox.Enabled = !this.ReadOnly && this.Content != null && this.Content.OptimizerJob != null && this.Content.OptimizerJob.IsParallelizable;
168
169      this.restartButton.Enabled = Content != null && Content.Job.State == JobState.Paused;
170      this.pauseButton.Enabled = Content != null && Content.Job.State == JobState.Calculating;
171      this.stopButton.Enabled = Content != null && (Content.Job.State == JobState.Calculating || Content.Job.State == JobState.Waiting || Content.Job.State == JobState.Paused);
172      this.showOptimizerButton.Enabled = Content != null && Content.Job.State == JobState.Paused && Content.OptimizerJob != null && Content.OptimizerJob.Optimizer != null;
173
174      optimizerNamedItemView.ReadOnly = true;
175    }
176
177    void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
178      if (InvokeRequired) {
179        Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
180      } else {
181        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
182      }
183    }
184    #endregion
185
186    private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
187      if (Content != null && Content.OptimizerJob != null) {
188        this.Content.OptimizerJob.ComputeInParallel = this.computeInParallelCheckBox.Checked;
189      }
190    }
191
192    private void exceptionTextBox_DoubleClick(object sender, EventArgs e) {
193      using (TextDialog dialog = new TextDialog("Exception", exceptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
194        if (dialog.ShowDialog(this) == DialogResult.OK)
195          Content.Description = dialog.Content;
196      }
197    }
198
199    private void restartButton_Click(object sender, EventArgs e) {
200      Content.Restart();
201    }
202
203    private void pauseButton_Click(object sender, EventArgs e) {
204      Content.Pause();
205    }
206
207    private void stopButton_Click(object sender, EventArgs e) {
208      Content.Stop();
209    }
210    private void showOptimizerButton_Click(object sender, EventArgs e) {
211      MainFormManager.MainForm.ShowContent(Content.OptimizerJob.Optimizer);
212    }
213  }
214}
Note: See TracBrowser for help on using the repository browser.