Changeset 16139 for branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
- Timestamp:
- 09/13/18 13:18:45 (6 years ago)
- Location:
- branches/2931_OR-Tools_LP_MIP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2931_OR-Tools_LP_MIP
- Property svn:mergeinfo changed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.JobManager
- Property svn:mergeinfo changed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r15583 r16139 23 23 using System.ComponentModel; 24 24 using System.Linq; 25 using System.Text;26 25 using System.Threading; 27 26 using System.Threading.Tasks; … … 34 33 using HeuristicLab.Optimization; 35 34 using HeuristicLab.PluginInfrastructure; 35 using System.Collections.Generic; 36 36 37 37 namespace HeuristicLab.Clients.Hive.JobManager.Views { … … 45 45 private bool SuppressEvents { get; set; } 46 46 private object runCollectionViewLocker = new object(); 47 private Project selectedProject; 48 private Dictionary<Guid, Guid> originalJobProjectAssignment = new Dictionary<Guid, Guid>(); 47 49 48 50 public new RefreshableJob Content { 49 51 get { return (RefreshableJob)base.Content; } 50 set { base.Content = value; } 52 set { 53 base.Content = value; 54 } 51 55 } 52 56 … … 117 121 if (Content == null) { 118 122 nameTextBox.Text = string.Empty; 123 descriptionTextBox.Text = string.Empty; 119 124 executionTimeTextBox.Text = string.Empty; 120 resourceNamesTextBox.Text = string.Empty;125 projectNameTextBox.Text = string.Empty; 121 126 refreshAutomaticallyCheckBox.Checked = false; 122 127 lock (runCollectionViewLocker) { … … 128 133 stateLogViewHost.Content = null; 129 134 } else { 135 if(Content.Job != null 136 && Content.Job.Id != Guid.Empty 137 && !originalJobProjectAssignment.ContainsKey(Content.Job.Id)) { 138 originalJobProjectAssignment.Add(Content.Job.Id, Content.Job.ProjectId); 139 } 140 141 if (Content.Job != null && Content.Job.ProjectId == Guid.Empty) { 142 if (HiveClient.Instance != null && HiveClient.Instance.Projects != null && HiveClient.Instance.Projects.Count == 1) { 143 var p = HiveClient.Instance.Projects.FirstOrDefault(); 144 if (p != null && p.Id != Guid.Empty) { 145 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId); 146 Content.Job.ProjectId = p.Id; 147 Content.Job.ResourceIds = HiveClient.Instance.GetAvailableResourcesForProject(p.Id).Select(x => x.Id).ToList(); 148 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 149 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 150 } 151 } 152 } 153 154 130 155 nameTextBox.Text = Content.Job.Name; 156 descriptionTextBox.Text = Content.Job.Description; 131 157 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 132 resourceNamesTextBox.Text = Content.Job.ResourceNames;133 158 refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically; 159 160 // project look up 161 if(Content.Job.ProjectId != null && Content.Job.ProjectId != Guid.Empty) { 162 if(selectedProject == null || selectedProject.Id != Content.Job.ProjectId) { 163 selectedProject = GetProject(Content.Job.ProjectId); 164 if (selectedProject != null) { 165 projectNameTextBox.Text = selectedProject.Name; 166 } else { 167 projectNameTextBox.Text = string.Empty; 168 } 169 } 170 } else { 171 selectedProject = null; 172 projectNameTextBox.Text = string.Empty; 173 Content.Job.ResourceIds = null; 174 } 175 134 176 logView.Content = Content.Log; 135 177 lock (runCollectionViewLocker) { … … 137 179 } 138 180 } 139 } 140 finally { 181 } finally { 141 182 SuppressEvents = false; 142 183 } … … 158 199 tabControl.Enabled = !Locked; 159 200 nameTextBox.Enabled = !Locked; 160 resourceNamesTextBox.Enabled = !Locked; 201 descriptionTextBox.Enabled = !Locked; 202 projectNameTextBox.Enabled = !Locked; 161 203 searchButton.Enabled = !Locked; 162 204 jobsTreeView.Enabled = !Locked; … … 182 224 tabControl.Enabled = !Content.IsProgressing; 183 225 184 this.nameTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded ||Content.IsProgressing;185 this. resourceNamesTextBox.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded ||Content.IsProgressing;186 this.searchButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Prepared && !alreadyUploaded && !Content.IsProgressing;226 this.nameTextBox.ReadOnly = Content.IsProgressing; 227 this.descriptionTextBox.ReadOnly = Content.IsProgressing; 228 this.searchButton.Enabled = !Content.IsProgressing && Content.ExecutionState != ExecutionState.Stopped; 187 229 this.jobsTreeView.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing; 188 230 189 231 this.refreshAutomaticallyCheckBox.Enabled = Content.IsControllable && alreadyUploaded && jobsLoaded && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 190 232 this.refreshButton.Enabled = Content.IsDownloadable && alreadyUploaded && !Content.IsProgressing; 233 this.updateButton.Enabled = Content.ExecutionState != ExecutionState.Prepared && Content.ExecutionState != ExecutionState.Stopped && !Content.IsProgressing; 191 234 192 235 this.UnloadButton.Enabled = Content.HiveTasks != null && Content.HiveTasks.Count > 0 && alreadyUploaded && !Content.IsProgressing; … … 333 376 #region Control events 334 377 private void searchButton_Click(object sender, EventArgs e) { 335 if (hiveResourceSelectorDialog == null) 336 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(); 378 if (hiveResourceSelectorDialog == null) { 379 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId); 380 } else if(hiveResourceSelectorDialog.JobId != Content.Job.Id) { 381 hiveResourceSelectorDialog.JobId = Content.Job.Id; 382 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 383 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 384 385 if (originalJobProjectAssignment.ContainsKey(Content.Job.Id)) { 386 hiveResourceSelectorDialog.ProjectId = originalJobProjectAssignment[Content.Job.Id]; 387 } else { 388 hiveResourceSelectorDialog.ProjectId = Guid.Empty; 389 } 390 } else if(hiveResourceSelectorDialog.JobId == Guid.Empty && Content.Job.Id == Guid.Empty) { 391 hiveResourceSelectorDialog.JobId = Content.Job.Id; 392 hiveResourceSelectorDialog.ProjectId = Guid.Empty; 393 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 394 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 395 } else { 396 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 397 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 398 } 399 337 400 if (hiveResourceSelectorDialog.ShowDialog(this) == DialogResult.OK) { 338 StringBuilder sb = new StringBuilder(); 339 foreach (Resource resource in hiveResourceSelectorDialog.GetSelectedResources()) { 340 sb.Append(resource.Name); 341 sb.Append(";"); 342 } 343 resourceNamesTextBox.Text = sb.ToString(); 344 if (Content.Job.ResourceNames != resourceNamesTextBox.Text) 345 Content.Job.ResourceNames = resourceNamesTextBox.Text; 401 selectedProject = hiveResourceSelectorDialog.SelectedProject; 402 if(selectedProject != null) { 403 projectNameTextBox.Text = selectedProject.Name; 404 Content.Job.ProjectId = selectedProject.Id; 405 Content.Job.ResourceIds = hiveResourceSelectorDialog.SelectedResources.Select(x => x.Id).ToList(); 406 } else { 407 selectedProject = null; 408 projectNameTextBox.Text = string.Empty; 409 Content.Job.ProjectId = Guid.Empty; 410 Content.Job.ResourceIds = null; 411 } 412 SetEnabledStateOfExecutableButtons(); 346 413 } 347 414 } … … 350 417 if (nameTextBox.Text.Trim() == string.Empty) { 351 418 MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 419 } else if (Content.Job.ProjectId == null || Content.Job.ProjectId == Guid.Empty) { 420 MessageBox.Show("Please select a project before uploading the job!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 421 } else if (Content.Job.ResourceIds == null || !Content.Job.ResourceIds.Any()) { 422 MessageBox.Show("Please select resources before uploading the job!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 352 423 } else if (Content.ExecutionState == ExecutionState.Paused) { 353 424 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content); … … 359 430 } else { 360 431 HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken()); 432 UpdateSelectorDialog(); 361 433 } 362 434 } … … 403 475 } 404 476 477 private void descriptionTextBox_Validated(object sender, EventArgs e) { 478 if (!SuppressEvents && Content.Job != null && Content.Job.Description != descriptionTextBox.Text) 479 Content.Job.Description = descriptionTextBox.Text; 480 } 481 405 482 private void resourceNamesTextBox_Validated(object sender, EventArgs e) { 406 if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text)407 Content.Job.ResourceNames = resourceNamesTextBox.Text;483 //if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text) 484 // Content.Job.ResourceNames = resourceNamesTextBox.Text; 408 485 } 409 486 … … 417 494 try { 418 495 invoker.EndInvoke(ar); 419 } 420 catch (Exception ex) { 421 ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); 496 } catch (Exception ex) { 497 ThreadPool.QueueUserWorkItem(delegate (object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); 422 498 } 423 499 }, null); 424 } 425 426 private void refreshPermissionsButton_Click(object sender, EventArgs e) { 427 if (this.Content.Job.Id == Guid.Empty) { 428 MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 429 } else { 430 hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id); 431 } 432 } 433 #endregion 434 435 #region Helpers 436 private void SetEnabledStateOfExecutableButtons() { 437 if (Content == null) { 438 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = false; 439 } else { 440 startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 441 pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing; 442 stopButton.Enabled = Content.IsControllable && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 443 } 444 } 445 #endregion 446 447 #region Drag & Drop 448 private void jobsTreeView_DragOver(object sender, DragEventArgs e) { 449 jobsTreeView_DragEnter(sender, e); 450 } 451 452 private void jobsTreeView_DragEnter(object sender, DragEventArgs e) { 453 e.Effect = DragDropEffects.None; 454 var obj = (IDeepCloneable)e.Data.GetData(Constants.DragDropDataFormat); 455 456 Type objType = obj.GetType(); 457 if (ItemTask.IsTypeSupported(objType)) { 458 if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None; 459 else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 460 else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 461 } 462 } 463 464 private void jobsTreeView_DragDrop(object sender, DragEventArgs e) { 465 if (e.Effect != DragDropEffects.None) { 466 var obj = (IItem)e.Data.GetData(Constants.DragDropDataFormat); 467 468 IItem newObj = null; 469 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 470 newObj = (IItem)obj.Clone(); 471 } else { 472 newObj = obj; 473 } 474 475 //IOptimizer and IExecutables need some special care 476 if (newObj is IOptimizer) { 477 ((IOptimizer)newObj).Runs.Clear(); 478 } 479 if (newObj is IExecutable) { 480 IExecutable exec = (IExecutable)newObj; 481 if (exec.ExecutionState != ExecutionState.Prepared) { 482 exec.Prepare(); 483 } 484 } 485 486 ItemTask hiveTask = ItemTask.GetItemTaskForItem(newObj); 487 Content.HiveTasks.Add(hiveTask.CreateHiveTask()); 488 } 489 } 490 #endregion 491 492 private void tabControl_SelectedIndexChanged(object sender, EventArgs e) { 493 if (tabControl.SelectedTab == permissionTabPage) { 494 if (!Content.IsSharable) { 495 MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 496 tabControl.SelectedTab = tasksTabPage; 497 } 498 } 499 } 500 501 private RunCollection GetAllRunsFromJob(RefreshableJob job) { 502 if (job != null) { 503 RunCollection runs = new RunCollection() { OptimizerName = job.ItemName }; 504 505 foreach (HiveTask subTask in job.HiveTasks) { 506 if (subTask is OptimizerHiveTask) { 507 OptimizerHiveTask ohTask = subTask as OptimizerHiveTask; 508 ohTask.ExecuteReadActionOnItemTask(new Action(delegate() { 509 runs.AddRange(ohTask.ItemTask.Item.Runs); 510 })); 511 } 512 } 513 return runs; 514 } else { 515 return null; 516 } 500 UpdateSelectorDialog(); 501 } 502 503 private void updateButton_Click2(object sender, EventArgs e) { 504 if (Content.ExecutionState == ExecutionState.Stopped) { 505 MessageBox.Show("Job cannot be updated once it stopped.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 506 return; 507 } 508 509 HiveClient.UpdateJob( 510 (Exception ex) => ErrorHandling.ShowErrorDialog(this, "Update failed.", ex), 511 Content, 512 new CancellationToken()); 513 UpdateSelectorDialog(); 514 } 515 516 private void updateButton_Click(object sender, EventArgs e) { 517 if (Content.ExecutionState == ExecutionState.Stopped) { 518 MessageBox.Show("Job cannot be updated once it stopped.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 519 return; 520 } 521 522 var invoker = new Action<RefreshableJob>(HiveClient.UpdateJob); 523 invoker.BeginInvoke(Content, (ar) => { 524 try { 525 invoker.EndInvoke(ar); 526 } catch (Exception ex) { 527 ThreadPool.QueueUserWorkItem(delegate (object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); 528 } 529 }, null); 530 UpdateSelectorDialog(); 517 531 } 518 532 … … 526 540 SetEnabledStateOfControls(); 527 541 } 542 543 private void refreshPermissionsButton_Click(object sender, EventArgs e) { 544 if (this.Content.Job.Id == Guid.Empty) { 545 MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 546 } else { 547 hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id); 548 } 549 } 550 #endregion 551 552 #region Helpers 553 private void SetEnabledStateOfExecutableButtons() { 554 if (Content == null) { 555 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = false; 556 } else { 557 startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 558 && Content.Job.ProjectId != null && Content.Job.ProjectId != Guid.Empty && Content.Job.ResourceIds != null && Content.Job.ResourceIds.Any() 559 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 560 pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing; 561 stopButton.Enabled = Content.IsControllable && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 562 } 563 } 564 565 private Project GetProject(Guid projectId) { 566 return HiveServiceLocator.Instance.CallHiveService(s => s.GetProject(projectId)); 567 } 568 569 private void UpdateSelectorDialog() { 570 if(hiveResourceSelectorDialog != null) { 571 hiveResourceSelectorDialog = null; 572 //hiveResourceSelectorDialog.JobId = Content.Job.Id; 573 //hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 574 //hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 575 } 576 } 577 #endregion 578 579 #region Drag & Drop 580 private void jobsTreeView_DragOver(object sender, DragEventArgs e) { 581 jobsTreeView_DragEnter(sender, e); 582 } 583 584 private void jobsTreeView_DragEnter(object sender, DragEventArgs e) { 585 e.Effect = DragDropEffects.None; 586 var obj = (IDeepCloneable)e.Data.GetData(Constants.DragDropDataFormat); 587 588 Type objType = obj.GetType(); 589 if (ItemTask.IsTypeSupported(objType)) { 590 if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None; 591 else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 592 else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 593 } 594 } 595 596 private void jobsTreeView_DragDrop(object sender, DragEventArgs e) { 597 if (e.Effect != DragDropEffects.None) { 598 var obj = (IItem)e.Data.GetData(Constants.DragDropDataFormat); 599 600 IItem newObj = null; 601 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 602 newObj = (IItem)obj.Clone(); 603 } else { 604 newObj = obj; 605 } 606 607 //IOptimizer and IExecutables need some special care 608 if (newObj is IOptimizer) { 609 ((IOptimizer)newObj).Runs.Clear(); 610 } 611 if (newObj is IExecutable) { 612 IExecutable exec = (IExecutable)newObj; 613 if (exec.ExecutionState != ExecutionState.Prepared) { 614 exec.Prepare(); 615 } 616 } 617 618 ItemTask hiveTask = ItemTask.GetItemTaskForItem(newObj); 619 Content.HiveTasks.Add(hiveTask.CreateHiveTask()); 620 } 621 } 622 #endregion 623 624 private void tabControl_SelectedIndexChanged(object sender, EventArgs e) { 625 if (tabControl.SelectedTab == permissionTabPage) { 626 if (!Content.IsSharable) { 627 MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 628 tabControl.SelectedTab = tasksTabPage; 629 } 630 } 631 } 632 633 private RunCollection GetAllRunsFromJob(RefreshableJob job) { 634 if (job != null) { 635 RunCollection runs = new RunCollection() { OptimizerName = job.ItemName }; 636 637 foreach (HiveTask subTask in job.HiveTasks) { 638 if (subTask is OptimizerHiveTask) { 639 OptimizerHiveTask ohTask = subTask as OptimizerHiveTask; 640 ohTask.ExecuteReadActionOnItemTask(new Action(delegate () { 641 runs.AddRange(ohTask.ItemTask.Item.Runs); 642 })); 643 } 644 } 645 return runs; 646 } else { 647 return null; 648 } 649 } 650 528 651 } 529 652 }
Note: See TracChangeset
for help on using the changeset viewer.