Thursday, June 12, 2008

WMI Association Classes

I've been trying for most of the day to determine how to create a WMI Association class using C#. Here's the ONLY reference I found, sheesh!

http://msdn.microsoft.com/en-us/library/system.management.instrumentation.managementreferenceattribute.aspx

This example demonstrates how to use the ManagementReferenceAttribute attribute together with the ManagementQualifierAttribute to create an association WMI class that links two other WMI classes. The example is a decoupled provider that exposes three WMI classes in the root/assoc namespace. The first two classes, NumberPhonetic and NumberLetter, are linked by the last class, LetterPhonetic.
To compile the example, you will need to include references to both System.Management.Instrumentation and System.Configuration.Install. You must run installutil.exe against the resulting executable and ensure that the program is running in order to use the implemented WMI classes.
Copy Codeusing System;
using System.Collections;
using System.Management.Instrumentation;
[assembly: WmiConfiguration("root/assoc", HostingModel = ManagementHostingModel.Decoupled)]
[System.ComponentModel.RunInstaller(true)]
public class TheInstaller : DefaultManagementInstaller
{ }
namespace AssocExample
{
class Program
{
static void Main(string[] args)
{
InstrumentationManager.RegisterType(typeof(NumberPhonetic));
InstrumentationManager.RegisterType(typeof(NumberLetter));
InstrumentationManager.RegisterType(typeof(LetterPhonetic));
Console.WriteLine("Press enter to exit");
Console.ReadLine();
InstrumentationManager.UnregisterType(typeof(NumberPhonetic));
InstrumentationManager.UnregisterType(typeof(NumberLetter));
InstrumentationManager.UnregisterType(typeof(LetterPhonetic));

}
}
[ManagementEntity]
public class NumberPhonetic
{
[ManagementKey]
public int Number;
[ManagementProbe]
public string Name;
[ManagementBind]
public NumberPhonetic(int Number)
{
this.Number = Number;
if(Number == 1)
{
Name = "alpha";
}
else if(Number == 2)
{
Name = "bravo";
}
else
{
throw new InstanceNotFoundException();
}
}
[ManagementEnumerator]
static public IEnumerable EnumerateInstances()
{
for (int i = 1; i < 3; i++)
{
yield return new NumberPhonetic(i);
}
}

}
[ManagementEntity]
public class NumberLetter
{
[ManagementKey]
public int Number;
[ManagementProbe]
public string Letter;
[ManagementBind]
public NumberLetter(int Number)
{
this.Number = Number;
if(Number == 1)
{
Letter = "A";
}
else if(Number == 2)
{
Letter = "B";
}
else
{
throw new InstanceNotFoundException();
}
}
[ManagementEnumerator]
static public IEnumerable EnumerateInstances()
{
for (int i = 1; i < 3; i++)
{
yield return new NumberLetter(i);
}
}
}
[ManagementEntity]
[ManagementQualifier("Association", Flavor = ManagementQualifierFlavors.DisableOverride)]
public class LetterPhonetic
{
[ManagementReference(Type = "NumberLetter")]
[ManagementKey]
public string LetterNumber;
[ManagementReference(Type = "NumberPhonetic")]
[ManagementKey]
public string PhoneticNumber;
[ManagementEnumerator]
static public IEnumerable EnumerateInstances()
{
ArrayList insts = new ArrayList();
for (int i = 1; i < 3; i++)
{
LetterPhonetic inst = new LetterPhonetic();
inst.LetterNumber = "Letter = " + i;
inst.PhoneticNumber = "Phonetic = " + i;
insts.Add(inst);
}
return insts;
}
}
}

Wednesday, April 9, 2008

Windows Computer Management Services SnapIn

I can't believe that I need to write my own MMC Snap-In to simply filter out certain services that the standard Services SnapIn displays. Why should I have to duplicate all of that existing functionality? It would be nice to be able to inherit that whole SnapIn and override the WMI query that it uses to retrieve the list of services.

If anybody knows another way to do this please comment.

Monday, April 7, 2008

Learning to Juggle 5

I've been trying to learn to juggle 5 balls for several months now. I only practice Thursday nights for a few hours at our (TurksHeadJugglers) club meetings, so it is definitely my fault that I'm not progressing faster then I should.

I'm finding that using tetrahedral felt bags filled with shot seems easier then my Dube balls.

I've gotten to the point where I can flash 5 fairly consistently, 6 once in a while, and 7 once in a GREAT while.

My biggest issue is accuracy. I juggle facing a wall and with a large pile of gym mats in front of me so I don't have to bend over to the floor every 15 seconds or so to pick up the bags. When I'm tossing 3 or 4, my accuracy isn't bad, but as I throw higher and faster, it goes to pot. Tosses from my Right hand inevitably go forward, so if the wall wasn't there, I'd be walking forward, and tosses from my left go much higher then they're supposed to. Every so often I just back down to 1 or 2 balls to improve my aim. It is going much slower then I'd hoped though.

Friday, April 4, 2008

First Entry

Ok, so I blog therefore, I am, right?

I'm putting this up so that I can save my random thoughts and ramblings on things I'm interested in which includes juggling, motorcycles, origami, flying and software development. Everything that appears here will be my thoughts and feelings only unless attributed to someone else.

Enjoy reading.