Changeset 8165
- Timestamp:
- 06/29/12 23:12:32 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientView.cs
r8160 r8165 35 35 36 36 private ProgressView progressView; 37 IProgress progress;37 private Progress progress; 38 38 39 39 public ClientView() { 40 40 InitializeComponent(); 41 progressView = new ProgressView(this); 41 progress = new Progress() { 42 CanBeCanceled = false, 43 ProgressState = ProgressState.Finished 44 }; 45 } 46 47 protected override void DeregisterContentEvents() { 48 if (progressView != null) { 49 progressView.Content = null; 50 progressView.Dispose(); 51 progressView = null; 52 } 53 base.DeregisterContentEvents(); 54 } 55 56 protected override void RegisterContentEvents() { 57 base.RegisterContentEvents(); 58 progressView = new ProgressView(this, progress); 42 59 } 43 60 … … 84 101 Invoke(new Action(StartProgressView)); 85 102 } else { 86 progress = new Progress();87 103 progress.Status = "Downloading client information. Please be patient."; 88 progress View.Progress = progress;104 progress.ProgressState = ProgressState.Started; 89 105 } 90 106 } -
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs
r8160 r8165 42 42 private ISet<TreeNode> filteredTreeNodes; 43 43 private ISet<TreeNode> nodeStore; 44 private IProgress currentProgress; 44 private Progress progress; 45 private ProgressView progressView; 45 46 46 47 private ISet<Resource> selectedResources; … … 48 49 get { return selectedResources; } 49 50 set { selectedResources = value; } 50 }51 52 private ProgressView progressView;53 public ProgressView ProgressView {54 get { return progressView; }55 set { progressView = value; }56 51 } 57 52 … … 69 64 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.MonitorLarge); 70 65 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NetworkCenterLarge); 66 progress = new Progress() { 67 CanBeCanceled = false, 68 ProgressState = ProgressState.Finished 69 }; 70 } 71 72 protected override void DeregisterContentEvents() { 73 if (progressView != null) { 74 progressView.Content = null; 75 progressView.Dispose(); 76 progressView = null; 77 } 78 base.DeregisterContentEvents(); 79 } 80 81 protected override void RegisterContentEvents() { 82 base.RegisterContentEvents(); 83 progressView = new ProgressView(this, progress); 71 84 } 72 85 … … 75 88 Invoke(new Action(StartProgressView)); 76 89 } else { 77 currentProgress = new Progress(); 78 currentProgress.Status = "Downloading resources. Please be patient."; 79 if (progressView == null) { 80 progressView = new ProgressView(this); 81 } 82 progressView.Progress = currentProgress; 90 progress.Status = "Downloading resources. Please be patient."; 91 progress.ProgressState = ProgressState.Started; 83 92 } 84 93 } … … 88 97 Invoke(new Action(FinishProgressView)); 89 98 } else { 90 currentProgress.Finish();99 progress.Finish(); 91 100 } 92 101 } -
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelectorDialog.Designer.cs
r7967 r8165 73 73 this.hiveResourceSelector.Location = new System.Drawing.Point(12, 12); 74 74 this.hiveResourceSelector.Name = "hiveResourceSelector"; 75 this.hiveResourceSelector.ProgressView = null;76 75 this.hiveResourceSelector.ReadOnly = false; 77 76 this.hiveResourceSelector.Size = new System.Drawing.Size(549, 591); -
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r8160 r8165 42 42 [Content(typeof(RefreshableJob), true)] 43 43 public partial class RefreshableHiveJobView : HeuristicLab.Core.Views.ItemView { 44 private Progress progress; 44 45 private ProgressView progressView; 45 46 private HiveResourceSelectorDialog hiveResourceSelectorDialog; … … 55 56 public RefreshableHiveJobView() { 56 57 InitializeComponent(); 57 progressView = new ProgressView(this); 58 progress = new Progress() { 59 CanBeCanceled = true, 60 ProgressState = ProgressState.Finished 61 }; 58 62 } 59 63 … … 73 77 Content.Loaded += new EventHandler(Content_Loaded); 74 78 Content.TaskReceived += new EventHandler(Content_TaskReceived); 79 progressView = new ProgressView(this, progress); 75 80 } 76 81 … … 88 93 Content.Loaded -= new EventHandler(Content_Loaded); 89 94 Content.TaskReceived -= new EventHandler(Content_TaskReceived); 95 if (progressView != null) { 96 progressView.Content = null; 97 progressView.Dispose(); 98 progressView = null; 99 } 90 100 base.DeregisterContentEvents(); 91 101 } … … 356 366 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content); 357 367 task.ContinueWith((t) => { 358 FinishProgressView();368 progress.Finish(); 359 369 MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 360 370 Content.Log.LogException(t.Exception); … … 368 378 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content); 369 379 task.ContinueWith((t) => { 370 FinishProgressView();380 progress.Finish(); 371 381 MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 372 382 Content.Log.LogException(t.Exception); … … 377 387 var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content); 378 388 task.ContinueWith((t) => { 379 FinishProgressView();389 progress.Finish(); 380 390 MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 381 391 Content.Log.LogException(t.Exception); … … 385 395 386 396 private void PauseJobAsync(object job) { 387 IProgress prog = new Progress(); 388 prog.Status = "Pausing job..."; 389 SetProgressView(prog); 397 progress.Status = "Pausing job..."; 398 progress.ProgressState = ProgressState.Started; 390 399 HiveClient.PauseJob((RefreshableJob)job); 391 FinishProgressView();392 400 } 393 401 394 402 private void StopJobAsync(object job) { 395 IProgress prog = new Progress(); 396 prog.Status = "Stopping job..."; 397 SetProgressView(prog); 403 progress.Status = "Stopping job..."; 404 progress.ProgressState = ProgressState.Started; 398 405 HiveClient.StopJob((RefreshableJob)job); 399 FinishProgressView();400 406 } 401 407 402 408 private void ResumeJobAsync(object job) { 403 IProgress prog = new Progress(); 404 prog.Status = "Resuming job..."; 405 SetProgressView(prog); 409 progress.Status = "Resuming job..."; 410 progress.ProgressState = ProgressState.Started; 406 411 HiveClient.ResumeJob((RefreshableJob)job); 407 FinishProgressView();408 412 } 409 413 … … 466 470 } else { 467 471 if (Content != null && Content.Progress != null && Content.IsProgressing) { 468 SetProgressView();472 progressView.Content = Content.Progress; 469 473 } else { 470 progressView.Progress = null; 471 } 472 } 473 } 474 475 private void SetProgressView() { 476 if (InvokeRequired) { 477 Invoke(new Action(SetProgressView)); 478 } else { 479 progressView.Progress = Content.Progress; 480 } 481 } 482 483 private void SetProgressView(IProgress progress) { 484 if (InvokeRequired) { 485 Invoke(new Action<IProgress>(SetProgressView), progress); 486 } else { 487 progressView.Progress = progress; 488 } 489 } 490 491 private void FinishProgressView() { 492 if (InvokeRequired) { 493 Invoke(new Action(FinishProgressView)); 494 } else { 495 if (Content != null && Content.Progress != null) 496 Content.Progress.Finish(); 474 progressView.Content = progress; 475 } 497 476 } 498 477 } -
trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs
r8160 r8165 31 31 [Content(typeof(OptimizerHiveTask), true)] 32 32 public partial class OptimizerHiveTaskView : HiveTaskView { 33 private ProgressView progressView; 34 private IProgress progress; 33 private Progress progress; 35 34 36 35 public new OptimizerHiveTask Content { … … 45 44 public OptimizerHiveTaskView() { 46 45 InitializeComponent(); 47 progressView = new ProgressView(this); 46 progress = new Progress() { 47 CanBeCanceled = false 48 }; 48 49 } 49 50 … … 76 77 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync); 77 78 task.ContinueWith((t) => { 78 FinishProgressView();79 progress.Finish(); 79 80 ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception); 80 81 }, TaskContinuationOptions.OnlyOnFaulted); … … 84 85 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync); 85 86 task.ContinueWith((t) => { 86 FinishProgressView();87 progress.Finish(); 87 88 ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception); 88 89 }, TaskContinuationOptions.OnlyOnFaulted); … … 92 93 var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync); 93 94 task.ContinueWith((t) => { 94 FinishProgressView();95 progress.Finish(); 95 96 ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception); 96 97 }, TaskContinuationOptions.OnlyOnFaulted); … … 99 100 100 101 private void PauseTaskAsync() { 101 progress = new Progress();102 102 progress.Status = "Pausing task. Please be patient for the command to take effect."; 103 SetProgressView(progress); 104 Content.Pause(); 105 FinishProgressView(); 103 progress.ProgressState = ProgressState.Started; 104 using (var view = new ProgressView(this, progress)) { 105 Content.Pause(); 106 } 106 107 } 107 108 108 109 private void StopTaskAsync() { 109 progress = new Progress();110 110 progress.Status = "Stopping task. Please be patient for the command to take effect."; 111 SetProgressView(progress); 112 Content.Stop(); 113 FinishProgressView(); 111 progress.ProgressState = ProgressState.Started; 112 using (var view = new ProgressView(this, progress)) { 113 Content.Stop(); 114 } 114 115 } 115 116 116 117 private void ResumeTaskAsync() { 117 progress = new Progress();118 118 progress.Status = "Resuming task. Please be patient for the command to take effect."; 119 SetProgressView(progress); 120 Content.Restart(); 121 FinishProgressView(); 122 } 123 124 private void SetProgressView(IProgress progress) { 125 if (InvokeRequired) { 126 Invoke(new Action<IProgress>(SetProgressView), progress); 127 } else { 128 progressView.Progress = progress; 129 } 130 } 131 132 private void FinishProgressView() { 133 if (InvokeRequired) { 134 Invoke(new Action(FinishProgressView)); 135 } else { 136 progress.Finish(); 119 progress.ProgressState = ProgressState.Started; 120 using (var view = new ProgressView(this, progress)) { 121 Content.Restart(); 137 122 } 138 123 } -
trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r8159 r8165 351 351 /// </summary> 352 352 /// <param name="parentHiveTask">shall be null if its the root task</param> 353 private void UploadTaskWithChildren( IProgress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, bool isPrivileged, CancellationToken cancellationToken) {353 private void UploadTaskWithChildren(Progress progress, HiveTask hiveTask, HiveTask parentHiveTask, IEnumerable<Guid> groups, int[] taskCount, int totalJobCount, Guid configPluginId, Guid jobId, ILog log, bool isPrivileged, CancellationToken cancellationToken) { 354 354 taskUploadSemaphore.WaitOne(); 355 355 bool semaphoreReleased = false; -
trunk/sources/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs
r8156 r8165 167 167 } 168 168 169 private IProgress progress;170 public IProgress Progress {169 private Progress progress; 170 public Progress Progress { 171 171 get { return progress; } 172 172 set { -
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs
r8160 r8165 39 39 public new IOptimizer Content { 40 40 get { return (IOptimizer)base.Content; } 41 set { 42 base.Content = value; 43 } 41 set { base.Content = value; } 44 42 } 45 43 … … 56 54 Algorithm selectedAlgorithm = null; 57 55 Problem selectedProblem = null; 58 private ProgressView progressView; 59 private IProgress progress;56 private ProgressView progressView; // this has to be disposed manually! 57 private Progress progress; 60 58 61 59 public OKBExperimentUploadView() { 62 60 InitializeComponent(); 63 progressView = new ProgressView(this); 61 progress = new Progress() { 62 CanBeCanceled = false, 63 ProgressState = ProgressState.Finished 64 }; 64 65 } 65 66 … … 95 96 RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing); 96 97 RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed); 98 progressView = new ProgressView(this, progress); 97 99 } 98 100 … … 100 102 RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing); 101 103 RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed); 104 if (progressView != null) { 105 progressView.Content = null; 106 progressView.Dispose(); 107 progressView = null; 108 } 102 109 base.DeregisterContentEvents(); 103 110 } … … 191 198 Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e); 192 199 } else { 193 progress = new Progress();194 200 progress.Status = "Refreshing algorithms and problems..."; 195 SetProgressView(progress);201 progress.ProgressState = ProgressState.Started; 196 202 } 197 203 } … … 201 207 Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e); 202 208 } else { 203 FinishProgressView();209 progress.Finish(); 204 210 SetEnabledStateOfControls(); 205 211 } … … 209 215 var task = System.Threading.Tasks.Task.Factory.StartNew(UploadAsync); 210 216 task.ContinueWith((t) => { 211 FinishProgressView();217 progress.Finish(); 212 218 PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", t.Exception); 213 219 }, TaskContinuationOptions.OnlyOnFaulted); … … 215 221 216 222 private void UploadAsync() { 217 progress = new Progress();218 223 progress.Status = "Uploading runs to OKB..."; 219 224 progress.ProgressValue = 0; … … 221 226 int i = 0; 222 227 223 SetProgressView(progress);224 foreach (DataGridViewRow row in dataGridView.Rows) {225 selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault();226 selectedProblem = problems.Where(x => x.Name == row.Cells[problemColumnIndex].Value.ToString()).FirstOrDefault();227 if (selectedAlgorithm == null || selectedProblem == null) {228 throw new ArgumentException("Can't retrieve the algorithm/problem to upload");229 }230 231 OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id);232 run.Store();233 i++;234 progress.ProgressValue = ((double)i) / count;235 }236 FinishProgressView();228 using (var view = new ProgressView(this, progress)) { 229 foreach (DataGridViewRow row in dataGridView.Rows) { 230 selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault(); 231 selectedProblem = problems.Where(x => x.Name == row.Cells[problemColumnIndex].Value.ToString()).FirstOrDefault(); 232 if (selectedAlgorithm == null || selectedProblem == null) { 233 throw new ArgumentException("Can't retrieve the algorithm/problem to upload"); 234 } 235 236 OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id); 237 run.Store(); 238 i++; 239 progress.ProgressValue = ((double)i) / count; 240 } 241 } 237 242 ClearRuns(); 238 }239 240 private void SetProgressView(IProgress progress) {241 if (InvokeRequired) {242 Invoke(new Action<IProgress>(SetProgressView), progress);243 } else {244 progressView.Progress = progress;245 }246 }247 248 private void FinishProgressView() {249 if (InvokeRequired) {250 Invoke(new Action(FinishProgressView));251 } else {252 progress.Finish();253 }254 243 } 255 244 -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Views/ProgressView.cs
r8159 r8165 21 21 22 22 using System; 23 using System.ComponentModel; 23 24 using System.Windows.Forms; 24 25 25 26 namespace HeuristicLab.MainForm.WindowsForms { 26 public partial class ProgressView : HeuristicLab.MainForm.WindowsForms.View { 27 [View("ProgressView")] 28 [Content(typeof(IProgress), true)] 29 public partial class ProgressView : AsynchronousContentView { 30 private const int DefaultCancelTimeoutMs = 3000; 27 31 private ContentView parentView; 28 32 29 private IProgress progress; 30 public IProgress Progress { 31 get { return progress; } 32 set { 33 if (progress == value) return; 34 Finish(); 35 progress = value; 36 RegisterProgressEvents(); 37 ShowProgress(); 38 OnProgressChanged(); 39 } 40 } 41 42 private bool cancelEnabled; 43 public bool CancelEnabled { 44 get { return cancelEnabled; } 45 set { 46 cancelEnabled = value; 47 SetCancelButtonVisibility(); 48 } 33 [Category("Custom"), Description("The time that the process is allowed to exit.")] 34 [DefaultValue(DefaultCancelTimeoutMs)] 35 public int CancelTimeoutMs { get; set; } 36 private bool ShouldSerializeCancelTimeoutMs() { return CancelTimeoutMs != DefaultCancelTimeoutMs; } 37 38 public new IProgress Content { 39 get { return (IProgress)base.Content; } 40 set { base.Content = value; } 41 } 42 43 public ProgressView() { 44 InitializeComponent(); 45 } 46 public ProgressView(IProgress progress) 47 : this() { 48 Content = progress; 49 } 50 public ProgressView(ContentView parentView) 51 : this() { 52 if (parentView == null) throw new ArgumentNullException("parentView", "The parent view is null."); 53 this.parentView = parentView; 54 } 55 public ProgressView(ContentView parentView, IProgress progress) 56 : this(parentView) { 57 Content = progress; 58 } 59 60 protected override void RegisterContentEvents() { 61 Content.StatusChanged += new EventHandler(progress_StatusChanged); 62 Content.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged); 63 Content.ProgressStateChanged += new EventHandler(Content_ProgressStateChanged); 64 Content.CanBeCanceledChanged += new EventHandler(Content_CanBeCanceledChanged); 65 base.RegisterContentEvents(); 66 } 67 68 protected override void DeregisterContentEvents() { 69 base.DeregisterContentEvents(); 70 Content.StatusChanged -= new EventHandler(progress_StatusChanged); 71 Content.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged); 72 Content.ProgressStateChanged -= new EventHandler(Content_ProgressStateChanged); 73 Content.CanBeCanceledChanged -= new EventHandler(Content_CanBeCanceledChanged); 74 } 75 76 protected override void OnContentChanged() { 77 base.OnContentChanged(); 78 if (Content == null) { 79 HideProgress(); 80 } else { 81 if (Content.ProgressState == ProgressState.Started) 82 ShowProgress(); 83 } 84 } 85 86 protected override void SetEnabledStateOfControls() { 87 base.SetEnabledStateOfControls(); 88 cancelButton.Visible = Content != null && Content.CanBeCanceled; 89 cancelButton.Enabled = Content != null && Content.CanBeCanceled && !ReadOnly; 49 90 } 50 91 51 92 private void ShowProgress() { 52 if (progress != null) { 53 this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2); 54 this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2); 55 this.Anchor = AnchorStyles.Left | AnchorStyles.Top; 56 57 LockBackground(); 58 59 if (!parentView.Controls.Contains(this)) { 60 parentView.Controls.Add(this); 61 } 62 63 BringToFront(); 93 if (InvokeRequired) Invoke((Action)ShowProgress); 94 else { 95 if (parentView != null) { 96 this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2); 97 this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2); 98 this.Anchor = AnchorStyles.None; 99 100 LockBackground(); 101 102 if (!parentView.Controls.Contains(this)) 103 parentView.Controls.Add(this); 104 105 BringToFront(); 106 } 107 UpdateProgressValue(); 108 UpdateProgressStatus(); 64 109 Visible = true; 65 110 } 66 111 } 67 112 68 public ProgressView(ContentView parentView) { 69 InitializeComponent(); 70 CancelEnabled = false; 71 72 if (parentView != null) { 73 this.parentView = parentView; 74 } else { 75 throw new ArgumentNullException("The parent view is null."); 76 } 77 } 78 79 private void RegisterProgressEvents() { 80 if (progress == null) return; 81 progress.Finished += new EventHandler(progress_Finished); 82 progress.StatusChanged += new EventHandler(progress_StatusChanged); 83 progress.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged); 84 progress.Canceled += new EventHandler(progress_Canceled); 85 } 86 87 private void DeregisterProgressEvents() { 88 if (progress == null) return; 89 progress.Finished -= new EventHandler(progress_Finished); 90 progress.StatusChanged -= new EventHandler(progress_StatusChanged); 91 progress.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged); 92 progress.Canceled -= new EventHandler(progress_Canceled); 93 } 94 95 private void progress_Finished(object sender, EventArgs e) { 96 Finish(); 113 private void HideProgress() { 114 if (InvokeRequired) Invoke((Action)HideProgress); 115 else { 116 if (parentView != null) { 117 if (parentView.Controls.Contains(this)) 118 parentView.Controls.Remove(this); 119 120 UnlockBackground(); 121 } 122 Visible = false; 123 } 97 124 } 98 125 … … 105 132 } 106 133 107 void progress_Canceled(object sender, EventArgs e) { 108 Finish(); 134 private void Content_ProgressStateChanged(object sender, EventArgs e) { 135 if (Content.ProgressState == ProgressState.Finished 136 || Content.ProgressState == ProgressState.Canceled) 137 HideProgress(); 138 if (Content.ProgressState == ProgressState.Started) 139 ShowProgress(); 140 } 141 142 private void Content_CanBeCanceledChanged(object sender, EventArgs e) { 143 SetEnabledStateOfControls(); 109 144 } 110 145 … … 115 150 parentView.Locked = true; 116 151 parentView.ReadOnly = true; 117 Enabled = true;152 Locked = false; 118 153 ReadOnly = false; 154 } 155 } 156 157 private void UnlockBackground() { 158 if (InvokeRequired) Invoke((Action)UnlockBackground); 159 else { 160 parentView.Locked = false; 161 parentView.ReadOnly = false; 162 Locked = true; 163 ReadOnly = true; 119 164 } 120 165 } … … 123 168 if (InvokeRequired) Invoke((Action)UpdateProgressValue); 124 169 else { 125 if ( progress!= null) {126 double progressValue = progress.ProgressValue;127 if (progressValue < progressBar.Minimum || progressValue > progressBar.Maximum) {128 progressBar.Style = ProgressBarStyle.Marquee;129 progressBar.Value = progressBar.Minimum;170 if (Content != null) { 171 double progressValue = Content.ProgressValue; 172 if (progressValue <= 0.0 || progressValue > 1.0) { 173 if (progressBar.Style != ProgressBarStyle.Marquee) 174 progressBar.Style = ProgressBarStyle.Marquee; 130 175 } else { 131 progressBar.Style = ProgressBarStyle.Blocks; 176 if (progressBar.Style != ProgressBarStyle.Blocks) 177 progressBar.Style = ProgressBarStyle.Blocks; 132 178 progressBar.Value = (int)Math.Round(progressBar.Minimum + progressValue * (progressBar.Maximum - progressBar.Minimum)); 133 179 } … … 138 184 private void UpdateProgressStatus() { 139 185 if (InvokeRequired) Invoke((Action)UpdateProgressStatus); 140 else { 141 if (progress != null) { 142 string status = progress.Status; 143 statusLabel.Text = progress.Status; 144 } 145 } 146 } 147 148 private void Finish() { 149 if (InvokeRequired) { 150 Invoke(new Action(Finish)); 151 } else { 152 progressBar.Value = progressBar.Maximum; 153 parentView.Controls.Remove(this); 154 parentView.Locked = false; 155 parentView.ReadOnly = false; 156 DeregisterProgressEvents(); 157 progress = null; 158 Visible = false; 159 } 186 else if (Content != null) 187 statusLabel.Text = Content.Status; 160 188 } 161 189 162 190 private void cancelButton_Click(object sender, EventArgs e) { 163 if (progress != null) { 164 progress.CancelRequested = true; 165 cancelButton.Enabled = false; 166 } 167 } 168 169 private void SetCancelButtonVisibility() { 170 if (InvokeRequired) { 171 Invoke((Action)SetCancelButtonVisibility); 172 } else { 173 cancelButton.Visible = cancelEnabled; 174 } 175 } 176 177 private void OnProgressChanged() { 178 UpdateProgressStatus(); 179 UpdateProgressValue(); 191 if (Content != null) { 192 try { 193 Content.Cancel(CancelTimeoutMs); 194 ReadOnly = true; 195 cancelButtonTimer.Interval = CancelTimeoutMs; 196 cancelButtonTimer.Start(); 197 } catch (NotSupportedException nse) { 198 PluginInfrastructure.ErrorHandling.ShowErrorDialog(nse); 199 } 200 } 201 } 202 203 private void cancelButtonTimer_Tick(object sender, EventArgs e) { 204 cancelButtonTimer.Stop(); 205 if (Visible) ReadOnly = false; 180 206 } 181 207 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Views/ProgressView.designer.cs
r8111 r8165 1 1 2 2 namespace HeuristicLab.MainForm.WindowsForms { 3 partial class ProgressView : View{3 partial class ProgressView { 4 4 /// <summary> 5 5 /// Required designer variable. … … 25 25 /// </summary> 26 26 private void InitializeComponent() { 27 this.components = new System.ComponentModel.Container(); 27 28 this.progressBar = new System.Windows.Forms.ProgressBar(); 28 29 this.statusLabel = new System.Windows.Forms.Label(); 29 30 this.cancelButton = new System.Windows.Forms.Button(); 30 31 this.panel = new System.Windows.Forms.Panel(); 32 this.cancelButtonTimer = new System.Windows.Forms.Timer(this.components); 31 33 this.panel.SuspendLayout(); 32 34 this.SuspendLayout(); … … 75 77 this.panel.TabIndex = 3; 76 78 // 79 // cancelButtonTimer 80 // 81 this.cancelButtonTimer.Tick += new System.EventHandler(this.cancelButtonTimer_Tick); 82 // 77 83 // ProgressView 78 84 // 79 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);80 85 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 81 86 this.Controls.Add(this.panel); … … 93 98 private System.Windows.Forms.Button cancelButton; 94 99 private System.Windows.Forms.Panel panel; 100 private System.Windows.Forms.Timer cancelButtonTimer; 95 101 } 96 102 } -
trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r8156 r8165 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 24 25 namespace HeuristicLab.MainForm { 25 public interface IProgress { 26 string Status { get; set; } 27 double ProgressValue { get; set; } 26 public enum ProgressState { Started = 1, Canceled = 2, Finished = 3 }; 28 27 29 void Finish(); 30 void SignalSuccessfulCancelation(); 28 public interface IProgress : IContent { 29 /// <summary> 30 /// Gets the currently associated status text with the progress. 31 /// </summary> 32 string Status { get; } 33 /// <summary> 34 /// Gets the currently associated progress value in the range (0;1]. 35 /// Values outside this range are permitted and need to be handled in some feasible manner. 36 /// </summary> 37 double ProgressValue { get; } 38 /// <summary> 39 /// Gets the current state of the progress. Every progress starts in state 40 /// Started and then becomes either Canceled or Finished. 41 /// If it is reused it may be Started again. 42 /// </summary> 43 ProgressState ProgressState { get; } 44 /// <summary> 45 /// Returns whether the operation can be canceled or not. 46 /// This can change during the course of the progress. 47 /// </summary> 48 bool CanBeCanceled { get; } 31 49 32 bool CancelRequested { get; set; } 50 /// <summary> 51 /// Requests the operation behind the process to cancel. 52 /// Check the !ProgressState property when the cancellation succeeded. 53 /// The corresponding event will also notify of a success. 54 /// </summary> 55 /// <exception cref="NotSupportedException">Thrown when cancellation is not supported.</exception> 56 /// <param name="timeoutMs">The operation is given a certain timeout to cancel. If the operation doesn't cancel in this time it will be forcibly closed.</param> 57 void Cancel(int timeoutMs); 33 58 34 event EventHandler Finished; 59 /// <summary> 60 /// The status text changed. 61 /// </summary> 35 62 event EventHandler StatusChanged; 63 /// <summary> 64 /// The value of the progress changed. This is the (0;1] progress value from starting to finish. Values outside this range are permitted and need to be handled in some feasible manner. 65 /// </summary> 36 66 event EventHandler ProgressValueChanged; 37 event EventHandler Canceled; 67 /// <summary> 68 /// The state of the progress changed. The handler is supposed to query the ProgressState property. 69 /// </summary> 70 event EventHandler ProgressStateChanged; 71 /// <summary> 72 /// The progress' ability to cancel changed. 73 /// </summary> 74 event EventHandler CanBeCanceledChanged; 75 /// <summary> 76 /// A cancelation is requested with a certain timeout (in ms) in which it should occur gracefully. If the timeout is surpassed, it should be forcibly canceled. 77 /// </summary> 78 event EventHandler<EventArgs<int>> CancelRequested; 38 79 } 39 80 } -
trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs
r8145 r8165 21 21 22 22 using System; 23 using HeuristicLab.Common; 23 24 24 25 namespace HeuristicLab.MainForm { … … 26 27 private string status; 27 28 public string Status { 28 get { 29 return this.status; 30 } 29 get { return status; } 31 30 set { 32 if ( this.status != value) {33 this.status = value;31 if (status != value) { 32 status = value; 34 33 OnStatusChanged(); 35 34 } … … 37 36 } 38 37 39 public bool CancelRequested { get; set; }40 41 38 private double progressValue; 42 39 public double ProgressValue { 43 get { 44 return this.progressValue; 45 } 40 get { return progressValue; } 46 41 set { 47 if ( this.progressValue != value) {48 this.progressValue = value;42 if (progressValue != value) { 43 progressValue = value; 49 44 OnProgressChanged(); 50 45 } … … 52 47 } 53 48 54 public Progress() { } 55 56 public Progress(string status) { 57 this.Status = status; 49 private ProgressState progressState; 50 public ProgressState ProgressState { 51 get { return progressState; } 52 set { 53 if (progressState != value) { 54 progressState = value; 55 OnProgressStateChanged(); 56 } 57 } 58 58 } 59 59 60 public void Finish() { 61 OnFinished(); 60 private bool canBeCanceled; 61 public bool CanBeCanceled { 62 get { return canBeCanceled; } 63 set { 64 if (canBeCanceled != value) { 65 canBeCanceled = value; 66 OnCanBeCanceledChanged(); 67 } 68 } 62 69 } 63 70 64 public void SignalSuccessfulCancelation() { 65 OnCanceled(); 71 public Progress() { 72 progressState = ProgressState.Started; 73 } 74 public Progress(string status) 75 : this() { 76 this.status = status; 77 } 78 public Progress(string status, double progressValue) 79 : this(status) { 80 this.progressValue = progressValue; 81 } 82 83 public void Cancel(int timeoutMs) { 84 if (canBeCanceled) 85 OnCancelRequested(timeoutMs); 86 } 87 88 /// <summary> 89 /// Sets the ProgressValue to 1 and the ProgressState to Finished. 90 /// </summary> 91 public void Finish() { 92 if (ProgressValue != 1.0) ProgressValue = 1.0; 93 ProgressState = ProgressState.Finished; 66 94 } 67 95 68 96 #region Event Handler 69 public event EventHandler Canceled;70 private void OnCanceled() {71 var handler = Canceled;72 try {73 if (handler != null) handler(this, EventArgs.Empty);74 }75 catch (Exception) { }76 }77 78 public event EventHandler Finished;79 private void OnFinished() {80 var handler = Finished;81 try {82 if (handler != null) handler(this, EventArgs.Empty);83 }84 catch (Exception) { }85 }86 87 97 public event EventHandler StatusChanged; 88 98 private void OnStatusChanged() { … … 90 100 try { 91 101 if (handler != null) handler(this, EventArgs.Empty); 92 } 93 catch (Exception) { } 102 } catch { } 94 103 } 95 104 … … 99 108 try { 100 109 if (handler != null) handler(this, EventArgs.Empty); 101 } 102 catch (Exception) { } 110 } catch { } 111 } 112 113 public event EventHandler ProgressStateChanged; 114 private void OnProgressStateChanged() { 115 var handler = ProgressStateChanged; 116 try { 117 if (handler != null) handler(this, EventArgs.Empty); 118 } catch { } 119 } 120 121 public event EventHandler CanBeCanceledChanged; 122 private void OnCanBeCanceledChanged() { 123 var handler = CanBeCanceledChanged; 124 try { 125 if (handler != null) handler(this, EventArgs.Empty); 126 } catch { } 127 } 128 129 public event EventHandler<EventArgs<int>> CancelRequested; 130 private void OnCancelRequested(int timeoutMs) { 131 var handler = CancelRequested; 132 try { 133 if (handler == null) throw new NotSupportedException("Cancel request was ignored."); 134 else handler(this, new EventArgs<int>(timeoutMs)); 135 } catch { } 103 136 } 104 137 #endregion
Note: See TracChangeset
for help on using the changeset viewer.