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