Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1950 fixed handling of IsAllowedPrivileged in the Hive Job Manager

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