Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8914 was 8914, checked in by ascheibe, 11 years ago

#1950

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