How to Create a Class
Applies To: System Center 2012 - Service Manager
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
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.
Tip
Unique identifiers such as class names cannot contain localized characters. To guarantee compatibility with Service Manager 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.
Set the DisplayName and Description properties.
The Base property must be set to an existing ManagementPackClass object. The System.Entity class from the System.Library management pack is the minimum base class one must inherit from.
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 Service Manager.
Example
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>1.0.0.0</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
Namespaces
Microsoft.EnterpriseManagement |
Microsoft.EnterpriseManagement.Configuration |
Assemblies
Microsoft.EnterpriseManagement.Core |
See Also
Tasks
How to Read a Class From a Management Pack
How to Add Properties to a Class
How to Update Existing Classes
Reference
ManagementPackClass
ManagementPack