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 @ 5636

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

#1233

  • updated jobstates documentation
  • enhanced ganttChart
  • fixed setting of jobstates
  • added option to force lifecycle-trigger (mainly for testing purposes)
File size: 8.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;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Clients.Hive.Views {
30  [View("HiveJob View")]
31  [Content(typeof(HiveJob), true)]
32  public partial class HiveJobView : ItemView {
33    public new HiveJob Content {
34      get { return (HiveJob)base.Content; }
35      set {
36        if (base.Content != value) {
37          base.Content = value;
38        }
39      }
40    }
41
42    public HiveJobView() {
43      InitializeComponent();
44    }
45
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      Content.OptimizerJobChanged += new EventHandler(Content_OptimizerJobChanged);
49      Content.JobChanged += new EventHandler(Content_JobChanged);
50      Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
51    }
52
53    protected override void DeregisterContentEvents() {
54      Content.OptimizerJobChanged -= new EventHandler(Content_OptimizerJobChanged);
55      Content.JobChanged -= new EventHandler(Content_JobChanged);
56      Content.JobStateChanged -= new EventHandler(Content_JobStateChanged);
57      base.DeregisterContentEvents();
58    }
59
60    protected override void OnContentChanged() {
61      base.OnContentChanged();
62      if (Content != null && Content.Job != null) {
63        logView.Content = Content.OptimizerJob.Log;
64        childHiveJobView.Content = Content.ChildHiveJobs;
65        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
66      } else {
67        logView.Content = null;
68        childHiveJobView.Content = null;
69        computeInParallelCheckBox.Checked = false;
70      }
71      Content_OptimizerJobChanged(this, EventArgs.Empty);
72      Content_JobChanged(this, EventArgs.Empty);
73      Content_JobStateChanged(this, EventArgs.Empty);
74    }
75
76    void Content_OptimizerJobChanged(object sender, EventArgs e) {
77      RegisterJobEvents();
78      Job_OptimizerChanged(this, e);
79    }
80
81    void Job_OptimizerChanged(object sender, EventArgs e) {
82      if (Content != null && Content.Job != null && Content.OptimizerJob.Optimizer != null) {
83        optimizerNamedItemView.Content = Content.OptimizerJob.Optimizer;
84        runCollectionViewHost.Content = Content.OptimizerJob.Optimizer.Runs;
85      } else {
86        optimizerNamedItemView.Content = null;
87        runCollectionViewHost.Content = null;
88      }
89    }
90
91    private void RegisterJobEvents() {
92      if (Content != null && Content.Job != null) {
93        Content.OptimizerJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);
94        Content.OptimizerJob.OptimizerChanged += new EventHandler(Job_OptimizerChanged);
95      }
96    }
97
98    private void DeregisterJobEvents() {
99      if (Content != null && Content.Job != null) {
100        Content.OptimizerJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);
101        Content.OptimizerJob.OptimizerChanged -= new EventHandler(Job_OptimizerChanged);
102      }
103    }
104
105    #region Content Events
106    private void Content_JobChanged(object sender, EventArgs e) {
107      if (InvokeRequired) {
108        Invoke(new EventHandler(Content_JobChanged), sender, e);
109      } else {
110        if (Content != null && Content.Job != null) {
111          this.jobIdTextBox.Text = Content.Job.Id.ToString();
112          this.dateCreatedTextBox.Text = Content.Job.DateCreated.ToString();
113          this.priorityTextBox.Text = Content.Job.Priority.ToString();
114          this.coresNeededTextBox.Text = Content.Job.CoresNeeded.ToString();
115          this.memoryNeededTextBox.Text = Content.Job.MemoryNeeded.ToString();
116        } else {
117          this.jobIdTextBox.Text = string.Empty;
118          this.dateCreatedTextBox.Text = string.Empty;
119          this.priorityTextBox.Text = string.Empty;
120          this.coresNeededTextBox.Text = string.Empty;
121          this.memoryNeededTextBox.Text = string.Empty;
122        }
123      }
124    }
125
126    private void Content_JobStateChanged(object sender, EventArgs e) {
127      if (InvokeRequired) {
128        Invoke(new EventHandler(Content_JobStateChanged), sender, e);
129      } else {
130        if (Content != null && Content.Job != null) {
131          this.stateTextBox.Text = Content.Job.State.ToString();
132          this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString();
133          //this.dateCalculatedText.Text = Content.Job.DateCalculated.ToString();
134          this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString();
135          this.exceptionTextBox.Text = Content.Job.CurrentStateLog.Exception;
136          if (Content.OptimizerJob.ComputeInParallel) {
137            this.stateLogViewHost.Content = new ItemList<StateLogList>(
138                this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog)
139              ));
140          } else {
141            this.stateLogViewHost.Content = new StateLogList(Content.Job.StateLog);
142          }
143        } else {
144          this.stateTextBox.Text = string.Empty;
145          this.executionTimeTextBox.Text = string.Empty;
146          this.dateCalculatedText.Text = string.Empty;
147          this.dateFinishedTextBox.Text = string.Empty;
148          this.exceptionTextBox.Text = string.Empty;
149          this.stateLogViewHost.Content = null;
150        }
151      }
152    }
153
154    protected override void SetEnabledStateOfControls() {
155      base.SetEnabledStateOfControls();
156      this.jobIdTextBox.ReadOnly = true;
157      this.stateTextBox.ReadOnly = true;
158      this.executionTimeTextBox.ReadOnly = true;
159      this.dateCreatedTextBox.ReadOnly = true;
160      this.dateCalculatedText.ReadOnly = true;
161      this.dateFinishedTextBox.ReadOnly = true;
162      this.exceptionTextBox.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      optimizerNamedItemView.ReadOnly = true;
170      ShowOrHideChildJobTabPage();
171    }
172
173    void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
174      if (InvokeRequired) {
175        Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
176      } else {
177        computeInParallelCheckBox.Checked = Content.OptimizerJob.ComputeInParallel;
178        ShowOrHideChildJobTabPage();
179      }
180    }
181
182    private void ShowOrHideChildJobTabPage() {
183      if (Content != null && Content.OptimizerJob != null) {
184        if (!Content.OptimizerJob.ComputeInParallel) {
185          if (tabControl.TabPages.Contains(childJobsTabPage))
186            tabControl.TabPages.Remove(childJobsTabPage);
187        } else {
188          if (!tabControl.TabPages.Contains(childJobsTabPage))
189            tabControl.TabPages.Insert(1, childJobsTabPage);
190        }
191      }
192    }
193    #endregion
194
195    private void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
196      if (Content != null && Content.OptimizerJob != null) {
197        this.Content.OptimizerJob.ComputeInParallel = this.computeInParallelCheckBox.Checked;
198      }
199    }
200  }
201}
Note: See TracBrowser for help on using the repository browser.