Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1950

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