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