Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.]
Relationships exist as instances of a relationship object. A relationship object is created by creating an instance of the CreatableEnterpriseManagementRelationshipObject class and passing an instance of an existing management pack relationship definition to the constructor. Before a relationship can be committed, the target and source properties must be set to enterprise management object instances. This is done by calling the SetTarget and SetTarget methods. To commit a relationship instance and add it to Service Manager, call the Commit.
To create an instance of a relationship
Get reference to two different management pack class objects.
Get an existing ManagementPackRelationship object from a management pack by using the GetRelationship method and the identifier of the relationship.
Create a new instance of the CreatableEnterpriseManagementRelationshipObject class using the relationship object from the previous step.
Call the SetSource method, providing an enterprise management object as the source of the relationship.
Call the SetTarget method, providing an enterprise management object as the target of the relationship.
Call the Commit method to finish creating the relationship instance.
Example
The following example demonstrates establishing a relationship between two RePackaging.Library!RePackaging.Request and System.Software.Library!System.SoftwareItem objects:
EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = new ManagementPack("Folder\\RePackaging.Library.xml", mg);
ManagementPack mpSoftware = mg.ManagementPacks.GetManagementPack("System.Software.Library", "9396306c2be7fcc4", new Version());
ManagementPack mpSystem = mg.ManagementPacks.GetManagementPack("System.Library", "9396306c2be7fcc4", new Version());
ManagementPackClass requestClass = mp.GetClass("RePackaging.Request");
ManagementPackClass softwareClass = mpSoftware.GetClass("System.SoftwareItem");
ManagementPackRelationship softwareToRequest = mp.GetRelationship("Relationship.SoftwareToRequest");
EnterpriseManagementObject sourceInstance = null;
EnterpriseManagementObject targetInstance = null;
foreach (var item in mg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(requestClass, ObjectQueryOptions.Default))
{
sourceInstance = item;
break;
}
foreach (var item in mg.EntityObjects.GetObjectReader<EnterpriseManagementObject>(softwareClass, ObjectQueryOptions.Default))
{
targetInstance = item;
break;
}
CreatableEnterpriseManagementRelationshipObject relationship = new CreatableEnterpriseManagementRelationshipObject(mg, softwareToRequest);
relationship.SetSource(sourceInstance);
relationship.SetTarget(targetInstance);
relationship.Commit();
Compiling the Code
Namespaces
Microsoft.EnterpriseManagement |
Microsoft.EnterpriseManagement.Common |
Microsoft.EnterpriseManagement.Configuration |
System |
Assemblies
Microsoft.EnterpriseManagement.Core |
System |
See Also
Tasks
Reference
RelationshipTypes
ManagementPackRelationship
ManagementPackRelationshipEndpoint
ManagementPackClass
ManagementPack