Changeset 15922 for branches/2839_HiveProjectManagement
- Timestamp:
- 04/26/18 16:33:53 (7 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectPermissionsView.Designer.cs
r15576 r15922 31 31 this.splitContainer = new System.Windows.Forms.SplitContainer(); 32 32 this.permissionsGroupBox = new System.Windows.Forms.GroupBox(); 33 this.treeView = new System.Windows.Forms.TreeView();33 this.treeView = new Hive.Views.TreeView.NoDoubleClickTreeView(); 34 34 this.detailsGroupBox = new System.Windows.Forms.GroupBox(); 35 35 this.detailsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); … … 184 184 private System.Windows.Forms.SplitContainer splitContainer; 185 185 private System.Windows.Forms.GroupBox permissionsGroupBox; 186 private System.Windows.Forms.TreeView treeView;186 private HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView treeView; 187 187 private System.Windows.Forms.GroupBox detailsGroupBox; 188 188 private MainForm.WindowsForms.ViewHost detailsViewHost; -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.Designer.cs
r15576 r15922 30 30 this.splitContainer = new System.Windows.Forms.SplitContainer(); 31 31 this.resourcesGroupBox = new System.Windows.Forms.GroupBox(); 32 this.treeView = new System.Windows.Forms.TreeView();32 this.treeView = new Hive.Views.TreeView.NoDoubleClickTreeView(); 33 33 this.imageList = new System.Windows.Forms.ImageList(this.components); 34 34 this.detailsGroupBox = new System.Windows.Forms.GroupBox(); … … 185 185 private System.Windows.Forms.GroupBox resourcesGroupBox; 186 186 private System.Windows.Forms.GroupBox detailsGroupBox; 187 private System.Windows.Forms.TreeView treeView;187 private HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView treeView; 188 188 private System.Windows.Forms.ImageList imageList; 189 189 private MainForm.WindowsForms.ViewHost detailsViewHost; -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs
r15819 r15922 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 7Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 51 51 private readonly HashSet<Resource> newIncludedResources = new HashSet<Resource>(); 52 52 53 private readonly Dictionary<Guid, HashSet<Project>> projectAncestors = new Dictionary<Guid, HashSet<Project>>();54 private readonly Dictionary<Guid, HashSet<Project>> projectDescendants = new Dictionary<Guid, HashSet<Project>>();55 private readonly Dictionary<Guid, HashSet<Resource>> resourceAncestors = new Dictionary<Guid, HashSet<Resource>>();56 private readonly Dictionary<Guid, HashSet<Resource>> resourceDescendants = new Dictionary<Guid, HashSet<Resource>>();57 58 53 private readonly Color addedAssignmentColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 59 54 private readonly Color removedAssignmentColor = Color.FromArgb(255, 236, 159, 72); // #ec9f48 … … 83 78 newAssignedResources.Clear(); 84 79 includedResources.Clear(); 85 resourceAncestors.Clear();86 80 treeView.Nodes.Clear(); 87 81 detailsViewHost.Content = null; 88 82 } else { 89 UpdateProjectGenealogy();90 83 UpdateAssignedResources(); 91 Update ResourceGenealogy();84 UpdateIncludedResources(); 92 85 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 93 86 detailsViewHost.Content = top; … … 111 104 112 105 private void refreshButton_Click(object sender, EventArgs e) { 113 UpdateProjectGenealogy();106 HiveAdminClient.Instance.Refresh(); 114 107 UpdateAssignedResources(); 115 Update ResourceGenealogy();108 UpdateIncludedResources(); 116 109 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 117 110 detailsViewHost.Content = top; … … 144 137 e.Cancel = true; 145 138 } else if (!HiveRoles.CheckAdminUserPermissions()) { 146 if (! projectAncestors[Content.Id].Any() || projectExclusiveResources.Contains(checkedResource)) {139 if (!HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).Any() || projectExclusiveResources.Contains(checkedResource)) { 147 140 e.Cancel = true; 148 141 } … … 166 159 private void UpdateResourceTree() { 167 160 UpdateAssignedResources(); 168 UpdateResourceGenealogy(); 161 UpdateIncludedResources(); 162 169 163 var top = BuildResourceTree(HiveAdminClient.Instance.Resources); 170 164 detailsViewHost.Content = top; … … 194 188 // look up for assignments of ancestor projects 195 189 var projectIds = new HashSet<Guid>(); 196 if(projectAncestors.ContainsKey(projectId)) { 197 projectAncestors[projectId].ToList().ForEach(x => projectIds.Add(x.Id)); 198 } 190 HiveClient.Instance.GetAvailableProjectAncestors(projectId).ToList().ForEach(x => projectIds.Add(x.Id)); 191 199 192 var ancestorProjectResources = resources.Where(x => 200 193 HiveAdminClient.Instance.ProjectResourceAssignments … … 206 199 HashSet<Resource> availableResources = new HashSet<Resource>(ancestorProjectResources); 207 200 foreach (var r in ancestorProjectResources) { 208 if(resourceDescendants.ContainsKey(r.Id)) { 209 foreach(var d in resourceDescendants[r.Id]) { 210 availableResources.Add(d); 211 } 201 foreach(var d in HiveAdminClient.Instance.GetAvailableResourceDescendants(r.Id)) { 202 availableResources.Add(d); 212 203 } 213 204 } … … 222 213 if (projectExclusiveResources.Any()) { 223 214 foreach (var r in projectExclusiveResources.ToArray()) { 224 if (resourceDescendants.ContainsKey(r.Id)) { 225 foreach (var d in resourceDescendants[r.Id]) { 226 projectExclusiveResources.Add(d); 227 } 228 } 215 foreach (var d in HiveAdminClient.Instance.GetAvailableResourceDescendants(r.Id)) { 216 projectExclusiveResources.Add(d); 217 } 229 218 } 230 219 } … … 251 240 private void UpdateNewAssignedResources() { 252 241 for(int i = newAssignedResources.Count -1; i >= 0; i--) { 253 if(newAssignedResources.Intersect( resourceAncestors[newAssignedResources.ElementAt(i).Id]).Any()) {242 if(newAssignedResources.Intersect(HiveAdminClient.Instance.GetAvailableResourceAncestors(newAssignedResources.ElementAt(i).Id)).Any()) { 254 243 newAssignedResources.Remove(newAssignedResources.ElementAt(i)); 255 244 } … … 266 255 } 267 256 257 private void UpdateIncludedResources() { 258 includedResources.Clear(); 259 newIncludedResources.Clear(); 260 foreach (var a in assignedResources) { 261 foreach (var r in HiveAdminClient.Instance.GetAvailableResourceDescendants(a.Id)) { 262 includedResources.Add(r); 263 newIncludedResources.Add(r); 264 } 265 } 266 } 267 268 268 private void UpdateNewIncludedResources() { 269 269 newIncludedResources.Clear(); 270 270 foreach (var a in newAssignedResources) { 271 if (resourceDescendants.ContainsKey(a.Id)) { 272 foreach (var r in resourceDescendants[a.Id]) { 273 newIncludedResources.Add(r); 274 } 271 foreach (var r in HiveAdminClient.Instance.GetAvailableResourceDescendants(a.Id)) { 272 newIncludedResources.Add(r); 275 273 } 276 274 } … … 325 323 newNode.Checked = true; 326 324 if(!HiveRoles.CheckAdminUserPermissions()) { 327 if(!projectAncestors[Content.Id].Any() || projectExclusiveResources.Contains(newResource)) { 325 if (!HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).Any() 326 || projectExclusiveResources.Contains(newResource)) { 328 327 newNode.ForeColor = SystemColors.GrayText; 329 328 newNode.Text += IMMUTABLE_TAG; … … 401 400 } 402 401 403 private void UpdateProjectGenealogy() {404 projectAncestors.Clear();405 projectDescendants.Clear();406 var projects = HiveAdminClient.Instance.Projects;407 408 foreach(var p in projects.Where(x => x.Id != Guid.Empty)) {409 projectAncestors.Add(p.Id, new HashSet<Project>());410 projectDescendants.Add(p.Id, new HashSet<Project>());411 }412 413 foreach (var p in projects.Where(x => x.Id != Guid.Empty)) {414 var parentProjectId = p.ParentProjectId;415 while (parentProjectId != null) {416 var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);417 if (parent != null) {418 projectAncestors[p.Id].Add(parent);419 projectDescendants[parent.Id].Add(p);420 parentProjectId = parent.ParentProjectId;421 } else {422 parentProjectId = null;423 }424 }425 }426 }427 428 private void UpdateResourceGenealogy() {429 resourceAncestors.Clear();430 resourceDescendants.Clear();431 var resources = HiveAdminClient.Instance.Resources;432 433 foreach (var r in resources.Where(x => x.Id != Guid.Empty)) {434 resourceAncestors.Add(r.Id, new HashSet<Resource>());435 resourceDescendants.Add(r.Id, new HashSet<Resource>());436 }437 438 foreach (var r in resources.Where(x => x.Id != Guid.Empty)) {439 var parentResourceId = r.ParentResourceId;440 while (parentResourceId != null) {441 var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);442 if (parent != null) {443 resourceAncestors[r.Id].Add(parent);444 resourceDescendants[parent.Id].Add(r);445 parentResourceId = parent.ParentResourceId;446 } else {447 parentResourceId = null;448 }449 }450 }451 452 includedResources.Clear();453 newIncludedResources.Clear();454 foreach (var a in assignedResources) {455 if (resourceDescendants.ContainsKey(a.Id)) {456 foreach (var r in resourceDescendants[a.Id]) {457 includedResources.Add(r);458 newIncludedResources.Add(r);459 }460 }461 }462 }463 464 402 private bool IsAdmin() { 465 403 return HiveRoles.CheckAdminUserPermissions(); -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs
r15813 r15922 54 54 this.btnRemoveGroup = new System.Windows.Forms.Button(); 55 55 this.btnAddGroup = new System.Windows.Forms.Button(); 56 this.treeView = new System.Windows.Forms.TreeView();56 this.treeView = new Hive.Views.TreeView.NoDoubleClickTreeView(); 57 57 this.tabSlaveGroup = new System.Windows.Forms.TabControl(); 58 58 this.tabDetails = new System.Windows.Forms.TabPage(); … … 253 253 private System.Windows.Forms.Button btnRemoveGroup; 254 254 private System.Windows.Forms.Button btnAddGroup; 255 private System.Windows.Forms.TreeView treeView;255 private HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView treeView; 256 256 private System.Windows.Forms.TabControl tabSlaveGroup; 257 257 private System.Windows.Forms.TabPage tabDetails; -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15819 r15922 231 231 }; 232 232 233 HiveAdminClient.Instance.UpdateResourceGenealogy(Content);233 //HiveAdminClient.Instance.UpdateResourceGenealogy(Content); 234 234 SelectedResource = group; 235 235 Content.Add(group); … … 322 322 } 323 323 324 HiveAdminClient.Instance.UpdateResourceGenealogy(Content); 324 // TODO 325 //HiveAdminClient.Instance.UpdateResourceGenealogy(Content); 325 326 OnContentChanged(); 326 327 } … … 486 487 private void CollapseSlaveOnlyNodes(TreeNode tn) { 487 488 Resource r = (Resource)tn.Tag; 488 var descendants = HiveAdminClient.Instance.ResourceDescendants;489 var descendants = GetResourceDescendants(); 489 490 if(descendants.ContainsKey(r.Id)) { 490 491 if(descendants[r.Id].OfType<SlaveGroup>().Any()) { … … 493 494 } else { 494 495 tn.Collapse(); 496 } 497 } 498 } 499 500 private void ExpandResourceNodesOfInterest(TreeNodeCollection nodes) { 501 foreach (TreeNode n in nodes) { 502 Resource r = (Resource)n.Tag; 503 if (n.Nodes.Count > 0) { 504 if (HiveClient.Instance.GetAvailableResourceDescendants(r.Id).OfType<SlaveGroup>().Any()) { 505 n.Expand(); 506 ExpandResourceNodesOfInterest(n.Nodes); 507 } else { 508 n.Collapse(); 509 } 510 } else { 511 n.Collapse(); 495 512 } 496 513 } … … 560 577 int childSlavesCount = 0; 561 578 if (r.Id != Guid.Empty && r is SlaveGroup) { 562 var descendants = HiveAdminClient.Instance.ResourceDescendants;579 var descendants = GetResourceDescendants(); 563 580 if (descendants.ContainsKey(r.Id)) { 564 581 childSlavesCount = resources 565 582 .OfType<Slave>() 566 583 .Where(x => descendants[r.Id].Select(y => y.Id) 567 .Contains(x.Id))584 .Contains(x.Id)) 568 585 .Count(); 569 586 } … … 659 676 } 660 677 678 679 private Dictionary<Guid, HashSet<Resource>> GetResourceDescendants() { 680 var resourceDescendants = new Dictionary<Guid, HashSet<Resource>>(); 681 682 foreach (var r in Content) resourceDescendants.Add(r.Id, new HashSet<Resource>()); 683 foreach(var r in Content) { 684 var parentResourceId = r.ParentResourceId; 685 while(parentResourceId != null) { 686 var parent = Content.SingleOrDefault(x => x.Id == parentResourceId); 687 if(parent != null) { 688 resourceDescendants[parent.Id].Add(r); 689 parentResourceId = parent.ParentResourceId; 690 } else { 691 parentResourceId = null; 692 } 693 } 694 } 695 return resourceDescendants; 696 } 697 661 698 #endregion 662 699 } -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs
r15920 r15922 289 289 if(project.Name.ToLower().Contains(currentSearchString.ToLower())) { 290 290 filteredProjects.Add(project); 291 filteredProjects.UnionWith(Content.Where(p => HiveClient.Instance. ProjectAncestors[project.Id].Contains(p.Id)));291 filteredProjects.UnionWith(Content.Where(p => HiveClient.Instance.GetAvailableProjectAncestors(project.Id).Select(x => x.Id).Contains(p.Id))); 292 292 } 293 293 } … … 448 448 private void UpdateNewAssignedResources() { 449 449 for(int i = newAssignedResources.Count-1; i>=0; i--) { 450 if(newAssignedResources.Intersect(HiveClient.Instance.GetAvailable ParentResources(newAssignedResources.ElementAt(i).Id)).Any()) {450 if(newAssignedResources.Intersect(HiveClient.Instance.GetAvailableResourceAncestors(newAssignedResources.ElementAt(i).Id)).Any()) { 451 451 newAssignedResources.Remove(newAssignedResources.ElementAt(i)); 452 452 } … … 460 460 if (JobId != Guid.Empty) { 461 461 foreach (var item in assignedResources) { 462 foreach (var descendant in HiveClient.Instance.GetAvailable ChildResources(item.Id)) {462 foreach (var descendant in HiveClient.Instance.GetAvailableResourceDescendants(item.Id)) { 463 463 includedResources.Add(descendant); 464 464 } … … 467 467 468 468 foreach (var item in newAssignedResources) { 469 foreach (var descendant in HiveClient.Instance.GetAvailable ChildResources(item.Id)) {469 foreach (var descendant in HiveClient.Instance.GetAvailableResourceDescendants(item.Id)) { 470 470 newIncludedResources.Add(descendant); 471 471 } … … 476 476 newIncludedResources.Clear(); 477 477 foreach (var item in newAssignedResources) { 478 foreach (var descendant in HiveClient.Instance.GetAvailable ChildResources(item.Id)) {478 foreach (var descendant in HiveClient.Instance.GetAvailableResourceDescendants(item.Id)) { 479 479 newIncludedResources.Add(descendant); 480 480 } … … 598 598 Resource r = (Resource)n.Tag; 599 599 if(n.Nodes.Count > 0) { 600 if(HiveClient.Instance.GetAvailable ChildResources(r.Id).OfType<SlaveGroup>().Any()601 || HiveClient.Instance.GetAvailable ChildResources(r.Id).OfType<Slave>().Intersect(assignedResources.Union(newAssignedResources)).Any()) {600 if(HiveClient.Instance.GetAvailableResourceDescendants(r.Id).OfType<SlaveGroup>().Any() 601 || HiveClient.Instance.GetAvailableResourceDescendants(r.Id).OfType<Slave>().Intersect(assignedResources.Union(newAssignedResources)).Any()) { 602 602 n.Expand(); 603 603 ExpandResourceNodesOfInterest(n.Nodes); … … 615 615 616 616 Resource r = (Resource)tn.Tag; 617 if (HiveClient.Instance.ResourceDescendants.ContainsKey(r.Id)) { 618 if (HiveClient.Instance.GetAvailableChildResources(r.Id).OfType<SlaveGroup>().Any()) { 619 tn.Expand(); 620 foreach (TreeNode n in tn.Nodes) CollapseSlaveOnlyNodes(n); 621 } else { 622 tn.Collapse(); 623 } 617 if (HiveClient.Instance.GetAvailableResourceDescendants(r.Id).OfType<SlaveGroup>().Any()) { 618 tn.Expand(); 619 foreach (TreeNode n in tn.Nodes) CollapseSlaveOnlyNodes(n); 620 } else { 621 tn.Collapse(); 624 622 } 625 623 } … … 628 626 HashSet<Slave> newAssignedSlaves = new HashSet<Slave>(newAssignedResources.OfType<Slave>()); 629 627 foreach (var slaveGroup in newAssignedResources.OfType<SlaveGroup>()) { 630 foreach (var slave in HiveClient.Instance.GetAvailable ChildResources(slaveGroup.Id).OfType<Slave>()) {628 foreach (var slave in HiveClient.Instance.GetAvailableResourceDescendants(slaveGroup.Id).OfType<Slave>()) { 631 629 newAssignedSlaves.Add(slave); 632 630 } … … 638 636 var slaveGroup = resource as SlaveGroup; 639 637 if (slaveGroup != null) { 640 selectedSlaves = new HashSet<Slave>(HiveClient.Instance.GetAvailable ChildResources(slaveGroup.Id).OfType<Slave>());638 selectedSlaves = new HashSet<Slave>(HiveClient.Instance.GetAvailableResourceDescendants(slaveGroup.Id).OfType<Slave>()); 641 639 } else { 642 640 selectedSlaves = new HashSet<Slave>(new[] { resource as Slave }); -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Views/3.3/HeuristicLab.Clients.Hive.Views-3.3.csproj
r14125 r15922 169 169 <DependentUpon>StateLogView.cs</DependentUpon> 170 170 </Compile> 171 <Compile Include="TreeView\NoDoubleClickTreeView.cs"> 172 <SubType>Component</SubType> 173 </Compile> 171 174 <None Include="Plugin.cs.frame" /> 172 175 <Compile Include="Plugin.cs" /> -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Views/3.3/TreeView/NoDoubleClickTreeView.cs
r15920 r15922 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 25 25 namespace HeuristicLab.Clients.Hive.Views.TreeView { 26 // Workaround for a well-known bug in TreeView 27 // cf. https://stackoverflow.com/questions/6130297/c-how-to-avoid-treenode-check-from-happening-on-a-double-click-event 26 28 public class NoDoubleClickTreeView : System.Windows.Forms.TreeView { 27 29 protected override void WndProc(ref Message m) { -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15819 r15922 70 70 } 71 71 72 private Dictionary<Guid, HashSet<Project>> projectAncestors; 73 public Dictionary<Guid, HashSet<Project>> ProjectAncestors { 72 //private Dictionary<Guid, HashSet<Project>> projectAncestors; 73 //public Dictionary<Guid, HashSet<Project>> ProjectAncestors { 74 // get { return projectAncestors; } 75 //} 76 77 //private Dictionary<Guid, HashSet<Project>> projectDescendants; 78 //public Dictionary<Guid, HashSet<Project>> ProjectDescendants { 79 // get { return projectDescendants; } 80 //} 81 82 //private Dictionary<Guid, HashSet<Resource>> resourceAncestors; 83 //public Dictionary<Guid, HashSet<Resource>> ResourceAncestors { 84 // get { return resourceAncestors; } 85 //} 86 87 //private Dictionary<Guid, HashSet<Resource>> resourceDescendants; 88 //public Dictionary<Guid, HashSet<Resource>> ResourceDescendants { 89 // get { return resourceDescendants; } 90 //} 91 92 private Dictionary<Guid, HashSet<Guid>> projectAncestors; 93 public Dictionary<Guid, HashSet<Guid>> ProjectAncestors { 74 94 get { return projectAncestors; } 75 95 } 76 96 77 private Dictionary<Guid, HashSet< Project>> projectDescendants;78 public Dictionary<Guid, HashSet< Project>> ProjectDescendants {97 private Dictionary<Guid, HashSet<Guid>> projectDescendants; 98 public Dictionary<Guid, HashSet<Guid>> ProjectDescendants { 79 99 get { return projectDescendants; } 80 100 } 81 101 82 private Dictionary<Guid, HashSet< Resource>> resourceAncestors;83 public Dictionary<Guid, HashSet< Resource>> ResourceAncestors {102 private Dictionary<Guid, HashSet<Guid>> resourceAncestors; 103 public Dictionary<Guid, HashSet<Guid>> ResourceAncestors { 84 104 get { return resourceAncestors; } 85 105 } 86 106 87 private Dictionary<Guid, HashSet< Resource>> resourceDescendants;88 public Dictionary<Guid, HashSet< Resource>> ResourceDescendants {107 private Dictionary<Guid, HashSet<Guid>> resourceDescendants; 108 public Dictionary<Guid, HashSet<Guid>> ResourceDescendants { 89 109 get { return resourceDescendants; } 90 110 } 91 92 93 111 #endregion 94 112 … … 117 135 projectResourceAssignments = new ItemList<AssignedProjectResource>(); 118 136 119 projectAncestors = new Dictionary<Guid, HashSet<Project>>(); 120 projectDescendants = new Dictionary<Guid, HashSet<Project>>(); 121 resourceAncestors = new Dictionary<Guid, HashSet<Resource>>(); 122 resourceDescendants = new Dictionary<Guid, HashSet<Resource>>(); 137 //projectAncestors = new Dictionary<Guid, HashSet<Project>>(); 138 //projectDescendants = new Dictionary<Guid, HashSet<Project>>(); 139 //resourceAncestors = new Dictionary<Guid, HashSet<Resource>>(); 140 //resourceDescendants = new Dictionary<Guid, HashSet<Resource>>(); 141 projectAncestors = new Dictionary<Guid, HashSet<Guid>>(); 142 projectDescendants = new Dictionary<Guid, HashSet<Guid>>(); 143 resourceAncestors = new Dictionary<Guid, HashSet<Guid>>(); 144 resourceDescendants = new Dictionary<Guid, HashSet<Guid>>(); 123 145 124 146 HiveServiceLocator.Instance.CallHiveService(service => { … … 132 154 }); 133 155 134 UpdateResourceGenealogy( resources);135 UpdateProjectGenealogy( projects);156 UpdateResourceGenealogy(); 157 UpdateProjectGenealogy(); 136 158 } 137 159 catch { … … 143 165 } 144 166 145 public void UpdateResourceGenealogy(IItemList<Resource> resources) { 167 //public void UpdateResourceGenealogy(IItemList<Resource> resources) { 168 // resourceAncestors.Clear(); 169 // resourceDescendants.Clear(); 170 171 // foreach (var r in resources) { 172 // resourceAncestors.Add(r.Id, new HashSet<Resource>()); 173 // resourceDescendants.Add(r.Id, new HashSet<Resource>()); 174 // } 175 176 // foreach (var r in resources) { 177 // var parentResourceId = r.ParentResourceId; 178 // while (parentResourceId != null) { 179 // var parent = resources.SingleOrDefault(x => x.Id == parentResourceId); 180 // if (parent != null) { 181 // resourceAncestors[r.Id].Add(parent); 182 // resourceDescendants[parent.Id].Add(r); 183 // parentResourceId = parent.ParentResourceId; 184 // } else { 185 // parentResourceId = null; 186 // } 187 // } 188 // } 189 //} 190 191 //public void UpdateProjectGenealogy(IItemList<Project> projects) { 192 // projectAncestors.Clear(); 193 // projectDescendants.Clear(); 194 195 // foreach (var p in projects) { 196 // projectAncestors.Add(p.Id, new HashSet<Project>()); 197 // projectDescendants.Add(p.Id, new HashSet<Project>()); 198 // } 199 200 // foreach (var p in projects) { 201 // var parentProjectId = p.ParentProjectId; 202 // while (parentProjectId != null) { 203 // var parent = projects.SingleOrDefault(x => x.Id == parentProjectId); 204 // if (parent != null) { 205 // projectAncestors[p.Id].Add(parent); 206 // projectDescendants[parent.Id].Add(p); 207 // parentProjectId = parent.ParentProjectId; 208 // } else { 209 // parentProjectId = null; 210 // } 211 // } 212 // } 213 //} 214 215 private void UpdateResourceGenealogy() { 146 216 resourceAncestors.Clear(); 147 217 resourceDescendants.Clear(); 148 218 149 foreach (var r in resources) { 150 resourceAncestors.Add(r.Id, new HashSet<Resource>()); 151 resourceDescendants.Add(r.Id, new HashSet<Resource>()); 152 } 153 154 foreach (var r in resources) { 155 var parentResourceId = r.ParentResourceId; 156 while (parentResourceId != null) { 157 var parent = resources.SingleOrDefault(x => x.Id == parentResourceId); 158 if (parent != null) { 159 resourceAncestors[r.Id].Add(parent); 160 resourceDescendants[parent.Id].Add(r); 161 parentResourceId = parent.ParentResourceId; 162 } else { 163 parentResourceId = null; 164 } 165 } 166 } 167 } 168 169 public void UpdateProjectGenealogy(IItemList<Project> projects) { 219 // fetch resource ancestor set 220 HiveServiceLocator.Instance.CallHiveService(service => { 221 var ra = service.GetResourceGenealogy(); 222 ra.Keys.ToList().ForEach(k => resourceAncestors.Add(k, new HashSet<Guid>())); 223 resourceAncestors.Keys.ToList().ForEach(k => resourceAncestors[k].UnionWith(ra[k])); 224 }); 225 226 // build resource descendant set 227 resourceAncestors.Keys.ToList().ForEach(k => resourceDescendants.Add(k, new HashSet<Guid>())); 228 foreach (var ra in resourceAncestors) { 229 foreach (var ancestor in ra.Value) { 230 resourceDescendants[ancestor].Add(ra.Key); 231 } 232 } 233 } 234 235 private void UpdateProjectGenealogy() { 170 236 projectAncestors.Clear(); 171 237 projectDescendants.Clear(); 172 238 173 foreach (var p in projects) { 174 projectAncestors.Add(p.Id, new HashSet<Project>()); 175 projectDescendants.Add(p.Id, new HashSet<Project>()); 176 } 177 178 foreach (var p in projects) { 179 var parentProjectId = p.ParentProjectId; 180 while (parentProjectId != null) { 181 var parent = projects.SingleOrDefault(x => x.Id == parentProjectId); 182 if (parent != null) { 183 projectAncestors[p.Id].Add(parent); 184 projectDescendants[parent.Id].Add(p); 185 parentProjectId = parent.ParentProjectId; 186 } else { 187 parentProjectId = null; 188 } 189 } 190 } 191 } 239 // fetch project ancestor list 240 HiveServiceLocator.Instance.CallHiveService(service => { 241 var pa = service.GetProjectGenealogy(); 242 pa.Keys.ToList().ForEach(k => projectAncestors.Add(k, new HashSet<Guid>())); 243 projectAncestors.Keys.ToList().ForEach(k => projectAncestors[k].UnionWith(pa[k])); 244 }); 245 246 // build project descendant list 247 projectAncestors.Keys.ToList().ForEach(k => projectDescendants.Add(k, new HashSet<Guid>())); 248 foreach (var pa in projectAncestors) { 249 foreach (var ancestor in pa.Value) { 250 projectDescendants[ancestor].Add(pa.Key); 251 } 252 } 253 } 254 192 255 #endregion 193 256 … … 268 331 269 332 #region Helper 333 public IEnumerable<Project> GetAvailableProjectAncestors(Guid id) { 334 if (projectAncestors.ContainsKey(id)) return projects.Where(x => projectAncestors[id].Contains(x.Id)); 335 else return Enumerable.Empty<Project>(); 336 } 337 338 public IEnumerable<Project> GetAvailableProjectDescendants(Guid id) { 339 if(projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id)); 340 else return Enumerable.Empty<Project>(); 341 } 342 343 public IEnumerable<Resource> GetAvailableResourceAncestors(Guid id) { 344 if (resourceAncestors.ContainsKey(id)) return resources.Where(x => resourceAncestors[id].Contains(x.Id)); 345 else return Enumerable.Empty<Resource>(); 346 } 347 348 public IEnumerable<Resource> GetAvailableResourceDescendants(Guid id) { 349 if (resourceDescendants.ContainsKey(id)) return resources.Where(x => resourceDescendants[id].Contains(x.Id)); 350 else return Enumerable.Empty<Resource>(); 351 } 352 270 353 public bool CheckAccessToAdminAreaGranted() { 271 354 if(projects != null) { … … 286 369 return true; 287 370 } else if(resourceAncestors.ContainsKey(res.Id)) { 288 return resourceAncestors[res.Id].Where(x => x.OwnerUserId == userId).Any();371 return GetAvailableResourceAncestors(res.Id).Where(x => x.OwnerUserId == userId).Any(); 289 372 } 290 373 … … 298 381 return true; 299 382 } else if (projectAncestors.ContainsKey(pro.Id)) { 300 return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any();383 return GetAvailableProjectAncestors(pro.Id).Where(x => x.OwnerUserId == userId).Any(); 301 384 } 302 385 … … 308 391 309 392 if(projectAncestors.ContainsKey(pro.Id)) { 310 return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any();393 return GetAvailableProjectAncestors(pro.Id).Where(x => x.OwnerUserId == userId).Any(); 311 394 } 312 395 … … 327 410 } else if(parent != null && projectDescendants.ContainsKey(child.Id)) { 328 411 // ... if the new parent is among the moved project's descendants 329 changePossible = ! projectDescendants[child.Id].Where(x => x.Id == parent.Id).Any();412 changePossible = !GetAvailableProjectDescendants(child.Id).Where(x => x.Id == parent.Id).Any(); 330 413 } 331 414 … … 350 433 } else if (parent != null && resourceDescendants.ContainsKey(child.Id)) { 351 434 // ... or if the new parent is among the moved resource's descendants 352 changePossible = ! resourceDescendants[child.Id].Where(x => x.Id == parent.Id).Any();435 changePossible = !GetAvailableResourceDescendants(child.Id).Where(x => x.Id == parent.Id).Any(); 353 436 } 354 437 -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r15913 r15922 239 239 } 240 240 241 public IEnumerable<Project> GetAvailableParentProjects(Guid id) { 242 return projects.Where(x => projectAncestors[id].Contains(x.Id)); 243 } 244 245 public IEnumerable<Project> GetAvailableChildProjects(Guid id) { 246 return projects.Where(x => projectDescendants[id].Contains(x.Id)); 247 } 248 249 public IEnumerable<Resource> GetAvailableParentResources(Guid id) { 250 return resources.Where(x => resourceAncestors[id].Contains(x.Id)); 251 } 252 253 public IEnumerable<Resource> GetAvailableChildResources(Guid id) { 254 return resources.Where(x => resourceDescendants[id].Contains(x.Id)); 255 } 256 241 public IEnumerable<Project> GetAvailableProjectAncestors(Guid id) { 242 if (projectAncestors.ContainsKey(id)) return projects.Where(x => projectAncestors[id].Contains(x.Id)); 243 else return Enumerable.Empty<Project>(); 244 } 245 246 public IEnumerable<Project> GetAvailableProjectDescendants(Guid id) { 247 if (projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id)); 248 else return Enumerable.Empty<Project>(); 249 } 250 251 public IEnumerable<Resource> GetAvailableResourceAncestors(Guid id) { 252 if (resourceAncestors.ContainsKey(id)) return resources.Where(x => resourceAncestors[id].Contains(x.Id)); 253 else return Enumerable.Empty<Resource>(); 254 } 255 256 public IEnumerable<Resource> GetAvailableResourceDescendants(Guid id) { 257 if (resourceDescendants.ContainsKey(id)) return resources.Where(x => resourceDescendants[id].Contains(x.Id)); 258 else return Enumerable.Empty<Resource>(); 259 } 257 260 #endregion 258 261
Note: See TracChangeset
for help on using the changeset viewer.