How to Create an Instance
Updated: April 25, 2012
Applies To: System Center 2012 - Service Manager
Object instances can only be created by using a class definition. Even though an object instance is created, it has not been committed to the database. In the Service Manager 2012 SDK the class CreatableEnterpriseManagementObject represents a management pack class instance. This class is created by providing the management pack class definition that the instance will represent. Once created, the properties of that class are set by using the indexer. The indexer lets you obtain a property by providing either the property GUID, a ManagementPackProperty instance, or the class definition together with the name of the property. All key properties must be set before the object instance can be committed to the database.
To create an instance of a management pack class
With reference to your management pack, get reference to an existing ManagementPackClass object.
Create an instance of the CreatableEnterpriseManagementObject providing the ManagementPackClass object from the previous step.
Set a value on each key property and any other properties you want by using the indexer.
Call the Commit method on the CreatableEnterpriseManagementObject object to commit the new instance to Service Manager.
Example
The following example creates a new instance of the RePackaging.Request management pack class, configures it, and commits it to Service Manager:
EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost"); ManagementPack mp = mg.GetManagementPack("RePackaging.Library", null, new Version()); ManagementPackClass requestClass = mp.GetClass("RePackaging.Request"); CreatableEnterpriseManagementObject request = new CreatableEnterpriseManagementObject(mg, requestClass); // Set a property by name request[requestClass, "SoftwareTitle"].Value = "Software Application A"; // Set a property by reference ManagementPackProperty property = requestClass["Requester"]; request[property].Value = "Domain\\User1"; // Set a property by identifier (the DisplayName property) Guid propertyGuid = new Guid("883cd2bb-eb57-b4ff-bbf2-69b7cf4570dc"); request[propertyGuid].Value = "Software Application A - Domain\\User1"; request.Commit();
Compiling the Code
Namespaces
System |
Microsoft.EnterpriseManagement |
Microsoft.EnterpriseManagement.Common |
Microsoft.EnterpriseManagement.Configuration |
Assemblies
mscorlib |
Microsoft.EnterpriseManagement.Core |