示例#1
0
        public void GetValues(string compName)
        {
            ComputerDescription cd = new ComputerDescription()
            {
                Name = compName
            };

            try{
                foreach (string query in this.QueryStrings)
                {
                    string winClass = string.Empty;

                    ObjectQuery oq = new ObjectQuery(query);
                    Regex       r  = new Regex(@"from ([\w\d_]+)");
                    winClass = r.Match(query).Groups[1].Value;

                    ManagementScope ms = new ManagementScope("\\\\" + compName + "\\root\\cimv2", _connectionOpts);

                    ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq);

                    ManagementObjectCollection data = mos.Get();

                    List <Dictionary <string, string> > l = new List <Dictionary <string, string> >();
                    foreach (ManagementObject obj in data)
                    {
                        Dictionary <string, string> dict = new Dictionary <string, string>();
                        foreach (PropertyData pd in obj.Properties)
                        {
                            if (pd.Value == null)
                            {
                                dict[pd.Name] = string.Empty;
                            }
                            else if (pd.Value is IEnumerable)
                            {
                                dict[pd.Name] = String.Join("  ", pd.Value);
                            }
                            else
                            {
                                dict[pd.Name] = pd.Value.ToString();
                            }
                        }
                        l.Add(dict);
                    }
                    cd.Values[winClass] = l;
                }
                ComputerDescription[compName] = cd;
            }
            catch (Exception ex)
            {
                cd.Exception = ex;
                ComputerDescription[compName] = cd;
            }
        }
示例#2
0
        //при нажатии на элемент списка компьютеров отображать детальную информацию о компьютере
        void ListView2SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_mfp.isRunning == true || listView2.SelectedItems.Count == 0)
            {
                return;
            }

            listView1.Items.Clear();
            if (_mfp.isRunning == false && listView2.SelectedItems != null && GetDetailComputerInfo != null)
            {
                ComputerDescription cd = GetDetailComputerInfo(listView2.SelectedItems[0].Text);

                if (cd == null)
                {
                    return;
                }


                if (cd.Values.Count() == 0 && cd.Exception != null)
                {
                    listView1.Items.Add(cd.Exception.Message);
                    return;
                }


                foreach (KeyValuePair <string, List <Dictionary <string, string> > > item in cd.Values)
                {
                    string textVal = GetTextValFromResource(item.Key);

                    listView1.Items.Add(new ListViewItem()
                    {
                        Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold), Text = textVal, ForeColor = Color.Green
                    });
                    listView1.Items.Add(string.Empty);

                    foreach (Dictionary <string, string> item1 in item.Value)
                    {
                        foreach (KeyValuePair <string, string> item2 in item1)
                        {
                            ListViewItem lvi = new ListViewItem(GetTextValFromResource(item2.Key));

                            textVal = NumberFormatHelper.Format(item2.Key, item2.Value);
                            lvi.SubItems.Add(textVal);
                            listView1.Items.Add(lvi);
                        }
                        listView1.Items.Add(string.Empty);
                    }
                }
            }
        }
示例#3
0
        ComputerDescription _mf_GetDetailComputerInfo(string compName)
        {
            ComputerDescription cd = _cDescriptions.Where((e) => e.Key == compName).Select((e) => e.Value).FirstOrDefault();

            return(cd);
        }