Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9456 was 9456, checked in by swagner, 11 years ago

Updated copyright year and added some missing license headers (#1889)

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