Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1950 fixed an InvalidOperationException in the Hive Job Manager

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 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        if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
360          Content.Job.ResourceNames = resourceNamesTextBox.Text;
361      }
362    }
363
364    private void startButton_Click(object sender, EventArgs e) {
365      if (nameTextBox.Text.Trim() == string.Empty) {
366        MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
367      } else if (Content.ExecutionState == ExecutionState.Paused) {
368        var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
369        task.ContinueWith((t) => {
370          progress.Finish();
371          MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
372          Content.Log.LogException(t.Exception);
373        }, TaskContinuationOptions.OnlyOnFaulted);
374      } else {
375        HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
376      }
377    }
378
379    private void pauseButton_Click(object sender, EventArgs e) {
380      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content);
381      task.ContinueWith((t) => {
382        progress.Finish();
383        MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
384        Content.Log.LogException(t.Exception);
385      }, TaskContinuationOptions.OnlyOnFaulted);
386    }
387
388    private void stopButton_Click(object sender, EventArgs e) {
389      var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content);
390      task.ContinueWith((t) => {
391        progress.Finish();
392        MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
393        Content.Log.LogException(t.Exception);
394      }, TaskContinuationOptions.OnlyOnFaulted);
395    }
396    private void resetButton_Click(object sender, EventArgs e) { }
397
398    private void PauseJobAsync(object job) {
399      progress.Status = "Pausing job...";
400      progress.ProgressState = ProgressState.Started;
401      HiveClient.PauseJob((RefreshableJob)job);
402      progress.Finish();
403    }
404
405    private void StopJobAsync(object job) {
406      progress.Status = "Stopping job...";
407      progress.ProgressState = ProgressState.Started;
408      HiveClient.StopJob((RefreshableJob)job);
409      progress.Finish();
410    }
411
412    private void ResumeJobAsync(object job) {
413      progress.Status = "Resuming job...";
414      progress.ProgressState = ProgressState.Started;
415      HiveClient.ResumeJob((RefreshableJob)job);
416      progress.Finish();
417    }
418
419    private void nameTextBox_Validated(object sender, EventArgs e) {
420      if (Content.Job.Name != nameTextBox.Text)
421        Content.Job.Name = nameTextBox.Text;
422    }
423
424    private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
425      if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
426        Content.Job.ResourceNames = resourceNamesTextBox.Text;
427    }
428
429    private void refreshAutomaticallyCheckBox_CheckedChanged(object sender, EventArgs e) {
430      if (Content != null) Content.RefreshAutomatically = refreshAutomaticallyCheckBox.Checked;
431    }
432
433    private void isPrivilegedCheckBox_Validated(object sender, EventArgs e) {
434      if (Content != null) Content.Job.IsPrivileged = isPrivilegedCheckBox.Checked;
435    }
436
437    private void refreshButton_Click(object sender, EventArgs e) {
438      var invoker = new Action<RefreshableJob>(HiveClient.LoadJob);
439      invoker.BeginInvoke(Content, (ar) => {
440        try {
441          invoker.EndInvoke(ar);
442        }
443        catch (Exception ex) {
444          ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
445        }
446      }, null);
447    }
448
449    private void refreshPermissionsButton_Click(object sender, EventArgs e) {
450      if (this.Content.Job.Id == Guid.Empty) {
451        MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
452      } else {
453        hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id);
454      }
455    }
456    #endregion
457
458    #region Helpers
459    private void SetEnabledStateOfExecutableButtons() {
460      if (Content == null) {
461        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
462      } else {
463        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
464        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
465        stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
466        resetButton.Enabled = false;
467      }
468    }
469    #endregion
470
471    #region Progress reporting
472    private void Content_IsProgressingChanged(object sender, EventArgs e) {
473      if (this.InvokeRequired) {
474        Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
475      } else {
476        if (Content != null && Content.Progress != null && Content.IsProgressing) {
477          progressView.Content = Content.Progress;
478        } else if (Content != null) {
479          progressView.Content = progress;
480        }
481      }
482    }
483    #endregion
484
485    #region Drag & Drop
486    private void jobsTreeView_DragOver(object sender, DragEventArgs e) {
487      jobsTreeView_DragEnter(sender, e);
488    }
489
490    private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
491      e.Effect = DragDropEffects.None;
492      var obj = e.Data.GetData(Constants.DragDropDataFormat);
493      if (obj is IOptimizer) {
494        if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
495        else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
496        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
497      }
498    }
499
500    private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
501      if (e.Effect != DragDropEffects.None) {
502        var obj = e.Data.GetData(Constants.DragDropDataFormat);
503
504        var optimizer = obj as IOptimizer;
505        if (optimizer != null) {
506          IOptimizer newOptimizer = null;
507          if (e.Effect.HasFlag(DragDropEffects.Copy)) {
508            newOptimizer = (IOptimizer)optimizer.Clone();
509            newOptimizer.Runs.Clear();
510          } else {
511            newOptimizer = optimizer;
512          }
513          if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
514            newOptimizer.Prepare();
515          }
516
517          Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
518        }
519      }
520    }
521    #endregion
522
523    private void tabControl_SelectedIndexChanged(object sender, EventArgs e) {
524      if (tabControl.SelectedTab == permissionTabPage) {
525        if (!Content.IsSharable) {
526          MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
527          tabControl.SelectedTab = tasksTabPage;
528        }
529      }
530    }
531
532    private RunCollection GetAllRunsFromJob(RefreshableJob job) {
533      if (job != null) {
534        RunCollection runs = new RunCollection();
535
536        foreach (HiveTask subTask in job.HiveTasks) {
537          if (subTask is OptimizerHiveTask) {
538            OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
539            runs.AddRange(ohTask.GetRuns());
540          }
541        }
542        return runs;
543      } else {
544        return null;
545      }
546    }
547  }
548}
Note: See TracBrowser for help on using the repository browser.