Changeset 7156
- Timestamp:
- 12/08/11 18:53:41 (13 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r7068 r7156 32 32 using HeuristicLab.Optimization; 33 33 using HeuristicLab.PluginInfrastructure; 34 using System.Threading.Tasks; 34 35 35 36 namespace HeuristicLab.Clients.Hive.JobManager.Views { … … 316 317 SetEnabledStateOfControls(); 317 318 } 318 } 319 319 } 320 320 321 321 private void UpdateStateLogList() { … … 336 336 if (nameTextBox.Text.Trim() == string.Empty) { 337 337 MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 338 } else if (Content.ExecutionState == ExecutionState.Paused) { 339 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content); 340 task.ContinueWith((t) => { 341 FinishProgressView(); 342 MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 343 Content.Log.LogException(t.Exception); 344 }, TaskContinuationOptions.OnlyOnFaulted); 338 345 } else { 339 346 HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken()); 340 347 } 341 348 } 349 342 350 private void pauseButton_Click(object sender, EventArgs e) { 343 HiveClient.PauseJob(Content); 344 } 351 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content); 352 task.ContinueWith((t) => { 353 FinishProgressView(); 354 MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 355 Content.Log.LogException(t.Exception); 356 }, TaskContinuationOptions.OnlyOnFaulted); 357 } 358 345 359 private void stopButton_Click(object sender, EventArgs e) { 346 HiveClient.StopJob(Content); 360 var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content); 361 task.ContinueWith((t) => { 362 FinishProgressView(); 363 MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 364 Content.Log.LogException(t.Exception); 365 }, TaskContinuationOptions.OnlyOnFaulted); 347 366 } 348 367 private void resetButton_Click(object sender, EventArgs e) { } 368 369 private void PauseJobAsync(object job) { 370 IProgress prog = new Progress(); 371 prog.Status = "Pausing job..."; 372 SetProgressView(prog); 373 HiveClient.PauseJob((RefreshableJob)job); 374 FinishProgressView(); 375 } 376 377 private void StopJobAsync(object job) { 378 IProgress prog = new Progress(); 379 prog.Status = "Stopping job..."; 380 SetProgressView(prog); 381 HiveClient.StopJob((RefreshableJob)job); 382 FinishProgressView(); 383 } 384 385 private void ResumeJobAsync(object job) { 386 IProgress prog = new Progress(); 387 prog.Status = "Resuming job..."; 388 SetProgressView(prog); 389 HiveClient.ResumeJob((RefreshableJob)job); 390 FinishProgressView(); 391 } 349 392 350 393 private void nameTextBox_Validated(object sender, EventArgs e) { … … 385 428 } 386 429 } 387 388 389 430 #endregion 390 431 … … 394 435 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false; 395 436 } else { 396 startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && Content.ExecutionState == ExecutionState.Prepared;437 startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused); 397 438 pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started; 398 439 stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started; … … 416 457 417 458 private void SetProgressView() { 418 if (progressView == null) { 419 progressView = new ProgressView(this, Content.Progress); 420 } 421 progressView.Progress = Content.Progress; 459 if (InvokeRequired) { 460 Invoke(new Action(SetProgressView)); 461 } else { 462 if (progressView == null) { 463 progressView = new ProgressView(this, Content.Progress); 464 } else { 465 progressView.Progress = Content.Progress; 466 } 467 } 468 } 469 470 private void SetProgressView(IProgress progress) { 471 if (InvokeRequired) { 472 Invoke(new Action<IProgress>(SetProgressView), progress); 473 } else { 474 if (progressView == null) { 475 progressView = new ProgressView(this, progress); 476 } else { 477 progressView.Progress = progress; 478 } 479 } 422 480 } 423 481 424 482 private void FinishProgressView() { 425 if (progressView != null) { 426 progressView.Finish(); 427 progressView = null; 428 SetEnabledStateOfControls(); 483 if (InvokeRequired) { 484 Invoke(new Action(FinishProgressView)); 485 } else { 486 if (progressView != null) { 487 progressView.Finish(); 488 progressView = null; 489 SetEnabledStateOfControls(); 490 } 429 491 } 430 492 } -
trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs
r6976 r7156 23 23 using System.Windows.Forms; 24 24 using HeuristicLab.MainForm; 25 using System.Threading.Tasks; 26 using HeuristicLab.PluginInfrastructure; 25 27 26 28 namespace HeuristicLab.Clients.Hive.Views { … … 28 30 [Content(typeof(OptimizerHiveTask), true)] 29 31 public partial class OptimizerHiveTaskView : HiveTaskView { 32 private ProgressView progressView; 33 30 34 public new OptimizerHiveTask Content { 31 35 get { return (OptimizerHiveTask)base.Content; } … … 67 71 #region Child Control Events 68 72 private void restartButton_Click(object sender, EventArgs e) { 69 Content.Restart(); 73 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync); 74 task.ContinueWith((t) => { 75 FinishProgressView(); 76 ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception); 77 }, TaskContinuationOptions.OnlyOnFaulted); 70 78 } 71 79 72 80 private void pauseButton_Click(object sender, EventArgs e) { 73 Content.Pause(); 81 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync); 82 task.ContinueWith((t) => { 83 FinishProgressView(); 84 ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception); 85 }, TaskContinuationOptions.OnlyOnFaulted); 74 86 } 75 87 76 88 private void stopButton_Click(object sender, EventArgs e) { 77 Content.Stop(); 89 var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync); 90 task.ContinueWith((t) => { 91 FinishProgressView(); 92 ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception); 93 }, TaskContinuationOptions.OnlyOnFaulted); 78 94 } 79 95 #endregion 96 97 private void PauseTaskAsync() { 98 IProgress prog = new Progress(); 99 prog.Status = "Pausing task. Please be patient for the command to take effect."; 100 SetProgressView(prog); 101 Content.Pause(); 102 FinishProgressView(); 103 } 104 105 private void StopTaskAsync() { 106 IProgress prog = new Progress(); 107 prog.Status = "Stopping task. Please be patient for the command to take effect."; 108 SetProgressView(prog); 109 Content.Stop(); 110 FinishProgressView(); 111 } 112 113 private void ResumeTaskAsync() { 114 IProgress prog = new Progress(); 115 prog.Status = "Resuming task. Please be patient for the command to take effect."; 116 SetProgressView(prog); 117 Content.Restart(); 118 FinishProgressView(); 119 } 120 121 private void SetProgressView(IProgress progress) { 122 if (InvokeRequired) { 123 Invoke(new Action<IProgress>(SetProgressView), progress); 124 } else { 125 if (progressView == null) { 126 progressView = new ProgressView(this, progress); 127 } else { 128 progressView.Progress = progress; 129 } 130 } 131 } 132 133 private void FinishProgressView() { 134 if (InvokeRequired) { 135 Invoke(new Action(FinishProgressView)); 136 } else { 137 if (progressView != null) { 138 progressView.Finish(); 139 progressView = null; 140 SetEnabledStateOfControls(); 141 } 142 } 143 } 80 144 81 145 protected override void SetEnabledStateOfControls() { -
trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r7144 r7156 236 236 } 237 237 }); 238 // execution state does not need to be set. it will be set to Stopped, when all jobs have been downloaded 238 refreshableJob.ExecutionState = ExecutionState.Stopped; 239 } 240 241 public static void ResumeJob(RefreshableJob refreshableJob) { 242 HiveServiceLocator.Instance.CallHiveService(service => { 243 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 244 if (task.Task.State == TaskState.Paused) { 245 service.RestartTask(task.Task.Id); 246 } 247 } 248 }); 249 refreshableJob.ExecutionState = ExecutionState.Started; 239 250 } 240 251
Note: See TracChangeset
for help on using the changeset viewer.