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