从另一个WMI类引用WMI可管理类 [英] Referencing WMI Manageable class from another WMI Class
问题描述
我正在尝试让WMI可管理类引用另一个WMI可管理类
类似
[ManagementEntity]
A类
{
}
[ManagementEntity]
B类
{
[ManagementReference(Type = "A")]
[ManagementProbe]
public A AClass;
}
尝试安装该类时,我收到类型不受支持" ;
我尝试了Microsoft ManagementReference 示例, (效果很好,但 LetterPhonetic类不会在WMI对象浏览器上显示)
I tried the Microsoft ManagementReference 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)
想法将受到高度赞赏
我的示例代码
My Sample code
using System;
using System.Management.Instrumentation;
using System.Collections.Concurrent;
using System.Collections;
[assembly: WmiConfiguration("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 = value; Console.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 { get; set; }
[ManagementConfiguration()]
public string teststring { get; set; }
[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<string, TestEnumWmi> instantlist = new ConcurrentDictionary<string, TestEnumWmi>();
}
}
推荐答案
卡多什,
Hi Kadosh,
根据您的描述,您的代码中没有定义LetterPhonetic类.所以有什么问题?您能更清楚地描述一下吗?
According to your description, there is not LetterPhonetic class defined in your code. So what's the problem? Chould you descript it more clearly?
感谢您的理解.
这篇关于从另一个WMI类引用WMI可管理类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!