Changeset 16386 for branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
- Timestamp:
- 12/15/18 12:07:16 (5 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Clients.Hive.JobManager
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r15583 r16386 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 // project look up 142 if (Content.Job != null && Content.Job.ProjectId == Guid.Empty) { 143 projectNameTextBox.Text = string.Empty; 144 if (HiveClient.Instance != null && HiveClient.Instance.Projects != null && HiveClient.Instance.Projects.Count == 1) { 145 var p = HiveClient.Instance.Projects.FirstOrDefault(); 146 if (p != null && p.Id != Guid.Empty) { 147 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId); 148 Content.Job.ProjectId = p.Id; 149 var resources = HiveClient.Instance.GetAvailableResourcesForProject(p.Id).ToList(); 150 Content.Job.ResourceIds = resources.Select(x => x.Id).ToList(); 151 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 152 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 153 154 var cores = resources.Union(resources.SelectMany(x => HiveClient.Instance.GetAvailableResourceDescendants(x.Id))) 155 .OfType<Slave>() 156 .Distinct() 157 .Sum(x => x.Cores); 158 159 projectNameTextBox.Text = HiveClient.Instance.GetProjectAncestry(Content.Job.ProjectId); 160 projectNameTextBox.Text += " (" + (cores.HasValue ? cores.Value.ToString() : "0") + " cores)"; 161 } 162 } 163 } else if (Content.Job != null && Content.Job.ProjectId != Guid.Empty) { 164 if (selectedProject == null || selectedProject.Id != Content.Job.ProjectId) { 165 selectedProject = GetProject(Content.Job.ProjectId); 166 hiveResourceSelectorDialog = null; 167 } 168 169 if(hiveResourceSelectorDialog == null) 170 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId); 171 172 if (selectedProject != null) { 173 projectNameTextBox.Text = HiveClient.Instance.GetProjectAncestry(selectedProject.Id); 174 } else { 175 projectNameTextBox.Text = string.Empty; 176 } 177 178 List<Resource> resources = null; 179 if (Content.Job.ResourceIds == null) 180 resources = HiveClient.Instance.GetAssignedResourcesForJob(Content.Job.Id).ToList(); 181 else 182 resources = HiveClient.Instance.Resources.Where(x => Content.Job.ResourceIds.Contains(x.Id)).ToList(); 183 184 Content.Job.ResourceIds = resources.Select(x => x.Id).ToList(); 185 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 186 187 var cores = resources.Union(resources.SelectMany(x => HiveClient.Instance.GetAvailableResourceDescendants(x.Id))) 188 .OfType<Slave>() 189 .Distinct() 190 .Sum(x => x.Cores); 191 192 projectNameTextBox.Text += " (" + (cores.HasValue ? cores.Value.ToString() : "0") + " cores)"; 193 194 } else { 195 selectedProject = null; 196 projectNameTextBox.Text = string.Empty; 197 Content.Job.ResourceIds = null; 198 } 199 200 130 201 nameTextBox.Text = Content.Job.Name; 202 descriptionTextBox.Text = Content.Job.Description; 131 203 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 132 resourceNamesTextBox.Text = Content.Job.ResourceNames;133 204 refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically; 205 134 206 logView.Content = Content.Log; 135 207 lock (runCollectionViewLocker) { … … 137 209 } 138 210 } 139 } 140 finally { 211 } finally { 141 212 SuppressEvents = false; 142 213 } 143 hiveExperimentPermissionListView.Content = null; // has to be filled by refresh button214 hiveExperimentPermissionListView.Content = null; // has to be filled by refresh 144 215 Content_JobStatisticsChanged(this, EventArgs.Empty); 145 216 Content_HiveExperimentChanged(this, EventArgs.Empty); … … 158 229 tabControl.Enabled = !Locked; 159 230 nameTextBox.Enabled = !Locked; 160 resourceNamesTextBox.Enabled = !Locked; 231 descriptionTextBox.Enabled = !Locked; 232 projectNameTextBox.Enabled = !Locked; 161 233 searchButton.Enabled = !Locked; 162 234 jobsTreeView.Enabled = !Locked; … … 182 254 tabControl.Enabled = !Content.IsProgressing; 183 255 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;256 this.nameTextBox.ReadOnly = Content.IsProgressing; 257 this.descriptionTextBox.ReadOnly = Content.IsProgressing; 258 this.searchButton.Enabled = !Content.IsProgressing && Content.ExecutionState != ExecutionState.Stopped; 187 259 this.jobsTreeView.ReadOnly = !Content.IsControllable || Content.ExecutionState != ExecutionState.Prepared || alreadyUploaded || Content.IsProgressing; 188 260 189 261 this.refreshAutomaticallyCheckBox.Enabled = Content.IsControllable && alreadyUploaded && jobsLoaded && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 190 262 this.refreshButton.Enabled = Content.IsDownloadable && alreadyUploaded && !Content.IsProgressing; 263 this.updateButton.Enabled = Content.ExecutionState != ExecutionState.Prepared && Content.ExecutionState != ExecutionState.Stopped && !Content.IsProgressing; 191 264 192 265 this.UnloadButton.Enabled = Content.HiveTasks != null && Content.HiveTasks.Count > 0 && alreadyUploaded && !Content.IsProgressing; … … 333 406 #region Control events 334 407 private void searchButton_Click(object sender, EventArgs e) { 335 if (hiveResourceSelectorDialog == null) 336 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(); 408 if (hiveResourceSelectorDialog == null) { 409 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId); 410 } else if(hiveResourceSelectorDialog.JobId != Content.Job.Id) { 411 hiveResourceSelectorDialog.JobId = Content.Job.Id; 412 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 413 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 414 415 if (originalJobProjectAssignment.ContainsKey(Content.Job.Id)) { 416 hiveResourceSelectorDialog.ProjectId = originalJobProjectAssignment[Content.Job.Id]; 417 } else { 418 hiveResourceSelectorDialog.ProjectId = Guid.Empty; 419 } 420 } else if(hiveResourceSelectorDialog.JobId == Guid.Empty && Content.Job.Id == Guid.Empty) { 421 hiveResourceSelectorDialog.JobId = Content.Job.Id; 422 hiveResourceSelectorDialog.ProjectId = Guid.Empty; 423 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 424 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 425 } else { 426 hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 427 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 428 } 429 337 430 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; 431 selectedProject = hiveResourceSelectorDialog.SelectedProject; 432 if(selectedProject != null) { 433 Content.Job.ProjectId = selectedProject.Id; 434 Content.Job.ResourceIds = hiveResourceSelectorDialog.SelectedResources.Select(x => x.Id).ToList(); 435 436 var cores = hiveResourceSelectorDialog.SelectedResources 437 .Union(hiveResourceSelectorDialog.SelectedResources 438 .SelectMany(x => HiveClient.Instance.GetAvailableResourceDescendants(x.Id))) 439 .OfType<Slave>() 440 .Distinct() 441 .Sum(x => x.Cores); 442 443 projectNameTextBox.Text = HiveClient.Instance.GetProjectAncestry(selectedProject.Id) + ""; 444 projectNameTextBox.Text += " (" + (cores.HasValue ? cores.Value.ToString() : "0") + " cores)"; 445 446 } else { 447 selectedProject = null; 448 projectNameTextBox.Text = string.Empty; 449 Content.Job.ProjectId = Guid.Empty; 450 Content.Job.ResourceIds = null; 451 } 452 SetEnabledStateOfExecutableButtons(); 346 453 } 347 454 } … … 350 457 if (nameTextBox.Text.Trim() == string.Empty) { 351 458 MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 459 } else if (Content.Job.ProjectId == null || Content.Job.ProjectId == Guid.Empty) { 460 MessageBox.Show("Please select a project before uploading the job!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 461 } else if (Content.Job.ResourceIds == null || !Content.Job.ResourceIds.Any()) { 462 MessageBox.Show("Please select resources before uploading the job!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 352 463 } else if (Content.ExecutionState == ExecutionState.Paused) { 353 464 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content); … … 359 470 } else { 360 471 HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken()); 472 UpdateSelectorDialog(); 361 473 } 362 474 } … … 403 515 } 404 516 517 private void descriptionTextBox_Validated(object sender, EventArgs e) { 518 if (!SuppressEvents && Content.Job != null && Content.Job.Description != descriptionTextBox.Text) 519 Content.Job.Description = descriptionTextBox.Text; 520 } 521 405 522 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;523 //if (!SuppressEvents && Content.Job != null && Content.Job.ResourceNames != resourceNamesTextBox.Text) 524 // Content.Job.ResourceNames = resourceNamesTextBox.Text; 408 525 } 409 526 … … 417 534 try { 418 535 invoker.EndInvoke(ar); 419 } 420 catch (Exception ex) { 421 ThreadPool.QueueUserWorkItem(delegate(object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); 536 } catch (Exception ex) { 537 ThreadPool.QueueUserWorkItem(delegate (object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); 422 538 } 423 539 }, 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 } 540 UpdateSelectorDialog(); 541 } 542 543 private void updateButton_Click(object sender, EventArgs e) { 544 if (Content.ExecutionState == ExecutionState.Stopped) { 545 MessageBox.Show("Job cannot be updated once it stopped.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 546 return; 547 } 548 549 var invoker = new Action<RefreshableJob>(HiveClient.UpdateJob); 550 invoker.BeginInvoke(Content, (ar) => { 551 try { 552 invoker.EndInvoke(ar); 553 } catch (Exception ex) { 554 ThreadPool.QueueUserWorkItem(delegate (object exception) { ErrorHandling.ShowErrorDialog(this, (Exception)exception); }, ex); 555 } 556 }, null); 557 UpdateSelectorDialog(); 517 558 } 518 559 … … 526 567 SetEnabledStateOfControls(); 527 568 } 569 570 private void refreshPermissionsButton_Click(object sender, EventArgs e) { 571 if (this.Content.Job.Id == Guid.Empty) { 572 MessageBox.Show("You have to upload the Job first before you can share it.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 573 } else { 574 hiveExperimentPermissionListView.Content = HiveClient.GetJobPermissions(this.Content.Job.Id); 575 } 576 } 577 #endregion 578 579 #region Helpers 580 private void SetEnabledStateOfExecutableButtons() { 581 if (Content == null) { 582 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = false; 583 } else { 584 startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 585 && Content.Job.ProjectId != Guid.Empty && Content.Job.ResourceIds != null && Content.Job.ResourceIds.Any() 586 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 587 pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing; 588 stopButton.Enabled = Content.IsControllable && (Content.ExecutionState == ExecutionState.Started || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 589 } 590 } 591 592 private Project GetProject(Guid projectId) { 593 return HiveServiceLocator.Instance.CallHiveService(s => s.GetProject(projectId)); 594 } 595 596 private void UpdateSelectorDialog() { 597 if(hiveResourceSelectorDialog != null) { 598 hiveResourceSelectorDialog = null; 599 //hiveResourceSelectorDialog.JobId = Content.Job.Id; 600 //hiveResourceSelectorDialog.SelectedProjectId = Content.Job.ProjectId; 601 //hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 602 } 603 } 604 #endregion 605 606 #region Drag & Drop 607 private void jobsTreeView_DragOver(object sender, DragEventArgs e) { 608 jobsTreeView_DragEnter(sender, e); 609 } 610 611 private void jobsTreeView_DragEnter(object sender, DragEventArgs e) { 612 e.Effect = DragDropEffects.None; 613 var obj = (IDeepCloneable)e.Data.GetData(Constants.DragDropDataFormat); 614 615 Type objType = obj.GetType(); 616 if (ItemTask.IsTypeSupported(objType)) { 617 if (Content.Id != Guid.Empty) e.Effect = DragDropEffects.None; 618 else if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 619 else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 620 } 621 } 622 623 private void jobsTreeView_DragDrop(object sender, DragEventArgs e) { 624 if (e.Effect != DragDropEffects.None) { 625 var obj = (IItem)e.Data.GetData(Constants.DragDropDataFormat); 626 627 IItem newObj = null; 628 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 629 newObj = (IItem)obj.Clone(); 630 } else { 631 newObj = obj; 632 } 633 634 //IOptimizer and IExecutables need some special care 635 if (newObj is IOptimizer) { 636 ((IOptimizer)newObj).Runs.Clear(); 637 } 638 if (newObj is IExecutable) { 639 IExecutable exec = (IExecutable)newObj; 640 if (exec.ExecutionState != ExecutionState.Prepared) { 641 exec.Prepare(); 642 } 643 } 644 645 ItemTask hiveTask = ItemTask.GetItemTaskForItem(newObj); 646 Content.HiveTasks.Add(hiveTask.CreateHiveTask()); 647 } 648 } 649 #endregion 650 651 private void tabControl_SelectedIndexChanged(object sender, EventArgs e) { 652 if (tabControl.SelectedTab == permissionTabPage) { 653 if (!Content.IsSharable) { 654 MessageBox.Show("Unable to load permissions. You have insufficient access privileges.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information); 655 tabControl.SelectedTab = tasksTabPage; 656 } 657 } 658 } 659 660 private RunCollection GetAllRunsFromJob(RefreshableJob job) { 661 if (job != null) { 662 RunCollection runs = new RunCollection() { OptimizerName = job.ItemName }; 663 664 foreach (HiveTask subTask in job.HiveTasks) { 665 if (subTask is OptimizerHiveTask) { 666 OptimizerHiveTask ohTask = subTask as OptimizerHiveTask; 667 ohTask.ExecuteReadActionOnItemTask(new Action(delegate () { 668 runs.AddRange(ohTask.ItemTask.Item.Runs); 669 })); 670 } 671 } 672 return runs; 673 } else { 674 return null; 675 } 676 } 677 528 678 } 529 679 }
Note: See TracChangeset
for help on using the changeset viewer.