Changeset 15613
- Timestamp:
- 01/15/18 01:53:02 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2877_HiveImprovements/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15583 r15613 48 48 private const int slaveGroupImageIndex = 1; 49 49 private readonly Color ownedResourceColor = Color.LightGreen; 50 private readonly Color calculatingColor = Color.DarkGreen; 51 private readonly Color offlineColor = Color.Red; 50 52 private TS.Task progressTask; 51 53 private bool stopProgressTask; … … 136 138 137 139 //rebuild 138 TreeNode ungrp = new TreeNode(UngroupedGroupName); 139 ungrp.ImageIndex = slaveGroupImageIndex; 140 ungrp.SelectedImageIndex = ungrp.ImageIndex; 141 var newGroup = new SlaveGroup(); 142 newGroup.Name = UngroupedGroupName; 143 newGroup.Id = Guid.NewGuid(); 144 newGroup.Description = "Contains slaves which are in no group"; 145 ungrp.Tag = newGroup; 146 147 foreach (Resource g in Content) { 148 if (g.GetType() == typeof(SlaveGroup)) { 149 //root node 150 if (g.ParentResourceId == null) { 151 TreeNode tn = new TreeNode(); 152 tn.ImageIndex = slaveGroupImageIndex; 153 tn.SelectedImageIndex = tn.ImageIndex; 154 155 tn.Tag = g; 156 tn.Text = g.Name; 157 if (g.OwnerUserId == Access.UserInformation.Instance.User.Id) tn.BackColor = ownedResourceColor; 158 159 BuildSlaveGroupTree(g, tn); 160 treeSlaveGroup.Nodes.Add(tn); 161 } 162 } else if (g.GetType() == typeof(Slave)) { 163 if (g.ParentResourceId == null) { 164 var stn = new TreeNode(g.Name); 165 stn.ImageIndex = slaveImageIndex; 166 stn.SelectedImageIndex = stn.ImageIndex; 167 stn.Tag = g; 168 if (g.OwnerUserId == Access.UserInformation.Instance.User.Id) stn.BackColor = ownedResourceColor; 169 ungrp.Nodes.Add(stn); 170 } 171 } 172 } 173 treeSlaveGroup.Nodes.Add(ungrp); 174 } 175 } 176 177 private void BuildSlaveGroupTree(Resource g, TreeNode tn) { 178 foreach (Resource r in Content.Where(s => s.ParentResourceId != null && s.ParentResourceId == g.Id)) { 179 TreeNode stn = new TreeNode(r.Name); 180 if (r is Slave) { 181 stn.ImageIndex = slaveImageIndex; 182 } else if (r is SlaveGroup) { 183 stn.ImageIndex = slaveGroupImageIndex; 184 } 185 stn.SelectedImageIndex = stn.ImageIndex; 186 stn.Tag = r; 187 if (r.OwnerUserId == Access.UserInformation.Instance.User.Id) stn.BackColor = ownedResourceColor; 188 tn.Nodes.Add(stn); 189 190 BuildSlaveGroupTree(r, stn); 191 } 140 var ungroupedSlaves = new SlaveGroup { 141 Id = Guid.NewGuid(), 142 Name = UngroupedGroupName, 143 Description = "Slaves without a group" 144 }; 145 var ungroupedSlavesCount = 0; 146 var ungroupedNode = CreateTreeNodeFromResource(ungroupedSlaves); 147 148 var parentlessResources = from r in Content 149 where r.ParentResourceId == null 150 orderby r.Name 151 select r; 152 foreach (Resource r in parentlessResources) { 153 if (r.GetType() == typeof(SlaveGroup)) { // root node 154 var root = CreateTreeNodeFromResource(r); 155 treeSlaveGroup.Nodes.Add(root); 156 BuildSlaveGroupTree((SlaveGroup)r, root); 157 } else if (r.GetType() == typeof(Slave)) { // ungrouped slaves 158 ungroupedNode.Nodes.Add(CreateTreeNodeFromResource(r)); 159 ungroupedSlavesCount++; 160 } 161 } 162 if (ungroupedSlavesCount > 0) 163 ungroupedNode.Text += " [" + ungroupedSlavesCount.ToString() + "]"; 164 treeSlaveGroup.Nodes.Add(ungroupedNode); 165 } 166 } 167 168 private void BuildSlaveGroupTree(SlaveGroup group, TreeNode node) { 169 var childGroups = from r in Content.OfType<SlaveGroup>() 170 where r.ParentResourceId == @group.Id 171 orderby r.Name 172 select r; 173 foreach (var g in childGroups) { 174 var childNode = CreateTreeNodeFromResource(g); 175 node.Nodes.Add(childNode); 176 BuildSlaveGroupTree(g, childNode); 177 } 178 179 var childSlaves = from r in Content.OfType<Slave>() 180 where r.ParentResourceId == @group.Id 181 orderby r.Name 182 select r; 183 foreach (var s in childSlaves) 184 node.Nodes.Add(CreateTreeNodeFromResource(s)); 185 var childSlavesCount = childSlaves.Count(); 186 if (childSlavesCount > 0) 187 node.Text += " [" + childSlavesCount.ToString() + "]"; 188 } 189 190 private TreeNode CreateTreeNodeFromResource(Resource r) { 191 var node = new TreeNode(); 192 node.Text = r.Name; 193 194 if (r is SlaveGroup) { 195 node.ImageIndex = slaveGroupImageIndex; 196 } else if (r is Slave) { 197 var s = r as Slave; 198 node.ImageIndex = slaveImageIndex; 199 if (s.SlaveState == SlaveState.Calculating) { 200 node.ForeColor = calculatingColor; 201 node.Text += " [" + s.CpuUtilization.ToString("N2") + " %]"; 202 } else if (s.SlaveState == SlaveState.Offline) { 203 node.ForeColor = offlineColor; 204 if (s.LastHeartbeat.HasValue) 205 node.Text += " [" + s.LastHeartbeat?.ToString("g") + "]"; 206 } 207 } 208 node.SelectedImageIndex = node.ImageIndex; 209 210 if (r.OwnerUserId == Access.UserInformation.Instance.User.Id) node.BackColor = ownedResourceColor; 211 212 node.Tag = r; 213 return node; 192 214 } 193 215
Note: See TracChangeset
for help on using the changeset viewer.