Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Referencing WMI Manageable class from another WMI Class

$
0
0

Hi,

 

I am trying to have WMI manageable class referring to another WMI manageable class

 

Something like

 

[ManagementEntity]

Class A

{

}

 

[ManagementEntity]

Class B

{

        [ManagementReference(Type = "A")]
        [ManagementProbe]
        public A AClass;

 

}

 

When trying to install the class, I am getting “Type unsupported”

 

I tried the MicrosoftManagementReference sample,http://msdn.microsoft.com/en-us/library/system.management.instrumentation.managementreferenceattribute.aspx (working fine but the LetterPhonetic class won’t show on the WMI Object Browser)

 

Ideas will be highly appreciated

 

My Sample code

 

using System;
using System.Management.Instrumentation;
using System.Collections.Concurrent;
using System.Collections;
 
[assemblyWmiConfiguration("root\\ConsoleC", HostingModel = ManagementHostingModel.Decoupled)]
 
 
 
namespace ConsoleDecoupled
{
 
    [System.ComponentModel.RunInstaller(true)]
    public class TheInstaller : DefaultManagementInstaller
    {
    }
 
    public class Program
    {
        public static void Main(string[] args)
        {
            for (int i = 0; i < 10; ++i)
            {
                TestEnumWmi ms = TestEnumWmi.CreateTestEnumWmi();
                ms.teststring = i.ToString();
            }
            InstrumentationManager.RegisterType(typeof(TestEnumWmi));
            InstrumentationManager.RegisterType(typeof(RuntimeConfigSettings));
            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
            InstrumentationManager.UnregisterType(typeof(TestEnumWmi));
            InstrumentationManager.UnregisterType(typeof(RuntimeConfigSettings));
 
        }
    }
 
    [ManagementEntity(Singleton = true, Name = "ConfigurationSample")]
    [ManagementQualifier("Description", Value = "Configuration Sample Application")]
    public class RuntimeConfigSettings
    {
        [ManagementProbe]
        public string[] ReadMe;
 
        private int myVar;
        [ManagementConfiguration]
        public int MyProperty
        {
            get { return myVar; }
            set { myVar = valueConsole.WriteLine(value); }
        }
 
        [ManagementReference(Type = "TestEnumWmi")]
        [ManagementProbe]
        public TestEnumWmi MSS;
 
        [ManagementBind]
        public RuntimeConfigSettings()
        {
            ReadMe = new string[10];
 
            for (int i = 0; i < 10; ++i)
            {
                ReadMe[i] = "blah " + i;
            }
 
        }
    }
 
 
    [ManagementEntity(Name = "TestEnumWmi")]
    public class TestEnumWmi
    {
 
        private TestEnumWmi()
        {
        }
 
        static internal TestEnumWmi CreateTestEnumWmi()
        {
            TestEnumWmi ms = new TestEnumWmi();
 
            ms._id = Guid.NewGuid().ToString();
            ms.teststring = "blah";
            ms.TestInt = new Random().NextDouble();
 
            instantlist.TryAdd(ms._id, ms);
            return ms;
        }
 
        [ManagementConfiguration()]
        public double TestInt { getset; }
        [ManagementConfiguration()]
        public string teststring { getset; }
 
        [ManagementKey(Name = "ID")]
        public string _id;
 
        [ManagementBind]
        static public TestEnumWmi GetInstant([ManagementName("ID")] string ID)
        {
            TestEnumWmi ms = null;
            if (instantlist.TryGetValue(ID, out ms))
                return ms;
            else
                throw new InstanceNotFoundException();
        }
 
        [ManagementEnumerator]
        static public IEnumerable EnumerateTestEnumWmis()
        {
            foreach (var i in instantlist)
            {
                yield return i.Value;
            }
        }
 
        static internal ConcurrentDictionary<stringTestEnumWmi> instantlist = new ConcurrentDictionary<stringTestEnumWmi>();
    }
}

 

 


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>