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