Share via


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:

 

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

  1. In the Authoring console, select Service Model, and then select Classes.
  2. Right-click in the Classes pane, select New, and then select Windows Server role.
  3. In the ID box, type the name MyMP.MyComputerRoleBase.
  4. In the Display Name box, type My Computer Role Base.
  5. Click Finish.
  6. Right click MyMP.MyComputerRoleBase and select Properties.
  7. On the General tab, in the Attributes pane, select Abstract.
  8. On the Properties tab, do the following:
    1. Right-click in the navigation pane and select Add Property.
    2. In the Choose a unique identifier box, type Version, and then click OK.
    3. 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.
    4. Click OK.
  9. Select File, and then click Save.

Creating classes based on a custom abstract class

  1. In the Authoring console, select Service Model, and then select Classes.
  2. Right-click in the Classes pane, select New, and then select Custom Class.
  3. In the Choose a unique identifier box, type the name MyMP.MyComputerRole1, and then click OK.
  4. On the General tab, do the following:
    1. In the Base Class box, select MyMP.MyComputerRoleBase.
    2. In the Display Name box, type My Computer Role 1. Click OK.
  5. Right-click in the Classes pane, select New, and then select Custom Class.
  6. In the Choose a unique identifier box, type the name MyMP.MyComputerRole2, and then click OK.
  7. On the General tab, do the following:
    1. In the Base Class box, select MyMP.MyComputerRoleBase.
    2. In the Display Name box, type My Computer Role 2. Click OK.
  8. Select File, and then click Save.

Creating an application component

  1. In the Authoring console, select Service Model, and then select Classes.
  2. Right-click in the Classes pane, select New, and then select Windows Local Application Component.
  3. On the General page, do the following:
    1. In the ID box, type the name MyMP.MyApplicationComponent.
    2. In the Display Name box, type My Application Component.
    3. Click Next.
  4. On the Key Properties page, do the following:
    1. 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.
    2. In the ID box, replace the existing text with ComponentName.
    3. In the Type box, select string.
    4. In the Name box, type Component Name. Click Next.
  5. On the Hosting Class page, do the following:
    1. In the Hosting Class box, type MyMP.MyComputerRole1.
    2. In the Hosting Relationship ID box, type MyMP.MyComputerRole1HostsMyApplicationComponent.
    3. In the Hosting Relationship Name box, type My Computer Role 1 Hosts My Application Component. Click Finish.
  6. Select File, and then click Save.

Visual Studio Authoring Extensions Procedure

Creating an abstract class

  1. In Visual Studio, right click the name of the solution and select Add and then New Item.

  2. Select Class.

  3. In the Name box, type Classes.mpx and click Add.

  4. Remove the comments from the Classes.mpx file.

  5. 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.

  6. 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>
    
  7. Select File, and then click Save Classes.mpx.

  8. Select Build and then Build Solution.

  9. Ensure that you don't receive any errors.

Creating classes based on a custom abstract class

  1. 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.

  2. 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>
    
  3. Select File, and then click Save Classes.mpx

  4. Select Build and then Build Solution.

  5. Ensure that you don't receive any errors.

Creating an application component

  1. 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>
    
  2. 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>
    
  3. 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>
    
  4. Select File, and then click Save Classes.mpx

  5. Select Build and then Build Solution

  6. Ensure that you don't receive any errors.

See Also