當前位置: 首頁>>代碼示例>>C#>>正文


C# TreeNode.DescendantNodes方法代碼示例

本文整理匯總了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();
    }
開發者ID:t-h-e,項目名稱:HeuristicLab,代碼行數:59,代碼來源:HiveResourceSelector.cs


注:本文中的System.Windows.Forms.TreeNode.DescendantNodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。