How to Create a Class
A management pack class is a structured set of data. You can define your own class from scratch, or you can define your class based on an existing class in your own or any referenced management pack. Management pack classes have properties; each property is a set of information that describes that class. For example, if you wanted to create a class that stored information about bookshelves, you would create a new class named BookShelf. Some properties to describe that bookshelf could be: Height, Width, and ShelfCount.
As your management pack becomes more complex, the number of classes and how they interact with one other will grow. Planning what you are going to do before actually creating it in Service Manager will help you determine the design problems you may experience when building your solution. It is best to create a design before actually creating the classes and properties. This will give you a better idea of what type of classes you will have to create, if you can use existing management pack classes, and what properties you will have to have in order to represent the data.
|Unique identifiers such as class names cannot contain localized characters. To guarantee compatibility with System Center use only plain-text UTF-8 characters.|
To create a class in the management pack
With reference to your management pack, create a new instance of the ManagementPackClass class.
Add any properties needed to describe your class’ data. For more information, see
Call the AcceptChanges method on the management pack to commit the new class to System Center.
The following example creates a new class named RePackaging.Request using the System.WorkItem class as the base class.
EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost"); ManagementPack workItemMP = mg.ManagementPacks.GetManagementPack("System.WorkItem.Library", "9396306c2be7fcc4", new Version()); ManagementPack mp = new ManagementPack("RePackaging.Library", "RePackaging Library", new Version(1, 0), mg); ManagementPackClass mpClass = new ManagementPackClass(mp, "RePackaging.Request", ManagementPackAccessibility.Public); mpClass.Base = workItemMP.GetClass("System.WorkItem"); mp.AcceptChanges();
<ManagementPack ContentReadable="true" SchemaVersion="1.1" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <Manifest> <Identity> <ID>RePackaging.Library</ID> <Version>220.127.116.11</Version> </Identity> <Name>RePackaging Library</Name> <References> <Reference Alias="WorkItem"> <ID>System.WorkItem.Library</ID> <Version>7.0.6555.0</Version> <PublicKeyToken>9396306c2be7fcc4</PublicKeyToken> </Reference> </References> </Manifest> <TypeDefinitions> <EntityTypes> <ClassTypes> <ClassType ID="RePackaging.Request" Accessibility="Public" Abstract="false" Base="WorkItem!System.WorkItem" Hosted="false" Singleton="false" Extension="false" /> </ClassTypes> </EntityTypes> </TypeDefinitions> </ManagementPack>
Compiling the Code