Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8109 was 8109, checked in by jkarder, 12 years ago

#1722: fixed creation and parsing of the resource string in the Hive Job Manager

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