- Timestamp:
- 02/20/18 14:32:16 (7 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r15777 r15792 250 250 if (result == DialogResult.Yes) { 251 251 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 252 action: () => RemoveProject(selectedProject), 252 action: () => { 253 RemoveProject(selectedProject); 254 }, 253 255 finallyCallback: () => { 254 256 removeButton.Enabled = true; … … 358 360 359 361 #region Helpers 360 private void ResetTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) {361 foreach (TreeNode n in nodes) {362 var pro = ((Project)n.Tag);363 if (n.BackColor.Equals(c1)) {364 n.BackColor = c2;365 }366 if (resetText) {367 n.Text = pro.Name;368 369 if (pro.Id == Guid.Empty) {370 n.Text += " [not stored]";371 } else if (pro.Modified) {372 n.Text += " [changes not stored]";373 }374 }375 if (n.Nodes.Count > 0) {376 ResetTreeNodes(n.Nodes, c1, c2, resetText);377 }378 }379 }380 381 private void ChangeSelectedProject(Project project) {382 projectView.Content = project;383 projectPermissionsView.Content = project;384 projectResourcesView.Content = project;385 386 bool locked = project == null || (project != null && project.Id == Guid.Empty);387 addButton.Enabled = !locked;388 projectPermissionsView.Locked = locked;389 projectResourcesView.Locked = locked;390 selectedProject = project;391 }392 393 private void ChangeSelectedProjectNode(TreeNode projectNode) {394 if (projectNode == null) return;395 SelectedProject = (Project)projectNode.Tag;396 ResetTreeNodes(projectsTreeView.Nodes, selectedColor, Color.Transparent, true);397 projectNode.BackColor = selectedColor;398 projectNode.Text += " [selected]";399 }400 401 362 private void BuildProjectTree(IEnumerable<Project> projects) { 402 363 projectsTreeView.Nodes.Clear(); … … 407 368 .Where(x => x.ParentProjectId.HasValue 408 369 && !projects.Select(y => y.Id).Contains(x.ParentProjectId.Value))); 409 370 mainProjects.UnionWith(parentedMainProjects); 410 371 var subProbjects = new HashSet<Project>(projects.Except(mainProjects)); 411 372 … … 416 377 TreeNode currentNode = null; 417 378 Project currentProject = null; 418 379 419 380 while (stack.Any()) { 420 381 var newProject = stack.Pop(); 421 382 var newNode = new TreeNode(newProject.Name) { Tag = newProject }; 422 423 if (newProject.Id == Guid.Empty) { 424 newNode.Text += " [not stored]"; 425 } else if(newProject.Modified) { 426 newNode.Text += " [changes not stored]"; 427 } 383 StyleTreeNode(newNode, newProject); 384 428 385 if (selectedProject == null) { 429 386 SelectedProject = newProject; … … 467 424 } 468 425 426 private void StyleTreeNode(TreeNode n, Project p) { 427 n.Text = p.Name; 428 n.BackColor = Color.Transparent; 429 n.ForeColor = Color.Black; 430 431 if (p.Id == Guid.Empty) { 432 n.Text += " [not stored]"; 433 } else if (p.Modified) { 434 n.Text += " [changes not stored]"; 435 } 436 } 437 438 private void ResetTreeNodes(TreeNodeCollection nodes) { 439 foreach (TreeNode n in nodes) { 440 StyleTreeNode(n, (Project)n.Tag); 441 if (n.Nodes.Count > 0) { 442 ResetTreeNodes(n.Nodes); 443 } 444 } 445 } 446 447 private void ChangeSelectedProject(Project project) { 448 projectView.Content = project; 449 projectPermissionsView.Content = project; 450 projectResourcesView.Content = project; 451 452 bool locked = project == null || (project != null && project.Id == Guid.Empty); 453 addButton.Enabled = !locked; 454 projectPermissionsView.Locked = locked; 455 projectResourcesView.Locked = locked; 456 selectedProject = project; 457 } 458 459 private void ChangeSelectedProjectNode(TreeNode projectNode) { 460 if (projectNode == null) return; 461 SelectedProject = (Project)projectNode.Tag; 462 ResetTreeNodes(projectsTreeView.Nodes); 463 projectNode.BackColor = selectedColor; 464 projectNode.Text += " [selected]"; 465 } 466 469 467 private void UpdateProjects() { 470 468 try { … … 480 478 481 479 try { 482 if(project.Id != Guid.Empty) HiveAdminClient.Delete(project); 483 Content.Remove(selectedProject); 480 if (project.Id != Guid.Empty) { 481 var projectsToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified); 482 foreach (var p in projectsToSave) 483 p.Store(); 484 HiveAdminClient.Delete(project); 485 UpdateProjects(); 486 } else { 487 Content.Remove(project); 488 } 484 489 } catch (AnonymousUserException) { 485 490 ShowHiveInformationDialog(); -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15777 r15792 45 45 private readonly Color changedColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 46 46 private readonly Color selectedColor = Color.FromArgb(255, 240, 194, 59); // #f0c23b 47 private readonly Color calculatingColor = Color.FromArgb(255, 58, 114, 35); // #3a7223 48 private readonly Color offlineColor = Color.FromArgb(255, 187, 36, 36); // #bb2424 47 49 48 50 private Resource selectedResource = null; … … 215 217 }; 216 218 219 HiveAdminClient.Instance.UpdateResourceGenealogy(Content); 217 220 SelectedResource = group; 218 221 Content.Add(group); … … 252 255 if (result == DialogResult.Yes) { 253 256 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 254 action: () => RemoveResource(selectedResource), 255 finallyCallback: () => { 257 action: () => { 258 RemoveResource(selectedResource); 259 }, 260 finallyCallback: () => { 256 261 btnRemoveGroup.Enabled = true; 257 262 }); … … 279 284 private void treeSlaveGroup_MouseDown(object sender, MouseEventArgs e) { 280 285 var node = treeView.GetNodeAt(e.Location); 281 if(node != null && node.Name != ungroupedGroupName) ChangeSelectedResourceNode(node);286 if(node != null && !node.Text.StartsWith(ungroupedGroupName)) ChangeSelectedResourceNode(node); 282 287 } 283 288 … … 325 330 } 326 331 332 HiveAdminClient.Instance.UpdateResourceGenealogy(Content); 327 333 SelectedResource = sourceResource; 328 334 OnContentChanged(); … … 350 356 || sourceNode == targetNode 351 357 || !HiveAdminClient.Instance.CheckParentChange(sourceResource, targetResource) 352 || (targetNode != null && (targetNode.Text == ungroupedGroupName || targetNode.Parent != null && targetNode.Parent.Text == ungroupedGroupName))) {358 || (targetNode != null && (targetNode.Text.StartsWith(ungroupedGroupName) || targetNode.Parent != null && targetNode.Parent.Text.StartsWith(ungroupedGroupName)))) { 353 359 e.Effect = DragDropEffects.None; 354 360 } … … 361 367 362 368 #region Helpers 363 private void ResetTreeNodes(TreeNodeCollection nodes, Color c1, Color c2, bool resetText) {364 foreach (TreeNode n in nodes) {365 var res = ((Resource)n.Tag);366 if (n.BackColor.Equals(c1)) {367 n.BackColor = c2;368 }369 if (resetText) {370 n.Text = res.Name;371 372 if (res.Id == Guid.Empty && res.Name != ungroupedGroupName) {373 n.Text += " [not stored]";374 } else if (res.Modified && res.Name != ungroupedGroupName) {375 n.Text += " [changes not stored]";376 }377 }378 if (n.Nodes.Count > 0) {379 ResetTreeNodes(n.Nodes, c1, c2, resetText);380 }381 }382 }383 384 369 private void BuildResourceTree(IEnumerable<Resource> resources) { 385 370 treeView.Nodes.Clear(); … … 400 385 Resource currentResource = null; 401 386 402 while (stack.Any()) {387 while (stack.Any()) { 403 388 var newResource = stack.Pop(); 404 389 var newNode = new TreeNode(newResource.Name) { Tag = newResource }; 405 406 if(newResource.Id == Guid.Empty) { 407 newNode.Text += " [not stored]"; 408 } else if(newResource.Modified) { 409 newNode.Text += " [changes not stored]"; 410 } 390 StyleTreeNode(newNode, newResource, resources); 391 411 392 if (selectedResource == null) { 412 393 SelectedResource = newResource; … … 426 407 } 427 408 428 if (currentNode == null) {409 if (currentNode == null) { 429 410 treeView.Nodes.Add(newNode); 430 411 } else { … … 432 413 } 433 414 434 if(newResource is Slave) { 435 newNode.ImageIndex = slaveImageIndex; 436 } else { 437 newNode.ImageIndex = slaveGroupImageIndex; 438 415 if (newResource is SlaveGroup) { 439 416 var childResources = subResources.Where(x => x.ParentResourceId == newResource.Id); 440 if (childResources.Any()) {441 foreach (var resource in childResources.OrderByDescending(x => x.Name)) {417 if (childResources.Any()) { 418 foreach (var resource in childResources.OrderByDescending(x => x.Name)) { 442 419 subResources.Remove(resource); 443 420 stack.Push(resource); … … 448 425 } 449 426 newNode.SelectedImageIndex = newNode.ImageIndex; 450 //if (newResource.OwnerUserId == UserInformation.Instance.User.Id)451 // newNode.BackColor = ownedResourceColor;452 427 } 453 428 … … 460 435 }; 461 436 437 int ungroupedSlavesCount = 0; 462 438 foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) { 463 439 var slaveNode = new TreeNode(slave.Name) { Tag = slave }; 440 StyleTreeNode(slaveNode, slave, resources); 464 441 ungroupedNode.Nodes.Add(slaveNode); 465 if(selectedResource == null) { 442 ungroupedSlavesCount++; 443 if (selectedResource == null) { 466 444 SelectedResource = slave; 467 445 } 468 if (slave.Id == Guid.Empty) { 469 slaveNode.Text += " [not stored]"; 470 } else if (slave.Modified) { 471 slaveNode.Text += " [changes not stored]"; 472 } 446 473 447 if (slave.Id == selectedResource.Id && !nodeSelected) { 474 448 slaveNode.BackColor = selectedColor; … … 478 452 } 479 453 454 if (ungroupedSlavesCount > 0) 455 ungroupedNode.Text += " [" + ungroupedSlavesCount.ToString() + "]"; 480 456 treeView.Nodes.Add(ungroupedNode); 481 457 treeView.ExpandAll(); 458 482 459 } 483 460 … … 488 465 UpdateChildHbIntervall(r); 489 466 } 490 }491 }492 493 private bool CheckParentsEqualsMovedNode(TreeNode dest, TreeNode movedNode) {494 TreeNode tmp = dest;495 496 while (tmp != null) {497 if (tmp == movedNode) {498 return true;499 }500 tmp = tmp.Parent;501 }502 return false;503 }504 505 private void ResetView() {506 if (InvokeRequired) Invoke((Action)ResetView);507 else {508 treeView.Nodes.Clear();509 510 if (viewHost.Content != null && viewHost.Content is SlaveGroup) {511 ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged;512 }513 514 viewHost.Content = null;515 if (scheduleView.Content != null) {516 scheduleView.Content.Clear();517 }518 519 HiveAdminClient.Instance.ResetDowntime();520 467 } 521 468 } … … 534 481 535 482 try { 536 if(resource.Id != Guid.Empty) HiveAdminClient.Delete(resource); 537 Content.Remove(selectedResource); 483 if (resource.Id != Guid.Empty) { 484 var resourcesToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified); 485 foreach (var r in resourcesToSave) 486 r.Store(); 487 HiveAdminClient.Delete(resource); 488 UpdateResources(); 489 } else { 490 Content.Remove(selectedResource); 491 } 538 492 } catch(AnonymousUserException) { 539 493 ShowHiveInformationDialog(); … … 549 503 } 550 504 551 private bool IsAuthorized(Resource resource) {552 return resource != null553 && resource.Name != ungroupedGroupName554 //&& resource.Id != Guid.Empty555 && UserInformation.Instance.UserExists556 && (HiveRoles.CheckAdminUserPermissions()557 || HiveAdminClient.Instance.CheckOwnershipOfResource(resource, UserInformation.Instance.User.Id));558 }559 560 505 private bool IsAdmin() { 561 506 return HiveRoles.CheckAdminUserPermissions(); 507 } 508 509 private void StyleTreeNode(TreeNode n, Resource r, IEnumerable<Resource> resources) { 510 n.Text = r.Name; 511 n.BackColor = Color.Transparent; 512 n.ForeColor = Color.Black; 513 514 // slave count 515 int childSlavesCount = 0; 516 if (r.Id != Guid.Empty && r is SlaveGroup) { 517 var descendants = HiveAdminClient.Instance.ResourceDescendants; 518 if (descendants.ContainsKey(r.Id)) { 519 childSlavesCount = resources 520 .OfType<Slave>() 521 .Where(x => descendants[r.Id].Select(y => y.Id) 522 .Contains(x.Id)) 523 .Count(); 524 } 525 } else if(r.Name.StartsWith(ungroupedGroupName)) { 526 childSlavesCount = resources 527 .OfType<Slave>() 528 .Where(x => x.ParentResourceId == null 529 || (x.ParentResourceId.HasValue && x.ParentResourceId.Value == Guid.Empty)) 530 .Count(); 531 } 532 if (childSlavesCount > 0) 533 n.Text += " [" + childSlavesCount.ToString() + "]"; 534 535 // slave image index, state, utilization 536 if (r is Slave) { 537 n.ImageIndex = slaveImageIndex; 538 var s = r as Slave; 539 if (s.SlaveState == SlaveState.Calculating) { 540 n.ForeColor = calculatingColor; 541 n.Text += " [" + s.CpuUtilization.ToString("N2") + "%]"; 542 } else if (s.SlaveState == SlaveState.Offline) { 543 n.ForeColor = offlineColor; 544 if (s.LastHeartbeat.HasValue) 545 n.Text += " [" + s.LastHeartbeat?.ToString("g") + "]"; 546 } 547 } else { 548 n.ImageIndex = slaveGroupImageIndex; 549 } 550 551 // not stored (i.e. new), changed 552 if (r.Id == Guid.Empty && !r.Name.StartsWith(ungroupedGroupName)) { 553 n.Text += " [not stored]"; 554 } else if (r.Modified && !r.Name.StartsWith(ungroupedGroupName)) { 555 n.Text += " [changes not stored]"; 556 } 557 558 // ungrouped 559 if(r.Name.StartsWith(ungroupedGroupName)) { 560 n.ForeColor = ForeColor = SystemColors.GrayText; 561 } 562 } 563 564 private void ResetTreeNodes(TreeNodeCollection nodes, IEnumerable<Resource> resources) { 565 foreach (TreeNode n in nodes) { 566 StyleTreeNode(n, (Resource)n.Tag, resources); 567 if (n.Nodes.Count > 0) { 568 ResetTreeNodes(n.Nodes, resources); 569 } 570 } 562 571 } 563 572 … … 571 580 572 581 bool locked = !IsAdmin() || resource == null; 573 bool addLocked = locked || (resource != null && resource.Id == Guid.Empty); 582 bool scheduleLocked = locked || (resource != null && resource.Id == Guid.Empty); 583 bool addLocked = locked || (resource != null && resource.Id == Guid.Empty) || resource is Slave; 574 584 575 585 btnAddGroup.Enabled = !addLocked; … … 578 588 viewHost.Locked = locked; 579 589 scheduleView.Locked = locked; 580 scheduleView.SetEnabledStateOfSchedule(! addLocked);590 scheduleView.SetEnabledStateOfSchedule(!scheduleLocked); 581 591 } 582 592 … … 584 594 if (resourceNode == null) return; 585 595 SelectedResource = (Resource)resourceNode.Tag; 586 ResetTreeNodes(treeView.Nodes, selectedColor, Color.Transparent, true);596 ResetTreeNodes(treeView.Nodes, Content); 587 597 resourceNode.BackColor = selectedColor; 588 598 resourceNode.Text += " [selected]"; … … 597 607 } 598 608 } 609 610 private void ResetView() { 611 if (InvokeRequired) Invoke((Action)ResetView); 612 else { 613 treeView.Nodes.Clear(); 614 615 if (viewHost.Content != null && viewHost.Content is SlaveGroup) { 616 ((SlaveGroup)viewHost.Content).PropertyChanged -= SlaveViewContent_PropertyChanged; 617 } 618 619 viewHost.Content = null; 620 if (scheduleView.Content != null) { 621 scheduleView.Content.Clear(); 622 } 623 624 HiveAdminClient.Instance.ResetDowntime(); 625 } 626 } 627 599 628 #endregion 600 629 } -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15777 r15792 77 77 private Dictionary<Guid, HashSet<Resource>> resourceAncestors; 78 78 public Dictionary<Guid, HashSet<Resource>> ResourceAncestors { 79 get { return ResourceAncestors; }79 get { return resourceAncestors; } 80 80 } 81 81 82 82 private Dictionary<Guid, HashSet<Resource>> resourceDescendants; 83 83 public Dictionary<Guid, HashSet<Resource>> ResourceDescendants { 84 get { return ResourceDescendants; }84 get { return resourceDescendants; } 85 85 } 86 86 … … 122 122 }); 123 123 124 UpdateResourceGenealogy( );125 UpdateProjectGenealogy( );124 UpdateResourceGenealogy(resources); 125 UpdateProjectGenealogy(projects); 126 126 } 127 127 catch { … … 133 133 } 134 134 135 p rivate void UpdateResourceGenealogy() {135 public void UpdateResourceGenealogy(IItemList<Resource> resources) { 136 136 resourceAncestors.Clear(); 137 137 resourceDescendants.Clear(); … … 157 157 } 158 158 159 p rivate void UpdateProjectGenealogy() {159 public void UpdateProjectGenealogy(IItemList<Project> projects) { 160 160 projectAncestors.Clear(); 161 161 projectDescendants.Clear();
Note: See TracChangeset
for help on using the changeset viewer.