本文整理汇总了C#中System.Windows.Forms.TreeNode.DescendantNodes方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.DescendantNodes方法的具体用法?C# TreeNode.DescendantNodes怎么用?C# TreeNode.DescendantNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TreeNode
的用法示例。
在下文中一共展示了TreeNode.DescendantNodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractStatistics
private void ExtractStatistics(TreeNode treeNode = null) {
StringBuilder sb = new StringBuilder();
Resource resource = treeNode == null ? null : treeNode.Tag as Resource;
ISet<Resource> resources = treeNode == null ? selectedResources : new HashSet<Resource>(treeNode.DescendantNodes().Select(x => x.Tag as Resource)); ;
IEnumerable<SlaveGroup> slaveGroups = resources.OfType<SlaveGroup>();
IEnumerable<Slave> slaves = resources.OfType<Slave>();
int cpuSpeed = 0, cores = 0, freeCores = 0, memory = 0, freeMemory = 0;
string contextString = treeNode == null ? "Selected" : "Included";
if (resources.Any() || resource != null) {
foreach (Slave s in slaves) {
cpuSpeed += s.CpuSpeed.GetValueOrDefault();
cores += s.Cores.GetValueOrDefault();
freeCores += s.FreeCores.GetValueOrDefault();
memory += s.Memory.GetValueOrDefault();
freeMemory += s.FreeMemory.GetValueOrDefault();
}
if (resource != null) {
if (resource is SlaveGroup) sb.Append("Slave group: ");
else if (resource is Slave) {
sb.Append("Slave: ");
if (!resources.Any()) {
Slave s = resource as Slave;
cpuSpeed = s.CpuSpeed.GetValueOrDefault();
cores = s.Cores.GetValueOrDefault();
freeCores = s.FreeCores.GetValueOrDefault();
memory = s.Memory.GetValueOrDefault();
freeMemory = s.FreeMemory.GetValueOrDefault();
}
}
sb.AppendLine(string.Format("{0}", resource.Name));
}
if (resource == null || resource is SlaveGroup) {
if (resources.Any()) {
sb.AppendFormat("{0} slave groups ({1}): ", contextString, slaveGroups.Count());
foreach (SlaveGroup sg in slaveGroups) sb.AppendFormat("{0}; ", sg.Name);
sb.AppendLine();
sb.AppendFormat("{0} slaves ({1}): ", contextString, slaves.Count());
foreach (Slave s in slaves) sb.AppendFormat("{0}; ", s.Name);
sb.AppendLine();
} else {
sb.Append("The selection does not inlcude any further resources.");
}
}
sb.AppendLine();
sb.AppendLine(string.Format("CPU speed: {0} MHz", cpuSpeed));
if (resources.Any()) sb.AppendLine(string.Format("Avg. CPU speed: {0:0.00} MHz", (double)cpuSpeed / resources.Count()));
sb.AppendLine(string.Format("Cores: {0}", cores));
sb.AppendLine(string.Format("Free cores: {0}", freeCores));
if (resources.Any()) sb.AppendLine(string.Format("Avg. free cores: {0:0.00}", (double)freeCores / resources.Count()));
sb.AppendLine(string.Format("Memory: {0} MB", memory));
sb.AppendFormat("Free memory: {0} MB", freeMemory);
if (resources.Any()) sb.Append(string.Format("{0}Avg. free memory: {1:0.00} MB", Environment.NewLine, (double)freeMemory / resources.Count()));
} else {
sb.Append("No resources selected.");
}
descriptionTextBox.Text = sb.ToString();
}