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