Changeset 15922


Ignore:
Timestamp:
04/26/18 16:33:53 (15 months ago)
Author:
jzenisek
Message:

#2839:

  • replaced use of TreeView with NoDoubleClickTreeView everywhere allegedly reasonable for Hive
  • updated genealogy computation for HiveAdminClient and corresponding views (ResourcesView & ProjectResourcesView)
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  
    3131      this.splitContainer = new System.Windows.Forms.SplitContainer();
    3232      this.permissionsGroupBox = new System.Windows.Forms.GroupBox();
    33       this.treeView = new System.Windows.Forms.TreeView();
     33      this.treeView = new Hive.Views.TreeView.NoDoubleClickTreeView();
    3434      this.detailsGroupBox = new System.Windows.Forms.GroupBox();
    3535      this.detailsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     
    184184    private System.Windows.Forms.SplitContainer splitContainer;
    185185    private System.Windows.Forms.GroupBox permissionsGroupBox;
    186     private System.Windows.Forms.TreeView treeView;
     186    private HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView treeView;
    187187    private System.Windows.Forms.GroupBox detailsGroupBox;
    188188    private MainForm.WindowsForms.ViewHost detailsViewHost;
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.Designer.cs

    r15576 r15922  
    3030      this.splitContainer = new System.Windows.Forms.SplitContainer();
    3131      this.resourcesGroupBox = new System.Windows.Forms.GroupBox();
    32       this.treeView = new System.Windows.Forms.TreeView();
     32      this.treeView = new Hive.Views.TreeView.NoDoubleClickTreeView();
    3333      this.imageList = new System.Windows.Forms.ImageList(this.components);
    3434      this.detailsGroupBox = new System.Windows.Forms.GroupBox();
     
    185185    private System.Windows.Forms.GroupBox resourcesGroupBox;
    186186    private System.Windows.Forms.GroupBox detailsGroupBox;
    187     private System.Windows.Forms.TreeView treeView;
     187    private HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView treeView;
    188188    private System.Windows.Forms.ImageList imageList;
    189189    private MainForm.WindowsForms.ViewHost detailsViewHost;
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs

    r15819 r15922  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5151    private readonly HashSet<Resource> newIncludedResources = new HashSet<Resource>();
    5252
    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 
    5853    private readonly Color addedAssignmentColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1
    5954    private readonly Color removedAssignmentColor = Color.FromArgb(255, 236, 159, 72); // #ec9f48
     
    8378        newAssignedResources.Clear();
    8479        includedResources.Clear();
    85         resourceAncestors.Clear();
    8680        treeView.Nodes.Clear();
    8781        detailsViewHost.Content = null;
    8882      } else {
    89         UpdateProjectGenealogy();
    9083        UpdateAssignedResources();
    91         UpdateResourceGenealogy();
     84        UpdateIncludedResources();
    9285        var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
    9386        detailsViewHost.Content = top;
     
    111104
    112105    private void refreshButton_Click(object sender, EventArgs e) {
    113       UpdateProjectGenealogy();
     106      HiveAdminClient.Instance.Refresh();
    114107      UpdateAssignedResources();
    115       UpdateResourceGenealogy();
     108      UpdateIncludedResources();
    116109      var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
    117110      detailsViewHost.Content = top;
     
    144137        e.Cancel = true;
    145138      } else if (!HiveRoles.CheckAdminUserPermissions()) {
    146           if (!projectAncestors[Content.Id].Any() || projectExclusiveResources.Contains(checkedResource)) {
     139          if (!HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).Any() || projectExclusiveResources.Contains(checkedResource)) {
    147140            e.Cancel = true;
    148141          }
     
    166159    private void UpdateResourceTree() {
    167160      UpdateAssignedResources();
    168       UpdateResourceGenealogy();
     161      UpdateIncludedResources();
     162
    169163      var top = BuildResourceTree(HiveAdminClient.Instance.Resources);
    170164      detailsViewHost.Content = top;
     
    194188      // look up for assignments of ancestor projects
    195189      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
    199192      var ancestorProjectResources = resources.Where(x =>
    200193        HiveAdminClient.Instance.ProjectResourceAssignments
     
    206199      HashSet<Resource> availableResources = new HashSet<Resource>(ancestorProjectResources);
    207200      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);
    212203        }
    213204      }
     
    222213      if (projectExclusiveResources.Any()) {
    223214        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          } 
    229218        }
    230219      }
     
    251240    private void UpdateNewAssignedResources() {
    252241      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()) {
    254243          newAssignedResources.Remove(newAssignedResources.ElementAt(i));
    255244        }
     
    266255    }
    267256
     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
    268268    private void UpdateNewIncludedResources() {
    269269      newIncludedResources.Clear();
    270270      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);
    275273        }
    276274      }
     
    325323          newNode.Checked = true;
    326324          if(!HiveRoles.CheckAdminUserPermissions()) {
    327             if(!projectAncestors[Content.Id].Any() || projectExclusiveResources.Contains(newResource)) {
     325            if (!HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).Any()
     326              || projectExclusiveResources.Contains(newResource)) {
    328327              newNode.ForeColor = SystemColors.GrayText;
    329328              newNode.Text += IMMUTABLE_TAG;
     
    401400    }
    402401
    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 
    464402    private bool IsAdmin() {
    465403      return HiveRoles.CheckAdminUserPermissions();
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs

    r15813 r15922  
    5454      this.btnRemoveGroup = new System.Windows.Forms.Button();
    5555      this.btnAddGroup = new System.Windows.Forms.Button();
    56       this.treeView = new System.Windows.Forms.TreeView();
     56      this.treeView = new Hive.Views.TreeView.NoDoubleClickTreeView();
    5757      this.tabSlaveGroup = new System.Windows.Forms.TabControl();
    5858      this.tabDetails = new System.Windows.Forms.TabPage();
     
    253253    private System.Windows.Forms.Button btnRemoveGroup;
    254254    private System.Windows.Forms.Button btnAddGroup;
    255     private System.Windows.Forms.TreeView treeView;
     255    private HeuristicLab.Clients.Hive.Views.TreeView.NoDoubleClickTreeView treeView;
    256256    private System.Windows.Forms.TabControl tabSlaveGroup;
    257257    private System.Windows.Forms.TabPage tabDetails;
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r15819 r15922  
    231231      };
    232232
    233       HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
     233      //HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
    234234      SelectedResource = group;
    235235      Content.Add(group);
     
    322322      }
    323323
    324       HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
     324      // TODO
     325      //HiveAdminClient.Instance.UpdateResourceGenealogy(Content);
    325326      OnContentChanged();
    326327    }
     
    486487    private void CollapseSlaveOnlyNodes(TreeNode tn) {
    487488      Resource r = (Resource)tn.Tag;
    488       var descendants = HiveAdminClient.Instance.ResourceDescendants;
     489      var descendants = GetResourceDescendants();
    489490      if(descendants.ContainsKey(r.Id)) {
    490491        if(descendants[r.Id].OfType<SlaveGroup>().Any()) {
     
    493494        } else {
    494495          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();
    495512        }
    496513      }
     
    560577      int childSlavesCount = 0;
    561578      if (r.Id != Guid.Empty && r is SlaveGroup) {
    562         var descendants = HiveAdminClient.Instance.ResourceDescendants;
     579        var descendants = GetResourceDescendants();
    563580        if (descendants.ContainsKey(r.Id)) {
    564581          childSlavesCount = resources
    565582            .OfType<Slave>()
    566583            .Where(x => descendants[r.Id].Select(y => y.Id)
    567             .Contains(x.Id))
     584              .Contains(x.Id))
    568585            .Count();
    569586        }
     
    659676    }
    660677
     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   
    661698    #endregion
    662699  }
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs

    r15920 r15922  
    289289          if(project.Name.ToLower().Contains(currentSearchString.ToLower())) {
    290290            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)));
    292292          }
    293293        }
     
    448448    private void UpdateNewAssignedResources() {
    449449      for(int i = newAssignedResources.Count-1; i>=0; i--) {
    450         if(newAssignedResources.Intersect(HiveClient.Instance.GetAvailableParentResources(newAssignedResources.ElementAt(i).Id)).Any()) {
     450        if(newAssignedResources.Intersect(HiveClient.Instance.GetAvailableResourceAncestors(newAssignedResources.ElementAt(i).Id)).Any()) {
    451451          newAssignedResources.Remove(newAssignedResources.ElementAt(i));
    452452        }
     
    460460      if (JobId != Guid.Empty) {
    461461        foreach (var item in assignedResources) {
    462           foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) {
     462          foreach (var descendant in HiveClient.Instance.GetAvailableResourceDescendants(item.Id)) {
    463463            includedResources.Add(descendant);
    464464          }
     
    467467
    468468      foreach (var item in newAssignedResources) {
    469         foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) {
     469        foreach (var descendant in HiveClient.Instance.GetAvailableResourceDescendants(item.Id)) {
    470470          newIncludedResources.Add(descendant);
    471471        }
     
    476476      newIncludedResources.Clear();
    477477      foreach (var item in newAssignedResources) {
    478         foreach (var descendant in HiveClient.Instance.GetAvailableChildResources(item.Id)) {
     478        foreach (var descendant in HiveClient.Instance.GetAvailableResourceDescendants(item.Id)) {
    479479          newIncludedResources.Add(descendant);
    480480        }
     
    598598        Resource r = (Resource)n.Tag;
    599599        if(n.Nodes.Count > 0) {
    600           if(HiveClient.Instance.GetAvailableChildResources(r.Id).OfType<SlaveGroup>().Any()
    601             || HiveClient.Instance.GetAvailableChildResources(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()) {
    602602            n.Expand();
    603603            ExpandResourceNodesOfInterest(n.Nodes);
     
    615615
    616616      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();
    624622      }
    625623    }
     
    628626      HashSet<Slave> newAssignedSlaves = new HashSet<Slave>(newAssignedResources.OfType<Slave>());
    629627      foreach (var slaveGroup in newAssignedResources.OfType<SlaveGroup>()) {
    630         foreach (var slave in HiveClient.Instance.GetAvailableChildResources(slaveGroup.Id).OfType<Slave>()) {
     628        foreach (var slave in HiveClient.Instance.GetAvailableResourceDescendants(slaveGroup.Id).OfType<Slave>()) {
    631629          newAssignedSlaves.Add(slave);
    632630        }
     
    638636        var slaveGroup = resource as SlaveGroup;
    639637        if (slaveGroup != null) {
    640           selectedSlaves = new HashSet<Slave>(HiveClient.Instance.GetAvailableChildResources(slaveGroup.Id).OfType<Slave>());
     638          selectedSlaves = new HashSet<Slave>(HiveClient.Instance.GetAvailableResourceDescendants(slaveGroup.Id).OfType<Slave>());
    641639        } else {
    642640          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  
    169169      <DependentUpon>StateLogView.cs</DependentUpon>
    170170    </Compile>
     171    <Compile Include="TreeView\NoDoubleClickTreeView.cs">
     172      <SubType>Component</SubType>
     173    </Compile>
    171174    <None Include="Plugin.cs.frame" />
    172175    <Compile Include="Plugin.cs" />
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Views/3.3/TreeView/NoDoubleClickTreeView.cs

    r15920 r15922  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424
    2525namespace 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
    2628  public class NoDoubleClickTreeView : System.Windows.Forms.TreeView {
    2729    protected override void WndProc(ref Message m) {
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r15819 r15922  
    7070    }
    7171
    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 {
    7494      get { return projectAncestors; }
    7595    }
    7696
    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 {
    7999      get { return projectDescendants; }
    80100    }
    81101
    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 {
    84104      get { return resourceAncestors; }
    85105    }
    86106
    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 {
    89109      get { return resourceDescendants; }
    90110    }
    91 
    92 
    93111    #endregion
    94112
     
    117135        projectResourceAssignments = new ItemList<AssignedProjectResource>();
    118136
    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>>();
    123145
    124146        HiveServiceLocator.Instance.CallHiveService(service => {
     
    132154        });
    133155
    134         UpdateResourceGenealogy(resources);
    135         UpdateProjectGenealogy(projects);
     156        UpdateResourceGenealogy();
     157        UpdateProjectGenealogy();
    136158      }
    137159      catch {
     
    143165    }
    144166
    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() {
    146216      resourceAncestors.Clear();
    147217      resourceDescendants.Clear();
    148218
    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() {
    170236      projectAncestors.Clear();
    171237      projectDescendants.Clear();
    172238
    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
    192255    #endregion
    193256
     
    268331
    269332    #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
    270353    public bool CheckAccessToAdminAreaGranted() {
    271354      if(projects != null) {
     
    286369        return true;
    287370      } 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();
    289372      }
    290373
     
    298381        return true;
    299382      } 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();
    301384      }
    302385
     
    308391
    309392      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();
    311394      }
    312395
     
    327410      } else if(parent != null && projectDescendants.ContainsKey(child.Id)) {
    328411        // ... 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();
    330413      }
    331414
     
    350433      } else if (parent != null && resourceDescendants.ContainsKey(child.Id)) {
    351434        // ... 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();
    353436      }
    354437
  • branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r15913 r15922  
    239239    }
    240240
    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    }
    257260    #endregion
    258261
Note: See TracChangeset for help on using the changeset viewer.