How to Define an Enumeration
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.]
Enumerations are defined by creating enumeration values. When the enumeration value has a parent, it represents a type for use by management pack class properties. When an enumeration value does point to a parent, it represents a value. When a management pack class property uses the enumeration type, the value of that property targets a single enumeration value from that enumeration type.
Since enumerations are defined by using a parent relationship, the values are defined in a hierarchy where any child of a parent can contain more children. Enumeration values can be created for enumeration types defined in other management packs, attaching themselves to that parent enumeration.
To create a new enumeration type with values
With reference to your management pack, create a new instance of the ManagementPackEnumeration class, providing the management pack, identifier of the enumeration, and specify if it will be public. This is referred to as the enumeration type.
Set the Description property of the enumeration instance to something that explains what the enumeration is used for.
Set the DisplayName property of the enumeration instance to something that will be displayed in the console UI. This should be kept short and simple.
Create another two more instances of the ManagementPackEnumeration class. These are referred to as the enumeration values.
With each enumeration value, follow steps one and two.
With each enumeration value, set the Parent property to object instance created in step one, the enumeration type.
Accept the changes on the management pack.
To create a new enumeration value that is based on an external type
With reference to your management pack, create a new instance of the ManagementPackEnumeration class, providing the management pack, identifier of the enumeration, and specify if it will be public.
Set the Description property of the enumeration instance to something that explains what the enumeration is used for.
Set the DisplayName property of the enumeration instance to something that will be displayed in the console UI. This should be kept short and simple.
With reference to another management pack, such as the System.Software.Library management pack, get reference an existing enumeration type, such as System.SoftwareItem.
With reference to your enumeration instance, set the Parent property to the enumeration instance obtained by the previous step.
Accept the changes on the management pack.
Example
The following example demonstrates how to create an enumeration type with enumeration values:
EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = new ManagementPack("Folder\\RePackaging.Library.xml", mg);
//<EnumerationValue ID="Enum.RePackagingStatus" Accessibility="Public" />
ManagementPackEnumeration status = new ManagementPackEnumeration(mp, "Enum.RePackagingStatus", ManagementPackAccessibility.Public);
status.Description = "Represents the status of a repackaging request.";
status.DisplayName = "Status";
ManagementPackEnumeration statusNone = new ManagementPackEnumeration(mp, "Enum.RePackagingStatus.None", ManagementPackAccessibility.Public);
status.Description = "The repackaging request does not have a status.";
status.DisplayName = "None Specified";
status.Parent = status;
ManagementPackEnumeration statusRequested = new ManagementPackEnumeration(mp, "Enum.RePackagingStatus.Requested", ManagementPackAccessibility.Public);
status.Description = "A repackaging request has been created.";
status.DisplayName = "Requested";
status.Parent = status;
ManagementPackEnumeration statusProcessing = new ManagementPackEnumeration(mp, "Enum.RePackagingStatus.Processing", ManagementPackAccessibility.Public);
status.Description = "The repackaging request is being processed.";
status.DisplayName = "Processing";
status.Parent = status;
ManagementPackEnumeration statusCompleted = new ManagementPackEnumeration(mp, "Enum.RePackagingStatus.Completed", ManagementPackAccessibility.Public);
status.Description = "The repackaging request has been completed.";
status.DisplayName = "Completed";
status.Parent = status;
mp.AcceptChanges();
The following example shows the management pack XML:
<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">
<Property ID="Requester" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" />
<Property ID="SoftwareTitle" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" />
<Property ID="BitsURI" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" />
<Property ID="PackagingStatus" Type="enum" Required="true" EnumType="Enum.RePackagingStatus" DefaultValue="Enum.RePackagingStatus.None" />
</ClassType>
</ClassTypes>
<EnumerationTypes>
<EnumerationValue ID="Enum.RePackagingStatus" Accessibility="Public" />
<EnumerationValue ID="Enum.RePackagingStatus.None" Accessibility="Public" Parent="Enum.RePackagingStatus" />
<EnumerationValue ID="Enum.RePackagingStatus.Requested" Accessibility="Public" Parent="Enum.RePackagingStatus" />
<EnumerationValue ID="Enum.RePackagingStatus.Processing" Accessibility="Public" Parent="Enum.RePackagingStatus" />
<EnumerationValue ID="Enum.RePackagingStatus.Completed" Accessibility="Public" Parent="Enum.RePackagingStatus" />
</EnumerationTypes>
</EntityTypes>
</TypeDefinitions>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="false">
<DisplayStrings>
<DisplayString ElementID="RePackaging.Request" SubElementID="Requester">
<Name>Requester</Name>
<Description>The name of the person requesting the software.</Description>
</DisplayString>
<DisplayString ElementID="RePackaging.Request" SubElementID="SoftwareTitle">
<Name>Software Title</Name>
<Description>The title of the software.</Description>
</DisplayString>
<DisplayString ElementID="RePackaging.Request" SubElementID="BitsURI">
<Name>Software Location</Name>
<Description>The URI of the software.</Description>
</DisplayString>
<DisplayString ElementID="RePackaging.Request" SubElementID="PackagingStatus">
<Name>Packaging Request Status</Name>
</DisplayString>
<DisplayString ElementID="Enum.RePackagingStatus.None">
<Name>None</Name>
</DisplayString>
<DisplayString ElementID="Enum.RePackagingStatus.Requested">
<Name>Requested</Name>
</DisplayString>
<DisplayString ElementID="Enum.RePackagingStatus.Processing">
<Name>Processing</Name>
</DisplayString>
<DisplayString ElementID="Enum.RePackagingStatus.Completed">
<Name>Completed</Name>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPack>
Compiling the Code
Namespaces
Microsoft.EnterpriseManagement |
Microsoft.EnterpriseManagement.Configuration |
Assemblies
Microsoft.EnterpriseManagement.Core |
See Also
Tasks
Reference
ManagementPackEnumeration
Parent