Changeset 15792 for branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
- Timestamp:
- 02/20/18 14:32:16 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.