[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;
|
---|
[7582] | 23 | using System.Threading.Tasks;
|
---|
[6976] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
[7582] | 26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[7156] | 27 | using HeuristicLab.PluginInfrastructure;
|
---|
[6976] | 28 |
|
---|
| 29 | namespace HeuristicLab.Clients.Hive.Views {
|
---|
| 30 | [View("OptimizerHiveTask View")]
|
---|
| 31 | [Content(typeof(OptimizerHiveTask), true)]
|
---|
| 32 | public partial class OptimizerHiveTaskView : HiveTaskView {
|
---|
[8206] | 33 | private Progress progress;
|
---|
[7156] | 34 | private ProgressView progressView;
|
---|
| 35 |
|
---|
[6976] | 36 | public new OptimizerHiveTask Content {
|
---|
| 37 | get { return (OptimizerHiveTask)base.Content; }
|
---|
| 38 | set {
|
---|
| 39 | if (base.Content != value) {
|
---|
| 40 | base.Content = value;
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public OptimizerHiveTaskView() {
|
---|
| 46 | InitializeComponent();
|
---|
[8206] | 47 | progress = new Progress() {
|
---|
| 48 | CanBeCanceled = false,
|
---|
| 49 | ProgressState = ProgressState.Finished
|
---|
| 50 | };
|
---|
[6976] | 51 | }
|
---|
| 52 |
|
---|
| 53 | protected override void Job_ItemChanged(object sender, EventArgs e) {
|
---|
| 54 | if (Content != null && Content.Task != null && Content.ItemTask.Item != null) {
|
---|
| 55 | runCollectionViewHost.Content = Content.ItemTask.Item.Runs;
|
---|
| 56 | } else {
|
---|
| 57 | runCollectionViewHost.Content = null;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | #region Content Events
|
---|
| 61 | protected override void RegisterContentEvents() {
|
---|
| 62 | base.RegisterContentEvents();
|
---|
| 63 | Content.IsControllableChanged += new EventHandler(Content_IsControllableChanged);
|
---|
[8206] | 64 | progressView = new ProgressView(this, progress);
|
---|
[6976] | 65 | }
|
---|
| 66 |
|
---|
| 67 | protected override void DeregisterContentEvents() {
|
---|
| 68 | Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged);
|
---|
[8206] | 69 | if (progressView != null) {
|
---|
| 70 | progressView.Content = null;
|
---|
| 71 | progressView.Dispose();
|
---|
| 72 | progressView = null;
|
---|
| 73 | }
|
---|
[6976] | 74 | base.DeregisterContentEvents();
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | protected virtual void Content_IsControllableChanged(object sender, EventArgs e) {
|
---|
| 78 | SetEnabledStateOfControls();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | #endregion
|
---|
| 82 |
|
---|
| 83 | #region Child Control Events
|
---|
| 84 | private void restartButton_Click(object sender, EventArgs e) {
|
---|
[7156] | 85 | var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync);
|
---|
| 86 | task.ContinueWith((t) => {
|
---|
[8206] | 87 | progress.Finish();
|
---|
[7156] | 88 | ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception);
|
---|
[7582] | 89 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
[6976] | 90 | }
|
---|
| 91 |
|
---|
| 92 | private void pauseButton_Click(object sender, EventArgs e) {
|
---|
[7156] | 93 | var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync);
|
---|
| 94 | task.ContinueWith((t) => {
|
---|
[8206] | 95 | progress.Finish();
|
---|
[7156] | 96 | ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception);
|
---|
| 97 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
[6976] | 98 | }
|
---|
| 99 |
|
---|
| 100 | private void stopButton_Click(object sender, EventArgs e) {
|
---|
[7156] | 101 | var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync);
|
---|
| 102 | task.ContinueWith((t) => {
|
---|
[8206] | 103 | progress.Finish();
|
---|
[7156] | 104 | ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception);
|
---|
| 105 | }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
[6976] | 106 | }
|
---|
| 107 | #endregion
|
---|
| 108 |
|
---|
[7156] | 109 | private void PauseTaskAsync() {
|
---|
[8206] | 110 | progress.Status = "Pausing task. Please be patient for the command to take effect.";
|
---|
| 111 | progress.ProgressState = ProgressState.Started;
|
---|
[7156] | 112 | Content.Pause();
|
---|
[8206] | 113 | progress.Finish();
|
---|
[7156] | 114 | }
|
---|
| 115 |
|
---|
| 116 | private void StopTaskAsync() {
|
---|
[8206] | 117 | progress.Status = "Stopping task. Please be patient for the command to take effect.";
|
---|
| 118 | progress.ProgressState = ProgressState.Started;
|
---|
[7156] | 119 | Content.Stop();
|
---|
[8206] | 120 | progress.Finish();
|
---|
[7156] | 121 | }
|
---|
| 122 |
|
---|
| 123 | private void ResumeTaskAsync() {
|
---|
[8206] | 124 | progress.Status = "Resuming task. Please be patient for the command to take effect.";
|
---|
| 125 | progress.ProgressState = ProgressState.Started;
|
---|
[7156] | 126 | Content.Restart();
|
---|
[8206] | 127 | progress.Finish();
|
---|
[7156] | 128 | }
|
---|
| 129 |
|
---|
[6976] | 130 | protected override void SetEnabledStateOfControls() {
|
---|
| 131 | base.SetEnabledStateOfControls();
|
---|
| 132 |
|
---|
| 133 | this.restartButton.Enabled = Content != null && Content.IsControllable && !Content.Task.Command.HasValue && (Content.Task.State == TaskState.Paused || Content.Task.State == TaskState.Failed || Content.Task.State == TaskState.Aborted);
|
---|
| 134 | this.pauseButton.Enabled = Content != null && Content.IsControllable && !Content.Task.Command.HasValue && Content.Task.State == TaskState.Calculating;
|
---|
| 135 | this.stopButton.Enabled = Content != null && Content.IsControllable && !Content.Task.Command.HasValue && (Content.Task.State == TaskState.Calculating || Content.Task.State == TaskState.Waiting || Content.Task.State == TaskState.Paused);
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | }
|
---|