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 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using System.Threading;
|
---|
27 | using System.Threading.Tasks;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Collections;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 | using HeuristicLab.Core;
|
---|
32 | using HeuristicLab.MainForm;
|
---|
33 | using HeuristicLab.MainForm.WindowsForms;
|
---|
34 | using HeuristicLab.Optimization;
|
---|
35 | using HeuristicLab.PluginInfrastructure;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Clients.Hive.JobManager.Views {
|
---|
38 | /// <summary>
|
---|
39 | /// The base class for visual representations of items.
|
---|
40 | /// </summary>
|
---|
41 | [View("Hive Job View")]
|
---|
42 | [Content(typeof(RefreshableJob), true)]
|
---|
43 | public partial class RefreshableHiveJobView : HeuristicLab.Core.Views.ItemView {
|
---|
44 | private Progress progress;
|
---|
45 | private ProgressView progressView;
|
---|
46 | private HiveResourceSelectorDialog hiveResourceSelectorDialog;
|
---|
47 |
|
---|
48 | public new RefreshableJob Content {
|
---|
49 | get { return (RefreshableJob)base.Content; }
|
---|
50 | set { base.Content = value; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /// <summary>
|
---|
54 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
55 | /// </summary>
|
---|
56 | public RefreshableHiveJobView() {
|
---|
57 | InitializeComponent();
|
---|
58 | progress = new Progress() {
|
---|
59 | CanBeCanceled = true,
|
---|
60 | ProgressState = ProgressState.Finished
|
---|
61 | };
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected override void RegisterContentEvents() {
|
---|
65 | base.RegisterContentEvents();
|
---|
66 | Content.RefreshAutomaticallyChanged += new EventHandler(Content_RefreshAutomaticallyChanged);
|
---|
67 | Content.JobChanged += new EventHandler(Content_HiveExperimentChanged);
|
---|
68 | Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
|
---|
69 | Content.JobStatisticsChanged += new EventHandler(Content_JobStatisticsChanged);
|
---|
70 | Content.ExceptionOccured += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured);
|
---|
71 | Content.StateLogListChanged += new EventHandler(Content_StateLogListChanged);
|
---|
72 | Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);
|
---|
73 | Content.HiveTasksChanged += new EventHandler(Content_HiveTasksChanged);
|
---|
74 | Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
|
---|
75 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
76 | Content.IsAllowedPrivilegedChanged += new EventHandler(Content_IsAllowedPrivilegedChanged);
|
---|
77 | Content.Loaded += new EventHandler(Content_Loaded);
|
---|
78 | Content.TaskReceived += new EventHandler(Content_TaskReceived);
|
---|
79 | progressView = new ProgressView(this, progress);
|
---|
80 | }
|
---|
81 |
|
---|
82 | protected override void DeregisterContentEvents() {
|
---|
83 | Content.RefreshAutomaticallyChanged -= new EventHandler(Content_RefreshAutomaticallyChanged);
|
---|
84 | Content.JobChanged -= new EventHandler(Content_HiveExperimentChanged);
|
---|
85 | Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
|
---|
86 | Content.JobStatisticsChanged -= new EventHandler(Content_JobStatisticsChanged);
|
---|
87 | Content.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured);
|
---|
88 | Content.StateLogListChanged -= new EventHandler(Content_StateLogListChanged);
|
---|
89 | Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);
|
---|
90 | Content.HiveTasksChanged -= new EventHandler(Content_HiveTasksChanged);
|
---|
91 | Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
|
---|
92 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
93 | Content.Loaded -= new EventHandler(Content_Loaded);
|
---|
94 | Content.TaskReceived -= new EventHandler(Content_TaskReceived);
|
---|
95 | if (progressView != null) {
|
---|
96 | progressView.Content = null;
|
---|
97 | progressView.Dispose();
|
---|
98 | progressView = null;
|
---|
99 | }
|
---|
100 | base.DeregisterContentEvents();
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void RegisterHiveExperimentEvents() {
|
---|
104 | Content.Job.PropertyChanged += new PropertyChangedEventHandler(HiveExperiment_PropertyChanged);
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void DeregisterHiveExperimentEvents() {
|
---|
108 | Content.Job.PropertyChanged -= new PropertyChangedEventHandler(HiveExperiment_PropertyChanged);
|
---|
109 | }
|
---|
110 |
|
---|
111 | private void RegisterHiveJobEvents() {
|
---|
112 | Content.HiveTasks.ItemsAdded += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded);
|
---|
113 | Content.HiveTasks.ItemsRemoved += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved);
|
---|
114 | Content.HiveTasks.CollectionReset += new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset);
|
---|
115 | }
|
---|
116 | private void DeregisterHiveJobEvents() {
|
---|
117 | Content.HiveTasks.ItemsAdded -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded);
|
---|
118 | Content.HiveTasks.ItemsRemoved -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved);
|
---|
119 | Content.HiveTasks.CollectionReset -= new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset);
|
---|
120 | }
|
---|
121 |
|
---|
122 | protected override void OnContentChanged() {
|
---|
123 | base.OnContentChanged();
|
---|
124 | if (Content == null) {
|
---|
125 | nameTextBox.Text = string.Empty;
|
---|
126 | executionTimeTextBox.Text = string.Empty;
|
---|
127 | resourceNamesTextBox.Text = string.Empty;
|
---|
128 | isPrivilegedCheckBox.Checked = false;
|
---|
129 | logView.Content = null;
|
---|
130 | refreshAutomaticallyCheckBox.Checked = false;
|
---|
131 | runCollectionViewHost.Content = null;
|
---|
132 | } else {
|
---|
133 | nameTextBox.Text = Content.Job.Name;
|
---|
134 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
135 | resourceNamesTextBox.Text = Content.Job.ResourceNames;
|
---|
136 | isPrivilegedCheckBox.Checked = Content.Job.IsPrivileged;
|
---|
137 | refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
|
---|
138 | logView.Content = Content.Log;
|
---|
139 | runCollectionViewHost.Content = GetAllRunsFromJob(Content);
|
---|
140 | }
|
---|
141 | hiveExperimentPermissionListView.Content = null; // has to be filled by refresh button
|
---|
142 | Content_JobStatisticsChanged(this, EventArgs.Empty);
|
---|
143 | Content_HiveExperimentChanged(this, EventArgs.Empty);
|
---|
144 | Content_HiveTasksChanged(this, EventArgs.Empty);
|
---|
145 | Content_IsProgressingChanged(this, EventArgs.Empty);
|
---|
146 | Content_StateLogListChanged(this, EventArgs.Empty);
|
---|
147 | HiveExperiment_PropertyChanged(this, new PropertyChangedEventArgs("Id"));
|
---|
148 | SetEnabledStateOfControls();
|
---|
149 | }
|
---|
150 |
|
---|
151 | protected override void SetEnabledStateOfControls() {
|
---|
152 | base.SetEnabledStateOfControls();
|
---|
153 | executionTimeTextBox.Enabled = Content != null;
|
---|
154 | jobsTextBox.ReadOnly = true;
|
---|
155 | calculatingTextBox.ReadOnly = true;
|
---|
156 | finishedTextBox.ReadOnly = true;
|
---|
157 |
|
---|
158 | if (Content != null) {
|
---|
159 | bool alreadyUploaded = Content.Id != Guid.Empty;
|
---|
160 | bool jobsLoaded = Content.HiveTasks != null && Content.HiveTasks.All(x => x.Task.Id != Guid.Empty);
|
---|
161 | tabControl.Enabled = !Content.IsProgressing;
|
---|
162 |
|
---|
163 | this.nameTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
|
---|
164 | this.resourceNamesTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
|
---|
165 | this.searchButton.Enabled = (Content.IsControllable && !(Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded)) || !Content.IsProgressing;
|
---|
166 | this.jobsTreeView.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing;
|
---|
167 |
|
---|
168 | this.isPrivilegedCheckBox.Enabled = Content.IsAllowedPrivileged && Content.IsControllable && !(Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded) && !Content.IsProgressing;
|
---|
169 | this.refreshAutomaticallyCheckBox.Enabled = Content.IsControllable && alreadyUploaded && jobsLoaded && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
|
---|
170 | this.refreshButton.Enabled = Content.IsDownloadable && alreadyUploaded && !Content.IsProgressing;
|
---|
171 | this.Locked = !Content.IsControllable || Content.ExecutionState == ExecutionState.Started || Content.IsProgressing;
|
---|
172 | }
|
---|
173 | SetEnabledStateOfExecutableButtons();
|
---|
174 | tabControl_SelectedIndexChanged(this, EventArgs.Empty); // ensure sharing tabpage is disabled
|
---|
175 | }
|
---|
176 |
|
---|
177 | protected override void OnClosed(FormClosedEventArgs e) {
|
---|
178 | if (Content != null) {
|
---|
179 | if (Content.RefreshAutomatically)
|
---|
180 | Content.StopResultPolling();
|
---|
181 | }
|
---|
182 | base.OnClosed(e);
|
---|
183 | }
|
---|
184 |
|
---|
185 | #region Content Events
|
---|
186 | void Content_TaskReceived(object sender, EventArgs e) {
|
---|
187 | runCollectionViewHost.Content = GetAllRunsFromJob(Content);
|
---|
188 | }
|
---|
189 |
|
---|
190 | private void HiveTasks_ItemsAdded(object sender, CollectionItemsChangedEventArgs<HiveTask> e) {
|
---|
191 | if (InvokeRequired)
|
---|
192 | Invoke(new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsAdded), sender, e);
|
---|
193 | else {
|
---|
194 | SetEnabledStateOfControls();
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | private void HiveTasks_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<HiveTask> e) {
|
---|
199 | if (InvokeRequired)
|
---|
200 | Invoke(new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_ItemsRemoved), sender, e);
|
---|
201 | else {
|
---|
202 | SetEnabledStateOfControls();
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | private void HiveTasks_CollectionReset(object sender, CollectionItemsChangedEventArgs<HiveTask> e) {
|
---|
207 | if (InvokeRequired)
|
---|
208 | Invoke(new CollectionItemsChangedEventHandler<HiveTask>(HiveTasks_CollectionReset), sender, e);
|
---|
209 | else {
|
---|
210 | SetEnabledStateOfControls();
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | private void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
215 | if (InvokeRequired)
|
---|
216 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
217 | else
|
---|
218 | SetEnabledStateOfControls();
|
---|
219 | }
|
---|
220 | private void Content_Prepared(object sender, EventArgs e) {
|
---|
221 | if (InvokeRequired)
|
---|
222 | Invoke(new EventHandler(Content_Prepared), sender, e);
|
---|
223 | else {
|
---|
224 | nameTextBox.Enabled = true;
|
---|
225 | Locked = false;
|
---|
226 | SetEnabledStateOfControls();
|
---|
227 | }
|
---|
228 | }
|
---|
229 | private void Content_Started(object sender, EventArgs e) {
|
---|
230 | if (InvokeRequired)
|
---|
231 | Invoke(new EventHandler(Content_Started), sender, e);
|
---|
232 | else {
|
---|
233 | nameTextBox.Enabled = false;
|
---|
234 | SetEnabledStateOfControls();
|
---|
235 | }
|
---|
236 | }
|
---|
237 | private void Content_Paused(object sender, EventArgs e) {
|
---|
238 | if (InvokeRequired)
|
---|
239 | Invoke(new EventHandler(Content_Paused), sender, e);
|
---|
240 | else {
|
---|
241 | nameTextBox.Enabled = true;
|
---|
242 | SetEnabledStateOfControls();
|
---|
243 | }
|
---|
244 | }
|
---|
245 | private void Content_Stopped(object sender, EventArgs e) {
|
---|
246 | if (InvokeRequired)
|
---|
247 | Invoke(new EventHandler(Content_Stopped), sender, e);
|
---|
248 | else {
|
---|
249 | nameTextBox.Enabled = true;
|
---|
250 | Locked = false;
|
---|
251 | SetEnabledStateOfControls();
|
---|
252 | }
|
---|
253 | }
|
---|
254 | private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
255 | if (InvokeRequired)
|
---|
256 | Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
|
---|
257 | else
|
---|
258 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
259 | }
|
---|
260 | private void Content_RefreshAutomaticallyChanged(object sender, EventArgs e) {
|
---|
261 | if (InvokeRequired)
|
---|
262 | Invoke(new EventHandler(Content_RefreshAutomaticallyChanged), sender, e);
|
---|
263 | else {
|
---|
264 | refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically;
|
---|
265 | SetEnabledStateOfControls();
|
---|
266 | }
|
---|
267 | }
|
---|
268 | private void Content_HiveTasksChanged(object sender, EventArgs e) {
|
---|
269 | if (InvokeRequired)
|
---|
270 | Invoke(new EventHandler(Content_HiveTasksChanged), sender, e);
|
---|
271 | else {
|
---|
272 | if (Content != null && Content.HiveTasks != null) {
|
---|
273 | jobsTreeView.Content = Content.HiveTasks;
|
---|
274 | RegisterHiveJobEvents();
|
---|
275 | } else {
|
---|
276 | jobsTreeView.Content = null;
|
---|
277 | }
|
---|
278 | SetEnabledStateOfControls();
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | void Content_Loaded(object sender, EventArgs e) {
|
---|
283 | runCollectionViewHost.Content = GetAllRunsFromJob(Content);
|
---|
284 | }
|
---|
285 |
|
---|
286 | private void Content_HiveExperimentChanged(object sender, EventArgs e) {
|
---|
287 | if (Content != null && Content.Job != null) {
|
---|
288 | RegisterHiveExperimentEvents();
|
---|
289 | Content_IsProgressingChanged(sender, e);
|
---|
290 | }
|
---|
291 | }
|
---|
292 | private void Content_IsControllableChanged(object sender, EventArgs e) {
|
---|
293 | SetEnabledStateOfControls();
|
---|
294 | }
|
---|
295 | private void Content_JobStatisticsChanged(object sender, EventArgs e) {
|
---|
296 | if (InvokeRequired)
|
---|
297 | Invoke(new EventHandler(Content_JobStatisticsChanged), sender, e);
|
---|
298 | else {
|
---|
299 | if (Content != null) {
|
---|
300 | jobsTextBox.Text = (Content.Job.JobCount - Content.Job.CalculatingCount - Content.Job.FinishedCount).ToString();
|
---|
301 | calculatingTextBox.Text = Content.Job.CalculatingCount.ToString();
|
---|
302 | finishedTextBox.Text = Content.Job.FinishedCount.ToString();
|
---|
303 | } else {
|
---|
304 | jobsTextBox.Text = "0";
|
---|
305 | calculatingTextBox.Text = "0";
|
---|
306 | finishedTextBox.Text = "0";
|
---|
307 | }
|
---|
308 | }
|
---|
309 | }
|
---|
310 | private void Content_ExceptionOccured(object sender, EventArgs<Exception> e) {
|
---|
311 | if (InvokeRequired)
|
---|
312 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured), sender, e);
|
---|
313 | else {
|
---|
314 | //don't show the error dialog when downloading tasks, the HiveClient will throw an exception and the dialog will be shown then
|
---|
315 | if (sender.GetType() != typeof(ConcurrentTaskDownloader<ItemTask>) && sender.GetType() != typeof(TaskDownloader)) {
|
---|
316 | ErrorHandling.ShowErrorDialog(this, e.Value);
|
---|
317 | }
|
---|
318 | }
|
---|
319 | }
|
---|
320 | private void Content_StateLogListChanged(object sender, EventArgs e) {
|
---|
321 | if (InvokeRequired)
|
---|
322 | Invoke(new EventHandler(Content_StateLogListChanged), sender, e);
|
---|
323 | else {
|
---|
324 | UpdateStateLogList();
|
---|
325 | }
|
---|
326 | }
|
---|
327 | private void Content_IsAllowedPrivilegedChanged(object sender, EventArgs e) {
|
---|
328 | if (InvokeRequired)
|
---|
329 | Invoke(new EventHandler(Content_IsAllowedPrivilegedChanged), sender, e);
|
---|
330 | else {
|
---|
331 | SetEnabledStateOfControls();
|
---|
332 | }
|
---|
333 | }
|
---|
334 |
|
---|
335 | private void UpdateStateLogList() {
|
---|
336 | if (Content != null && this.Content.Job != null) {
|
---|
337 | stateLogViewHost.Content = this.Content.StateLogList;
|
---|
338 | } else {
|
---|
339 | stateLogViewHost.Content = null;
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | private void HiveExperiment_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
344 | if (this.Content != null && e.PropertyName == "Id") this.hiveExperimentPermissionListView.HiveExperimentId = this.Content.Job.Id;
|
---|
345 | }
|
---|
346 | #endregion
|
---|
347 |
|
---|
348 | #region Control events
|
---|
349 | private void searchButton_Click(object sender, EventArgs e) {
|
---|
350 | if (hiveResourceSelectorDialog == null)
|
---|
351 | hiveResourceSelectorDialog = new HiveResourceSelectorDialog();
|
---|
352 | if (hiveResourceSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
353 | StringBuilder sb = new StringBuilder();
|
---|
354 | foreach (Resource resource in hiveResourceSelectorDialog.GetSelectedResources()) {
|
---|
355 | sb.Append(resource.Name);
|
---|
356 | sb.Append(";");
|
---|
357 | }
|
---|
358 | resourceNamesTextBox.Text = sb.ToString();
|
---|
359 | }
|
---|
360 | }
|
---|
361 |
|
---|
362 | private void startButton_Click(object sender, EventArgs e) {
|
---|
363 | if (nameTextBox.Text.Trim() == string.Empty) {
|
---|
364 | MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
365 | } else if (Content.ExecutionState == ExecutionState.Paused) {
|
---|
366 | var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
|
---|
367 | task.ContinueWith((t) => {
|
---|
368 | progress.Finish();
|
---|
369 | MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
370 | Content.Log.LogException(t.Exception);
|
---|
371 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
372 | } else {
|
---|
373 | HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
|
---|
374 | }
|
---|
375 | }
|
---|
376 |
|
---|
377 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
378 | var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content);
|
---|
379 | task.ContinueWith((t) => {
|
---|
380 | progress.Finish();
|
---|
381 | MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
382 | Content.Log.LogException(t.Exception);
|
---|
383 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
384 | }
|
---|
385 |
|
---|
386 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
387 | var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content);
|
---|
388 | task.ContinueWith((t) => {
|
---|
389 | progress.Finish();
|
---|
390 | MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
391 | Content.Log.LogException(t.Exception);
|
---|
392 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
393 | }
|
---|
394 | private void resetButton_Click(object sender, EventArgs e) { }
|
---|
395 |
|
---|
396 | private void PauseJobAsync(object job) {
|
---|
397 | progress.Status = "Pausing job...";
|
---|
398 | progress.ProgressState = ProgressState.Started;
|
---|
399 | HiveClient.PauseJob((RefreshableJob)job);
|
---|
400 | }
|
---|
401 |
|
---|
402 | private void StopJobAsync(object job) {
|
---|
403 | progress.Status = "Stopping job...";
|
---|
404 | progress.ProgressState = ProgressState.Started;
|
---|
405 | HiveClient.StopJob((RefreshableJob)job);
|
---|
406 | }
|
---|
407 |
|
---|
408 | private void ResumeJobAsync(object job) {
|
---|
409 | progress.Status = "Resuming job...";
|
---|
410 | progress.ProgressState = ProgressState.Started;
|
---|
411 | HiveClient.ResumeJob((RefreshableJob)job);
|
---|
412 | }
|
---|
413 |
|
---|
414 | private void nameTextBox_Validated(object sender, EventArgs e) {
|
---|
415 | if (Content.Job.Name != nameTextBox.Text)
|
---|
416 | Content.Job.Name = nameTextBox.Text;
|
---|
417 | }
|
---|
418 |
|
---|
419 | private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
|
---|
420 | if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
|
---|
421 | Content.Job.ResourceNames = resourceNamesTextBox.Text;
|
---|
422 | }
|
---|
423 |
|
---|
424 | private void refreshAutomaticallyCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
425 | if (Content != null) Content.RefreshAutomatically = refreshAutomaticallyCheckBox.Checked;
|
---|
426 | }
|
---|
427 |
|
---|
428 | private void isPrivilegedCheckBox_Validated(object sender, EventArgs e) {
|
---|
429 | if (Content != null) Content.Job.IsPrivileged = isPrivilegedCheckBox.Checked;
|
---|
430 | }
|
---|
431 |
|
---|
432 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
433 | var invoker = new Action<RefreshableJob>(HiveClient.LoadJob);
|
---|
434 | invoker.BeginInvoke(Content, (ar) => {
|
---|
435 | try {
|
---|
436 | invoker.EndInvoke(ar);
|
---|
437 | }
|
---|
438 | catch (Exception ex) {
|
---|
439 | ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
|
---|
440 | }
|
---|
441 | }, null);
|
---|
442 | }
|
---|
443 |
|
---|
444 | private void refreshPermissionsButton_Click(object sender, EventArgs e) {
|
---|
445 | if (this.Content.Job.Id == Guid.Empty) {
|
---|
446 | MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
447 | } else {
|
---|
448 | hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id);
|
---|
449 | }
|
---|
450 | }
|
---|
451 | #endregion
|
---|
452 |
|
---|
453 | #region Helpers
|
---|
454 | private void SetEnabledStateOfExecutableButtons() {
|
---|
455 | if (Content == null) {
|
---|
456 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
|
---|
457 | } else {
|
---|
458 | startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
|
---|
459 | pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
|
---|
460 | stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
|
---|
461 | resetButton.Enabled = false;
|
---|
462 | }
|
---|
463 | }
|
---|
464 | #endregion
|
---|
465 |
|
---|
466 | #region Progress reporting
|
---|
467 | private void Content_IsProgressingChanged(object sender, EventArgs e) {
|
---|
468 | if (this.InvokeRequired) {
|
---|
469 | Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
|
---|
470 | } else {
|
---|
471 | if (Content != null && Content.Progress != null && Content.IsProgressing) {
|
---|
472 | progressView.Content = Content.Progress;
|
---|
473 | } else if (Content != null) {
|
---|
474 | progressView.Content = progress;
|
---|
475 | }
|
---|
476 | }
|
---|
477 | }
|
---|
478 | #endregion
|
---|
479 |
|
---|
480 | #region Drag & Drop
|
---|
481 | private void jobsTreeView_DragOver(object sender, DragEventArgs e) {
|
---|
482 | jobsTreeView_DragEnter(sender, e);
|
---|
483 | }
|
---|
484 |
|
---|
485 | private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
|
---|
486 | e.Effect = DragDropEffects.None;
|
---|
487 | var obj = e.Data.GetData(Constants.DragDropDataFormat);
|
---|
488 | if (obj is IOptimizer) {
|
---|
489 | if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
|
---|
490 | else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
491 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
|
---|
496 | if (e.Effect != DragDropEffects.None) {
|
---|
497 | var obj = e.Data.GetData(Constants.DragDropDataFormat);
|
---|
498 |
|
---|
499 | var optimizer = obj as IOptimizer;
|
---|
500 | if (optimizer != null) {
|
---|
501 | IOptimizer newOptimizer = null;
|
---|
502 | if (e.Effect.HasFlag(DragDropEffects.Copy)) {
|
---|
503 | newOptimizer = (IOptimizer)optimizer.Clone();
|
---|
504 | } else {
|
---|
505 | newOptimizer = optimizer;
|
---|
506 | }
|
---|
507 | if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
|
---|
508 | newOptimizer.Prepare();
|
---|
509 | }
|
---|
510 |
|
---|
511 | Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
|
---|
512 | }
|
---|
513 | }
|
---|
514 | }
|
---|
515 | #endregion
|
---|
516 |
|
---|
517 | private void tabControl_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
518 | if (tabControl.SelectedTab == permissionTabPage) {
|
---|
519 | if (!Content.IsSharable) {
|
---|
520 | MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
521 | tabControl.SelectedTab = tasksTabPage;
|
---|
522 | }
|
---|
523 | }
|
---|
524 | }
|
---|
525 |
|
---|
526 | private RunCollection GetAllRunsFromJob(RefreshableJob job) {
|
---|
527 | if (job != null) {
|
---|
528 | RunCollection runs = new RunCollection();
|
---|
529 |
|
---|
530 | foreach (HiveTask subTask in job.HiveTasks) {
|
---|
531 | if (subTask is OptimizerHiveTask) {
|
---|
532 | OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
|
---|
533 | runs.AddRange(ohTask.ItemTask.Item.Runs);
|
---|
534 | }
|
---|
535 | }
|
---|
536 | return runs;
|
---|
537 | } else {
|
---|
538 | return null;
|
---|
539 | }
|
---|
540 | }
|
---|
541 | }
|
---|
542 | }
|
---|