Management Pack Service Model Exercise #1 - Creating a Class in Operations Manager
Overview
The following procedures explain how to create classes in a management pack using both the Operations Manager 2007 Authoring Console and Visual Studio Authoring Extensions. This exercise is part of the System Center Operations Manager Management Pack Authoring Center.
Product Versions
This exercise applies to the following products:
- System Center Operations Manager 2007 R2
- System Center 2012 Operations Manager
- System Center 2012 Operations Manager SP1
Prerequisites
Before you perform this procedure, you must first complete the following prerequisite procedures:
- Creating a New Management Pack - Create the management pack.
Revisions
The Microsoft System Center team has validated this procedure as of revision #4. We will continue to review any changes and periodically provide validations on later revisions as they are made. Please feel free to make any corrections or additions to this procedure that you think would assist other users
Sample Code
A sample of the completed code for each exercise is available in the TechNet Gallery. There is a separate sample for each exercise that includes the management pack completed at the end of that exercise and each preceding exercise. This strategy allows you to work through each exercise in order and then compare your results. For VSAE, this also includes the Visual Studio solution.
Details
The classes created in the following procedures have the following characteristics:
- Abstract class named MyMP.MyComputerRoleBase based on Windows Computer Role. Class has a single non-key property named Version and no key property.
- Two classes based on the abstract class named MyComputerRole1 and MyComputerRole2.
- Single application component hosted by a computer role called MyApplicationComponent. Class has a single key property named ComponentName.
Authoring Console Procedure
Creating an abstract class
- In the Authoring console, select Service Model, and then select Classes.
- Right-click in the Classes pane, select New, and then select Windows Server role.
- In the ID box, type the name MyMP.MyComputerRoleBase.
- In the Display Name box, type My Computer Role Base.
- Click Finish.
- Right click MyMP.MyComputerRoleBase and select Properties.
- On the General tab, in the Attributes pane, select Abstract.
- On the Properties tab, do the following:
- Right-click in the navigation pane and select Add Property.
- In the Choose a unique identifier box, type Version, and then click OK.
- In the Display Name box, type Version. Because you are expecting only a single instance of this class on a computer, it does not require a key property.
- Click OK.
- Select File, and then click Save.
Creating classes based on a custom abstract class
- In the Authoring console, select Service Model, and then select Classes.
- Right-click in the Classes pane, select New, and then select Custom Class.
- In the Choose a unique identifier box, type the name MyMP.MyComputerRole1, and then click OK.
- On the General tab, do the following:
- In the Base Class box, select MyMP.MyComputerRoleBase.
- In the Display Name box, type My Computer Role 1. Click OK.
- Right-click in the Classes pane, select New, and then select Custom Class.
- In the Choose a unique identifier box, type the name MyMP.MyComputerRole2, and then click OK.
- On the General tab, do the following:
- In the Base Class box, select MyMP.MyComputerRoleBase.
- In the Display Name box, type My Computer Role 2. Click OK.
- Select File, and then click Save.
Creating an application component
- In the Authoring console, select Service Model, and then select Classes.
- Right-click in the Classes pane, select New, and then select Windows Local Application Component.
- On the General page, do the following:
- In the ID box, type the name MyMP.MyApplicationComponent.
- In the Display Name box, type My Application Component.
- Click Next.
- On the Key Properties page, do the following:
- Check the Specify a key property box. You are expecting multiple instances of MyApplicationComponent for each instance of MyApplication, which is its hosting parent. Therefore, the class requires a key property.
- In the ID box, replace the existing text with ComponentName.
- In the Type box, select string.
- In the Name box, type Component Name. Click Next.
- On the Hosting Class page, do the following:
- In the Hosting Class box, type MyMP.MyComputerRole1.
- In the Hosting Relationship ID box, type MyMP.MyComputerRole1HostsMyApplicationComponent.
- In the Hosting Relationship Name box, type My Computer Role 1 Hosts My Application Component. Click Finish.
- Select File, and then click Save.
Visual Studio Authoring Extensions Procedure
Creating an abstract class
In Visual Studio, right click the name of the solution and select Add and then New Item.
Select Class.
In the Name box, type Classes.mpx and click Add.
Remove the comments from the Classes.mpx file.
Replace the ClassType entry with the following XML. This creates the Computer Role base abstract class.
<ClassType ID="MyMP.MyComputerRoleBase" Base="Windows!Microsoft.Windows.ComputerRole" Accessibility="Internal" Abstract="true" Hosted="true" Singleton="false"> <Property ID="Version" Key="false" Type="string" /> </ClassType>
Note that you can use Intellisense to create the attributes. Press Ctrl+SpaceBar on the Base entry to prompt for available base classes.
Replace the DisplayString entry with the following XML. This creates the display string for the Computer Role base abstract class.
<DisplayString ElementID="MyMP.MyComputerRoleBase"> <Name>My Computer Role Base</Name> <Description></Description> </DisplayString> <DisplayString ElementID="MyMP.MyComputerRoleBase" SubElementID="Version"> <Name>Version</Name> <Description></Description> </DisplayString>
Select File, and then click Save Classes.mpx.
Select Build and then Build Solution.
Ensure that you don't receive any errors.
Creating classes based on a custom abstract class
In Classes.mpx, add the following XML after the ClassType definition for MyMP.MyComputerRoleBase. This creates the Computer Role concrete classes.
<ClassType ID="MyMP.MyComputerRole1" Base="MyMP.MyComputerRoleBase" Accessibility="Internal" Abstract="false" Hosted="true" Singleton="false" /> <ClassType ID="MyMP.MyComputerRole2" Base="MyMP.MyComputerRoleBase" Accessibility="Internal" Abstract="false" Hosted="true" Singleton="false" />
Note that you can use Intellisense to create the attributes. Press Ctrl+SpaceBar on the Base entry to prompt for available base classes.
In the DisplayStrings section, add the following XML. This creates the display strings for the Computer Role concrete classes.
<DisplayString ElementID="MyMP.MyComputerRole1"> <Name>My Computer Role 1</Name> <Description></Description> </DisplayString> <DisplayString ElementID="MyMP.MyComputerRole2"> <Name>My Computer Role 2</Name> <Description></Description> </DisplayString>
Select File, and then click Save Classes.mpx.
Select Build and then Build Solution.
Ensure that you don't receive any errors.
Creating an application component
In Classes.mpx, add the following XML after the ClassType definition for MyMP.MyComputerRole. This creates the Application Component class.
<ClassType ID="MyMP.MyApplicationComponent" Base="Windows!Microsoft.Windows.ApplicationComponent" Accessibility="Internal" Abstract="false" Hosted="true" Singleton="false"> <Property ID="ComponentName" Key="true" Type="string" /> </ClassType>
In Classes.mpx, add the following XML after ClassTypes section. This creates the hosting relationship from the Computer Role class to the Application Component class.
<RelationshipTypes> <RelationshipType ID="MyMP.MyComputerRole1HostsMyApplicationComponent" Base="System!System.Hosting" Accessibility="Internal" Abstract="false"> <Source ID="Source" Type="MyMP.MyComputerRole1" /> <Target ID="Target" Type="MyMP.MyApplicationComponent" /> </RelationshipType> </RelationshipTypes>
In the DisplayStrings section, add the following XML. This creates the display string for the Application Component class and the hosting relationship.
<DisplayString ElementID="MyMP.MyApplicationComponent"> <Name>My Application Component</Name> <Description></Description> </DisplayString> <DisplayString ElementID="MyMP.MyComputerRole1HostsMyApplicationComponent"> <Name>My Computer Role Hosts My Application Component</Name> <Description></Description> </DisplayString>
Select File, and then click Save Classes.mpx.
Select Build and then Build Solution.
Ensure that you don't receive any errors.