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

Last change on this file since 6178 was 6178, checked in by cneumuel, 13 years ago

#1233

  • added semaphores to ensure an appdomain is never unloaded when the start method has not finished
  • HiveEngine uploading and downloading of jobs works and is displayed in the view
File size: 8.4 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  [Content(typeof(HiveJob<>), false)]
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.JobItemChanged += new EventHandler(Content_JobItemChanged);
49      Content.JobChanged += new EventHandler(Content_JobChanged);
50      Content.JobStateChanged += new EventHandler(Content_JobStateChanged);
51    }
52
53    protected override void DeregisterContentEvents() {
54      Content.JobItemChanged -= new EventHandler(Content_JobItemChanged);
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        computeInParallelCheckBox.Checked = Content.ItemJob.ComputeInParallel;
64      } else {
65        computeInParallelCheckBox.Checked = false;
66      }
67      Content_JobItemChanged(this, EventArgs.Empty);
68      Content_JobChanged(this, EventArgs.Empty);
69      Content_JobStateChanged(this, EventArgs.Empty);
70    }
71
72    protected virtual void RegisterJobEvents() {
73      if (Content != null && Content.Job != null) {
74        Content.ItemJob.ComputeInParallelChanged += new EventHandler(OptimizerJob_ComputeInParallelChanged);
75        Content.ItemJob.ItemChanged += new EventHandler(Job_ItemChanged);
76      }
77    }
78
79    protected virtual void DeregisterJobEvents() {
80      if (Content != null && Content.Job != null) {
81        Content.ItemJob.ComputeInParallelChanged -= new EventHandler(OptimizerJob_ComputeInParallelChanged);
82        Content.ItemJob.ItemChanged -= new EventHandler(Job_ItemChanged);
83      }
84    }
85
86    #region Content Events
87    protected virtual void Content_JobChanged(object sender, EventArgs e) {
88      if (InvokeRequired) {
89        Invoke(new EventHandler(Content_JobChanged), sender, e);
90      } else {
91        if (Content != null && Content.Job != null) {
92          this.jobIdTextBox.Text = Content.Job.Id.ToString();
93          this.dateCreatedTextBox.Text = Content.Job.DateCreated.HasValue ? Content.Job.DateCreated.ToString() : string.Empty;
94          this.priorityTextBox.Text = Content.Job.Priority.ToString();
95          this.coresNeededTextBox.Text = Content.Job.CoresNeeded.ToString();
96          this.memoryNeededTextBox.Text = Content.Job.MemoryNeeded.ToString();
97        } else {
98          this.jobIdTextBox.Text = string.Empty;
99          this.dateCreatedTextBox.Text = string.Empty;
100          this.priorityTextBox.Text = string.Empty;
101          this.coresNeededTextBox.Text = string.Empty;
102          this.memoryNeededTextBox.Text = string.Empty;
103        }
104      }
105    }
106
107    protected virtual void Content_JobItemChanged(object sender, EventArgs e) {
108      RegisterJobEvents();
109      Job_ItemChanged(this, e);
110    }
111
112    protected virtual void Job_ItemChanged(object sender, EventArgs e) {
113      if (Content != null && Content.Job != null && Content.ItemJob.Item != null) {
114        optimizerItemView.Content = Content.ItemJob.Item;
115      } else {
116        optimizerItemView.Content = null;
117      }
118    }
119
120    protected virtual void Content_JobStateChanged(object sender, EventArgs e) {
121      if (InvokeRequired) {
122        Invoke(new EventHandler(Content_JobStateChanged), sender, e);
123      } else {
124        if (Content != null && Content.Job != null) {
125          this.stateTextBox.Text = Content.Job.State.ToString();
126          this.commandTextBox.Text = Content.Job.Command.ToString();
127          this.executionTimeTextBox.Text = Content.Job.ExecutionTime.ToString();
128          this.dateFinishedTextBox.Text = Content.Job.DateFinished.ToString();
129          this.exceptionTextBox.Text = Content.Job.CurrentStateLog != null ? Content.Job.CurrentStateLog.Exception : string.Empty;
130          this.lastUpdatedTextBox.Text = Content.Job.LastJobDataUpdate.ToString();
131          if (Content.ItemJob.ComputeInParallel) {
132            this.stateLogViewHost.Content = new StateLogListList(
133                this.Content.ChildHiveJobs.Select(child => new StateLogList(child.Job.StateLog)
134              ));
135          } else {
136            this.stateLogViewHost.Content = new StateLogList(Content.Job.StateLog);
137          }
138        } else {
139          this.stateTextBox.Text = string.Empty;
140          this.commandTextBox.Text = string.Empty;
141          this.executionTimeTextBox.Text = string.Empty;
142          this.dateCalculatedText.Text = string.Empty;
143          this.dateFinishedTextBox.Text = string.Empty;
144          this.exceptionTextBox.Text = string.Empty;
145          this.stateLogViewHost.Content = null;
146          this.lastUpdatedTextBox.Text = string.Empty;
147        }
148        SetEnabledStateOfControls();
149      }
150    }
151
152    protected override void SetEnabledStateOfControls() {
153      base.SetEnabledStateOfControls();
154      this.jobIdTextBox.ReadOnly = true;
155      this.stateTextBox.ReadOnly = true;
156      this.commandTextBox.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.ItemJob != null && this.Content.ItemJob.IsParallelizable;
168
169      this.modifyItemButton.Enabled = (Content != null && Content.ItemJob.Item != null && (Content.Job.State == JobState.Paused || Content.Job.State == JobState.Offline || Content.Job.State == JobState.Finished || Content.Job.State == JobState.Failed || Content.Job.State == JobState.Aborted));
170
171      optimizerItemView.ReadOnly = true;
172    }
173
174    protected virtual void OptimizerJob_ComputeInParallelChanged(object sender, EventArgs e) {
175      if (InvokeRequired) {
176        Invoke(new EventHandler(OptimizerJob_ComputeInParallelChanged), sender, e);
177      } else {
178        computeInParallelCheckBox.Checked = Content.ItemJob.ComputeInParallel;
179      }
180    }
181    #endregion
182
183    #region Child Control Events
184     protected virtual void computeInParallelCheckBox_CheckedChanged(object sender, EventArgs e) {
185      if (Content != null && Content.ItemJob != null) {
186        this.Content.ItemJob.ComputeInParallel = this.computeInParallelCheckBox.Checked;
187      }
188    }
189
190    protected virtual void exceptionTextBox_DoubleClick(object sender, EventArgs e) {
191      using (TextDialog dialog = new TextDialog("Exception", exceptionTextBox.Text, ReadOnly || !Content.CanChangeDescription)) {
192        if (dialog.ShowDialog(this) == DialogResult.OK)
193          Content.Description = dialog.Content;
194      }
195    }
196
197    protected virtual void modifyItemButton_Click(object sender, EventArgs e) {
198      MainFormManager.MainForm.ShowContent(Content.ItemJob.Item);
199    }
200    #endregion
201  }
202}
Note: See TracBrowser for help on using the repository browser.