public void EnumerateClassesTest()
        {
            try
            {
                CimClassList list = client.EnumerateClasses();
                Console.WriteLine(list.Count);

                EnumerateClassesOpSettings op = new EnumerateClassesOpSettings();
                op.LocalOnly = false;

                CimClassList l2 = client.EnumerateClasses(op);
                Console.WriteLine(l2.Count);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        public void EnumerateClassesTest2()
        {
            Assert.IsNotNull(client);
            try
            {

                EnumerateClassesOpSettings op = new EnumerateClassesOpSettings();
                op.LocalOnly = false;
                op.DeepInheritance = true;

                CimClassList list = client.EnumerateClasses(op);

                Console.WriteLine(list.Count);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
Exemple #3
0
        private bool Login()
        {
            if (uxChkBx_UseCustomPort.Checked)
            {
                mainWbemClient = new WbemClient(uxTxtBox_Hostname.Text, (int)uxNumUpDn_Port.Value,
                                                uxTxtBox_Username.Text, uxTxtBox_Password.Text,
                                                uxTxtBox_Namespace.Text);
            }
            else
            {
                mainWbemClient = new WbemClient(uxTxtBox_Hostname.Text, uxTxtBox_Username.Text,
                                                uxTxtBox_Password.Text, uxTxtBox_Namespace.Text);
            }

            mainWbemClient.IsSecure = uxChkBx_UseSSL.Checked;

            try
            {
                // Login and get the data
                //classList = mainWbemClient.EnumerateClassHierarchy();

                CimName className = null;

                EnumerateClassesOpSettings ec = new EnumerateClassesOpSettings(className);
                ec.DeepInheritance = true;
                ec.IncludeClassOrigin = false;
                ec.IncludeQualifiers = false;
                ec.LocalOnly = true;

                CimClassList classList2 = mainWbemClient.EnumerateClasses(ec);
                Dictionary<CimName, CimTreeNode> TreeDictionary = new Dictionary<CimName, CimTreeNode>();

                if (className == null)
                {
                    className = mainWbemClient.DefaultNamespace;
                }

                TreeDictionary.Add(className, new CimTreeNode(className));
                classList = TreeDictionary[className];

                //int cnt = 0;
                //string newClassName = "";

                for (int i = 0; i < classList2.Count; i++)
                {

                    String CurClassName = classList2[i].ClassName.ToString();

                    //if (CurClassName != "CIM_Fan" && CurClassName != "CIM_PowerSupply")
                    if (CurClassName == "CIM_Fan" ||
                        CurClassName == "CIM_PowerSupply" ||
                        CurClassName == "CIM_Processor" ||
                        CurClassName == "CIM_NumericSensor" ||
                        CurClassName == "CIM_NetworkPort")
                    {

                        ec = new EnumerateClassesOpSettings(CurClassName);
                        ec.DeepInheritance = true;
                        ec.IncludeClassOrigin = false;
                        ec.IncludeQualifiers = false;
                        ec.LocalOnly = true;

                        CimClassList classList3 = mainWbemClient.EnumerateClasses(ec);

                        CimClass curClass = classList2[i];
                        CimClass Class1 = mainWbemClient.GetClass(curClass.ClassName);
                        Wbem.CimTreeNode Node1 = new CimTreeNode(Class1.ClassName); //mainWbemClient.EnumerateClassHierarchy(Class1.ClassName);

                        //for (int j = 0; j < classList3.Count; j++)
                        //{
                        CimClass curClass2 = classList3[0];
                        CimClass Class2 = mainWbemClient.GetClass(curClass2.ClassName);
                        //Wbem.CimTreeNode Node2 = mainWbemClient.EnumerateClassHierarchy(Class2.ClassName);
                        //Dictionary<CimName, CimTreeNode> TreeDictionary2 = new Dictionary<CimName, CimTreeNode>();
                        //TreeDictionary2.Add(Class2.ClassName, new CimTreeNode(Class2.ClassName));
                        Wbem.CimTreeNode Node2 = new CimTreeNode(Class2.ClassName); //TreeDictionary2[Class2.ClassName];
                        //Node2.Name = Class2.ClassName;

                        // get the instances
                        Wbem.CimInstanceList ChildrenList = mainWbemClient.EnumerateInstances(curClass2.ClassName);
                        for (int k = 0; k < ChildrenList.Count; k++)
                        {
                            CimInstance CurInstance = ChildrenList[k];
                            CimInstance Instance1 = mainWbemClient.GetInstance(CurInstance.InstanceName);
                            Wbem.CimTreeNode Node3 = new CimTreeNode(CurInstance.Properties["Caption"].Value);
                            Node2.Children.Add(Node3);
                        }

                        Node1.Children.Add(Node2);
                        //    String CurClassName2 = classList3[j].ClassName.ToString();
                        //    EnumerateClassesOpSettings ec2 = new EnumerateClassesOpSettings(CurClassName);
                        //    ec2.DeepInheritance = true;
                        //    ec2.IncludeClassOrigin = false;
                        //    ec2.IncludeQualifiers = false;
                        //    ec2.LocalOnly = true;
                        //    CimClassList classList4 = mainWbemClient.EnumerateClasses(ec2);

                        //    for (int k = 0; k < classList4.Count; k++)
                        //    {
                        //        CimClass curClass3 = classList4[k];
                        //        CimClass Class3 = mainWbemClient.GetClass(curClass3.ClassName);
                        //        Wbem.CimTreeNode Node3 = mainWbemClient.EnumerateClassHierarchy(Class3.ClassName);
                        //        Node2.Children.Add(Node3);
                        //    }

                        //}

                        classList.Children.Add(Node1);
                    }

                    //cnt += 1;
                    //newClassName = cnt.ToString() + "_" + curClass.ClassName;

                    //CimTreeNode curNode = new CimTreeNode(newClassName);

                    //hash.Add(newClassName, curNode);

                    //if (curClass.SuperClass != string.Empty)
                    //{
                    //    if (!hash.ContainsKey(curClass.SuperClass))
                    //    {
                    //        hash.Add(curClass.SuperClass, new CimTreeNode(curClass.SuperClass));
                    //    }
                    //    hash[curClass.SuperClass].Children.Add(curNode);
                    //}
                    //else
                    //{
                    //    hash[className].Children.Add(curNode);
                    //}
                }

                //CimClass Class1 = mainWbemClient.GetClass("CIM_Fan");
                //Wbem.CimTreeNode Node1 = mainWbemClient.EnumerateClassHierarchy(Class1.ClassName);
                //classList.Children.Add(Node1);

                //CimClass Class2 = mainWbemClient.GetClass("OMC_Fan");
                //Wbem.CimTreeNode Node2 = mainWbemClient.EnumerateClassHierarchy(Class2.ClassName);

                ////Class1 = mainWbemClient.GetClass("Fan 6");
                //Wbem.CimInstanceList ChildrenList = mainWbemClient.EnumerateInstances(Class1.ClassName);
                ////classList.Children.Add(Node1);
                ////Wbem.CimTreeNodeList
                //for (int i=0; i < ChildrenList.Count; ++i)
                //{
                //    Wbem.CimTreeNode Item = new Wbem.CimTreeNode();
                //    //Wbem.CimInstanceName
                //    Item.Name = ChildrenList[i].ClassName;
                //    Node2.Children[0].Children.Add(Item);
                //}
                ////for each item in ChildrenList ChildrenList[i];
                ////{
                ////Wbem.CimTreeNodeList
                ////}

                ////Node2.Children[0].Children.Add()

                //classList.Children.Add(Node2);

                //mainWbemClient.Login();
                return true;
            }
            catch (Exception ex)
            {
                mainWbemClient = null;
                MessageBox.Show(ex.Message, "Invalid login");
                return false;
            }
        }
Exemple #4
0
        public CimTreeNode EnumerateClassHierarchyChildren(CimName className)
        {
            EnumerateClassesOpSettings ec = new EnumerateClassesOpSettings(className);
            ec.DeepInheritance = true;
            ec.IncludeClassOrigin = false;
            ec.IncludeQualifiers = false;
            ec.LocalOnly = true;

            CimClassList classList = EnumerateClasses(ec);
            Dictionary<CimName, CimTreeNode> hash = new Dictionary<CimName, CimTreeNode>();

            if (className == null)
            {
                className = this.DefaultNamespace;
            }

            hash.Add(className, new CimTreeNode(className));

            int cnt = 0;
            string newClassName = "";

            for (int i = 0; i < classList.Count; i++)
            {
                CimClass curClass = classList[i];

                cnt += 1;
                newClassName = cnt.ToString() + "_" + curClass.ClassName;

                CimTreeNode curNode = new CimTreeNode(newClassName);

                hash.Add(newClassName, curNode);

                if (curClass.SuperClass != string.Empty)
                {
                    if (!hash.ContainsKey(curClass.SuperClass))
                    {
                        hash.Add(curClass.SuperClass, new CimTreeNode(curClass.SuperClass));
                    }
                    hash[curClass.SuperClass].Children.Add(curNode);
                }
                else
                {
                    hash[className].Children.Add(curNode);
                }
            }

            return hash[className];
        }
Exemple #5
0
        public CimClassList EnumerateClasses(EnumerateClassesOpSettings settings)
        {
            SingleResponse response = MakeSingleRequest("EnumerateClasses", settings);

            if (response.Value == null)
            {
                return new CimClassList();  // return an empty list
            }

            CheckSingleResponse(response, typeof(CimClassList));

            return (CimClassList)response.Value;
        }
Exemple #6
0
        public void EnumerateClasses(EnumerateClassesOpSettings settings, CimDataTypeHandler callBack)
        {
            ParseResponse pr = new ParseResponse();
            string opXml = Wbem.CimXml.CreateRequest.ToXml(settings, this.DefaultNamespace);
            string respXml = ExecuteRequest("EnumerateClasses", opXml);

            pr.ParseXml(respXml, callBack);
        }