[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 |
|
---|
| 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 {
|
---|
[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 | }
|
---|
[9710] | 328 | if (InvokeRequired) {
|
---|
| 329 | Invoke(new Action(() => { isPrivilegedCheckBox.Checked = Content.Job.IsPrivileged; }));
|
---|
| 330 | } else {
|
---|
| 331 | isPrivilegedCheckBox.Checked = Content.Job.IsPrivileged;
|
---|
| 332 | }
|
---|
[6976] | 333 | }
|
---|
| 334 |
|
---|
| 335 | private void Content_HiveExperimentChanged(object sender, EventArgs e) {
|
---|
| 336 | if (Content != null && Content.Job != null) {
|
---|
| 337 | RegisterHiveExperimentEvents();
|
---|
| 338 | Content_IsProgressingChanged(sender, e);
|
---|
| 339 | }
|
---|
| 340 | }
|
---|
| 341 | private void Content_IsControllableChanged(object sender, EventArgs e) {
|
---|
| 342 | SetEnabledStateOfControls();
|
---|
| 343 | }
|
---|
| 344 | private void Content_JobStatisticsChanged(object sender, EventArgs e) {
|
---|
| 345 | if (InvokeRequired)
|
---|
| 346 | Invoke(new EventHandler(Content_JobStatisticsChanged), sender, e);
|
---|
| 347 | else {
|
---|
| 348 | if (Content != null) {
|
---|
| 349 | jobsTextBox.Text = (Content.Job.JobCount - Content.Job.CalculatingCount - Content.Job.FinishedCount).ToString();
|
---|
| 350 | calculatingTextBox.Text = Content.Job.CalculatingCount.ToString();
|
---|
| 351 | finishedTextBox.Text = Content.Job.FinishedCount.ToString();
|
---|
| 352 | } else {
|
---|
| 353 | jobsTextBox.Text = "0";
|
---|
| 354 | calculatingTextBox.Text = "0";
|
---|
| 355 | finishedTextBox.Text = "0";
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
| 358 | }
|
---|
| 359 | private void Content_ExceptionOccured(object sender, EventArgs<Exception> e) {
|
---|
[7409] | 360 | if (InvokeRequired)
|
---|
| 361 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured), sender, e);
|
---|
| 362 | else {
|
---|
| 363 | //don't show the error dialog when downloading tasks, the HiveClient will throw an exception and the dialog will be shown then
|
---|
| 364 | if (sender.GetType() != typeof(ConcurrentTaskDownloader<ItemTask>) && sender.GetType() != typeof(TaskDownloader)) {
|
---|
| 365 | ErrorHandling.ShowErrorDialog(this, e.Value);
|
---|
| 366 | }
|
---|
| 367 | }
|
---|
[6976] | 368 | }
|
---|
| 369 | private void Content_StateLogListChanged(object sender, EventArgs e) {
|
---|
| 370 | if (InvokeRequired)
|
---|
| 371 | Invoke(new EventHandler(Content_StateLogListChanged), sender, e);
|
---|
| 372 | else {
|
---|
| 373 | UpdateStateLogList();
|
---|
| 374 | }
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | private void UpdateStateLogList() {
|
---|
| 378 | if (Content != null && this.Content.Job != null) {
|
---|
| 379 | stateLogViewHost.Content = this.Content.StateLogList;
|
---|
| 380 | } else {
|
---|
| 381 | stateLogViewHost.Content = null;
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | private void HiveExperiment_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 386 | if (this.Content != null && e.PropertyName == "Id") this.hiveExperimentPermissionListView.HiveExperimentId = this.Content.Job.Id;
|
---|
| 387 | }
|
---|
| 388 | #endregion
|
---|
| 389 |
|
---|
| 390 | #region Control events
|
---|
[7910] | 391 | private void searchButton_Click(object sender, EventArgs e) {
|
---|
| 392 | if (hiveResourceSelectorDialog == null)
|
---|
| 393 | hiveResourceSelectorDialog = new HiveResourceSelectorDialog();
|
---|
| 394 | if (hiveResourceSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 395 | StringBuilder sb = new StringBuilder();
|
---|
| 396 | foreach (Resource resource in hiveResourceSelectorDialog.GetSelectedResources()) {
|
---|
| 397 | sb.Append(resource.Name);
|
---|
[8109] | 398 | sb.Append(";");
|
---|
[7910] | 399 | }
|
---|
| 400 | resourceNamesTextBox.Text = sb.ToString();
|
---|
[8690] | 401 | if (Content.Job.ResourceNames != resourceNamesTextBox.Text)
|
---|
| 402 | Content.Job.ResourceNames = resourceNamesTextBox.Text;
|
---|
[7910] | 403 | }
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[6976] | 406 | private void startButton_Click(object sender, EventArgs e) {
|
---|
[7068] | 407 | if (nameTextBox.Text.Trim() == string.Empty) {
|
---|
| 408 | MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
[7162] | 409 | } else if (Content.ExecutionState == ExecutionState.Paused) {
|
---|
[7156] | 410 | var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
|
---|
| 411 | task.ContinueWith((t) => {
|
---|
[8165] | 412 | progress.Finish();
|
---|
[7156] | 413 | MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 414 | Content.Log.LogException(t.Exception);
|
---|
| 415 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
[7068] | 416 | } else {
|
---|
| 417 | HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
|
---|
| 418 | }
|
---|
[6976] | 419 | }
|
---|
[7156] | 420 |
|
---|
[6976] | 421 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
[7156] | 422 | var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content);
|
---|
[7162] | 423 | task.ContinueWith((t) => {
|
---|
[8165] | 424 | progress.Finish();
|
---|
[7156] | 425 | MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 426 | Content.Log.LogException(t.Exception);
|
---|
| 427 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
[7162] | 428 | }
|
---|
[7156] | 429 |
|
---|
[6976] | 430 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
[7156] | 431 | var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content);
|
---|
| 432 | task.ContinueWith((t) => {
|
---|
[8165] | 433 | progress.Finish();
|
---|
[7156] | 434 | MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 435 | Content.Log.LogException(t.Exception);
|
---|
| 436 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
[6976] | 437 | }
|
---|
| 438 | private void resetButton_Click(object sender, EventArgs e) { }
|
---|
| 439 |
|
---|
[7156] | 440 | private void PauseJobAsync(object job) {
|
---|
[8165] | 441 | progress.Status = "Pausing job...";
|
---|
| 442 | progress.ProgressState = ProgressState.Started;
|
---|
[7156] | 443 | HiveClient.PauseJob((RefreshableJob)job);
|
---|
[8186] | 444 | progress.Finish();
|
---|
[7156] | 445 | }
|
---|
| 446 |
|
---|
| 447 | private void StopJobAsync(object job) {
|
---|
[8165] | 448 | progress.Status = "Stopping job...";
|
---|
| 449 | progress.ProgressState = ProgressState.Started;
|
---|
[7156] | 450 | HiveClient.StopJob((RefreshableJob)job);
|
---|
[8186] | 451 | progress.Finish();
|
---|
[7156] | 452 | }
|
---|
| 453 |
|
---|
| 454 | private void ResumeJobAsync(object job) {
|
---|
[8165] | 455 | progress.Status = "Resuming job...";
|
---|
| 456 | progress.ProgressState = ProgressState.Started;
|
---|
[7156] | 457 | HiveClient.ResumeJob((RefreshableJob)job);
|
---|
[8186] | 458 | progress.Finish();
|
---|
[7156] | 459 | }
|
---|
| 460 |
|
---|
[6976] | 461 | private void nameTextBox_Validated(object sender, EventArgs e) {
|
---|
[9219] | 462 | if (!SuppressEvents && Content.Job != null && Content.Job.Name != nameTextBox.Text)
|
---|
[6976] | 463 | Content.Job.Name = nameTextBox.Text;
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | private void resourceNamesTextBox_Validated(object sender, EventArgs e) {
|
---|
[9219] | 467 | if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text)
|
---|
[6976] | 468 | Content.Job.ResourceNames = resourceNamesTextBox.Text;
|
---|
| 469 | }
|
---|
| 470 |
|
---|
[8090] | 471 | private void refreshAutomaticallyCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[8914] | 472 | if (Content != null && !SuppressEvents) Content.RefreshAutomatically = refreshAutomaticallyCheckBox.Checked;
|
---|
[6976] | 473 | }
|
---|
| 474 |
|
---|
[9107] | 475 | private void isPrivilegedCheckBox_CheckChanged(object sender, EventArgs e) {
|
---|
[9436] | 476 | if (Content != null && !SuppressEvents) Content.Job.IsPrivileged = isPrivilegedCheckBox.Checked;
|
---|
[6976] | 477 | }
|
---|
| 478 |
|
---|
| 479 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
| 480 | var invoker = new Action<RefreshableJob>(HiveClient.LoadJob);
|
---|
| 481 | invoker.BeginInvoke(Content, (ar) => {
|
---|
| 482 | try {
|
---|
| 483 | invoker.EndInvoke(ar);
|
---|
| 484 | }
|
---|
| 485 | catch (Exception ex) {
|
---|
| 486 | ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex);
|
---|
| 487 | }
|
---|
| 488 | }, null);
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | private void refreshPermissionsButton_Click(object sender, EventArgs e) {
|
---|
[7029] | 492 | if (this.Content.Job.Id == Guid.Empty) {
|
---|
| 493 | MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
| 494 | } else {
|
---|
| 495 | hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id);
|
---|
| 496 | }
|
---|
[6976] | 497 | }
|
---|
| 498 | #endregion
|
---|
| 499 |
|
---|
| 500 | #region Helpers
|
---|
| 501 | private void SetEnabledStateOfExecutableButtons() {
|
---|
| 502 | if (Content == null) {
|
---|
| 503 | startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
|
---|
| 504 | } else {
|
---|
[8159] | 505 | startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing;
|
---|
| 506 | pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
|
---|
| 507 | stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing;
|
---|
[6976] | 508 | resetButton.Enabled = false;
|
---|
| 509 | }
|
---|
| 510 | }
|
---|
| 511 | #endregion
|
---|
| 512 |
|
---|
| 513 | #region Progress reporting
|
---|
| 514 | private void Content_IsProgressingChanged(object sender, EventArgs e) {
|
---|
| 515 | if (this.InvokeRequired) {
|
---|
| 516 | Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);
|
---|
| 517 | } else {
|
---|
[8156] | 518 | if (Content != null && Content.Progress != null && Content.IsProgressing) {
|
---|
[8165] | 519 | progressView.Content = Content.Progress;
|
---|
[8166] | 520 | } else if (Content != null) {
|
---|
[8165] | 521 | progressView.Content = progress;
|
---|
[6976] | 522 | }
|
---|
| 523 | }
|
---|
| 524 | }
|
---|
| 525 | #endregion
|
---|
| 526 |
|
---|
| 527 | #region Drag & Drop
|
---|
| 528 | private void jobsTreeView_DragOver(object sender, DragEventArgs e) {
|
---|
| 529 | jobsTreeView_DragEnter(sender, e);
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | private void jobsTreeView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 533 | e.Effect = DragDropEffects.None;
|
---|
| 534 | var obj = e.Data.GetData(Constants.DragDropDataFormat);
|
---|
| 535 | if (obj is IOptimizer) {
|
---|
[7067] | 536 | if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None;
|
---|
| 537 | else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
[6976] | 538 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 | private void jobsTreeView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 543 | if (e.Effect != DragDropEffects.None) {
|
---|
| 544 | var obj = e.Data.GetData(Constants.DragDropDataFormat);
|
---|
| 545 |
|
---|
| 546 | var optimizer = obj as IOptimizer;
|
---|
| 547 | if (optimizer != null) {
|
---|
[7067] | 548 | IOptimizer newOptimizer = null;
|
---|
| 549 | if (e.Effect.HasFlag(DragDropEffects.Copy)) {
|
---|
| 550 | newOptimizer = (IOptimizer)optimizer.Clone();
|
---|
[8341] | 551 | newOptimizer.Runs.Clear();
|
---|
[7067] | 552 | } else {
|
---|
| 553 | newOptimizer = optimizer;
|
---|
| 554 | }
|
---|
| 555 | if (newOptimizer.ExecutionState != ExecutionState.Prepared) {
|
---|
| 556 | newOptimizer.Prepare();
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | Content.HiveTasks.Add(new OptimizerHiveTask(newOptimizer));
|
---|
[6976] | 560 | }
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 | #endregion
|
---|
| 564 |
|
---|
| 565 | private void tabControl_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 566 | if (tabControl.SelectedTab == permissionTabPage) {
|
---|
| 567 | if (!Content.IsSharable) {
|
---|
[7162] | 568 | MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
[6976] | 569 | tabControl.SelectedTab = tasksTabPage;
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | private RunCollection GetAllRunsFromJob(RefreshableJob job) {
|
---|
| 575 | if (job != null) {
|
---|
[8962] | 576 | RunCollection runs = new RunCollection() { OptimizerName = job.ItemName };
|
---|
[6976] | 577 |
|
---|
[8700] | 578 | foreach (HiveTask subTask in job.HiveTasks) {
|
---|
| 579 | if (subTask is OptimizerHiveTask) {
|
---|
| 580 | OptimizerHiveTask ohTask = subTask as OptimizerHiveTask;
|
---|
[8939] | 581 | ohTask.ExecuteReadActionOnItemTask(new Action(delegate() {
|
---|
| 582 | runs.AddRange(ohTask.ItemTask.Item.Runs);
|
---|
| 583 | }));
|
---|
[8700] | 584 | }
|
---|
[6976] | 585 | }
|
---|
| 586 | return runs;
|
---|
| 587 | } else {
|
---|
| 588 | return null;
|
---|
| 589 | }
|
---|
| 590 | }
|
---|
[9219] | 591 |
|
---|
| 592 | private void UnloadButton_Click(object sender, EventArgs e) {
|
---|
| 593 | Content.Unload();
|
---|
| 594 | runCollectionViewHost.Content = null;
|
---|
| 595 | stateLogViewHost.Content = null;
|
---|
| 596 | hiveExperimentPermissionListView.Content = null;
|
---|
| 597 | jobsTreeView.Content = null;
|
---|
| 598 |
|
---|
| 599 | SetEnabledStateOfControls();
|
---|
| 600 | }
|
---|
[6976] | 601 | }
|
---|
| 602 | }
|
---|