- Timestamp:
- 04/26/18 16:33:53 (6 years ago)
- Location:
- branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.