Free cookie consent management tool by TermsFeed Policy Generator

source: branches/gteufl/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs @ 11813

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

#2117

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