Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceReintegration/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs @ 16300

Last change on this file since 16300 was 14927, checked in by gkronber, 8 years ago

#2520: changed all usages of StorableClass to use StorableType with an auto-generated GUID (did not add StorableType to other type definitions yet)

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