public SysInfoResult Retrieve(SysInfoQuery sysInfoQuery)
        {
            _sysInfoQuery    = sysInfoQuery;
            _sysInfoSearcher = new ManagementObjectSearcher(string.Format("SELECT * FROM {0}", _sysInfoQuery.QueryText));
            _sysInfoResult   = new SysInfoResult(_sysInfoQuery.Name);

            foreach (ManagementObject managementObject in _sysInfoSearcher.Get())
            {
                _sysInfoResult.AddNode(managementObject.GetPropertyValue(_sysInfoQuery.DisplayField).ToString().Trim());
                _sysInfoResult.AddChildren(GetChildren(managementObject));
            }
            return(_sysInfoResult);
        }
Пример #2
0
        public static void AddTreeViewNode(TreeNode parentNode, SysInfoResult result)
        {
            var nodeRoot = new TreeNode(result.Name);

            foreach (var nodeValueParent in result.Nodes)
            {
                var nodeLeaf = new TreeNode(nodeValueParent);
                nodeRoot.Nodes.Add(nodeLeaf);

                foreach (var childResult in result.ChildResults)
                {
                    foreach (var nodeValue in childResult.Nodes)
                    {
                        nodeLeaf.Nodes.Add(new TreeNode(nodeValue));
                    }
                }
            }
            parentNode.Nodes.Add(nodeRoot);
        }
        private IEnumerable <SysInfoResult> GetChildren(ManagementBaseObject managementObject)
        {
            SysInfoResult childResult             = null;
            ICollection <SysInfoResult> childList = new List <SysInfoResult>();

            foreach (var propertyData in managementObject.Properties)
            {
                if (childResult == null)
                {
                    childResult = new SysInfoResult(_sysInfoQuery.Name + "_Child");
                    childList.Add(childResult);
                }

                var nodeValue = string.Format("{0} = {1}", propertyData.Name, Convert.ToString(propertyData.Value));
                childResult.Nodes.Add(nodeValue);
            }

            return(childList);
        }