Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs @ 9070

Last change on this file since 9070 was 8186, checked in by ascheibe, 12 years ago

#1762 fixed activation/deactivation of progress view

File size: 23.6 KB
Line 
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
22using System;
23using System.ComponentModel;
24using System.Linq;
25using System.Text;
26using System.Threading;
27using System.Threading.Tasks;
28using System.Windows.Forms;
29using HeuristicLab.Collections;
30using HeuristicLab.Common;
31using HeuristicLab.Core;
32using HeuristicLab.MainForm;
33using HeuristicLab.MainForm.WindowsForms;
34using HeuristicLab.Optimization;
35using HeuristicLab.PluginInfrastructure;
36
37namespace 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 = false,
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      progress.Finish();
401    }
402
403    private void StopJobAsync(object job) {
404      progress.Status = "Stopping job...";
405      progress.ProgressState = ProgressState.Started;
406      HiveClient.StopJob((RefreshableJob)job);
407      progress.Finish();
408    }
409
410    private void ResumeJobAsync(object job) {
411      progress.Status = "Resuming job...";
412      progress.ProgressState = ProgressState.Started;
413      HiveClient.ResumeJob((RefreshableJob)job);
414      progress.Finish();
415    }
416
417    private void nameTextBox_Validated(object sender, EventArgs e) {
418      if (Content.Job.Name != nameTextBox.Text)
419        Content.Job.Name = nameTextBox.Text;
420    }
421
422    private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
423      if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
424        Content.Job.ResourceNames = resourceNamesTextBox.Text;
425    }
426
427    private void refreshAutomaticallyCheckBox_CheckedChanged(object sender, EventArgs e) {
428      if (Content != null) Content.RefreshAutomatically = refreshAutomaticallyCheckBox.Checked;
429    }
430
431    private void isPrivilegedCheckBox_Validated(object sender, EventArgs e) {
432      if (Content != null) Content.Job.IsPrivileged = isPrivilegedCheckBox.Checked;
433    }
434
435    private void refreshButton_Click(object sender, EventArgs e) {
436      var invoker = new Action<RefreshableJob>(HiveClient.LoadJob);
437      invoker.BeginInvoke(Content, (ar) => {
438        try {
439          invoker.EndInvoke(ar);
440        }
441        catch (Exception ex) {
442          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
443        }
444      }, null);
445    }
446
447    private void refreshPermissionsButton_Click(object sender, EventArgs e) {
448      if (this.Content.Job.Id == Guid.Empty) {
449        MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
450      } else {
451        hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id);
452      }
453    }
454    #endregion
455
456    #region Helpers
457    private void SetEnabledStateOfExecutableButtons() {
458      if (Content == null) {
459        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
460      } else {
461        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
462        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
463        stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
464        resetButton.Enabled = false;
465      }
466    }
467    #endregion
468
469    #region Progress reporting
470    private void Content_IsProgressingChanged(object sender, EventArgs e) {
471      if (this.InvokeRequired) {
472        Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
473      } else {
474        if (Content != null && Content.Progress != null && Content.IsProgressing) {
475          progressView.Content = Content.Progress;
476        } else if (Content != null) {
477          progressView.Content = progress;
478        }
479      }
480    }
481    #endregion
482
483    #region Drag & Drop
484    private void jobsTreeView_DragOver(object sender, DragEventArgs e) {
485      jobsTreeView_DragEnter(sender, e);
486    }
487
488    private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
489      e.Effect = DragDropEffects.None;
490      var obj = e.Data.GetData(Constants.DragDropDataFormat);
491      if (obj is IOptimizer) {
492        if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
493        else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
494        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
495      }
496    }
497
498    private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
499      if (e.Effect != DragDropEffects.None) {
500        var obj = e.Data.GetData(Constants.DragDropDataFormat);
501
502        var optimizer = obj as IOptimizer;
503        if (optimizer != null) {
504          IOptimizer newOptimizer = null;
505          if (e.Effect.HasFlag(DragDropEffects.Copy)) {
506            newOptimizer = (IOptimizer)optimizer.Clone();
507          } else {
508            newOptimizer = optimizer;
509          }
510          if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
511            newOptimizer.Prepare();
512          }
513
514          Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
515        }
516      }
517    }
518    #endregion
519
520    private void tabControl_SelectedIndexChanged(object sender, EventArgs e) {
521      if (tabControl.SelectedTab == permissionTabPage) {
522        if (!Content.IsSharable) {
523          MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
524          tabControl.SelectedTab = tasksTabPage;
525        }
526      }
527    }
528
529    private RunCollection GetAllRunsFromJob(RefreshableJob job) {
530      if (job != null) {
531        RunCollection runs = new RunCollection();
532
533        foreach (HiveTask subTask in job.HiveTasks) {
534          if (subTask is OptimizerHiveTask) {
535            OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
536            runs.AddRange(ohTask.ItemTask.Item.Runs);
537          }
538        }
539        return runs;
540      } else {
541        return null;
542      }
543    }
544  }
545}
Note: See TracBrowser for help on using the repository browser.