Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs @ 8146

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

#1762 fixed unit test

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