Partager via


How to Install a Management Pack with Resources

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 only contains references to external resource files. It does not internally contain any of the resource files. To automatically install these resources with a management pack, you must use a bundle. When the bundle is created, the resources can be added to the bundle. This requires that you have access to two things: the identifier of the resource that is used in the management pack, and the actual associated resource file.

To import a management pack instance directly, not using a bundle, you can import the resource files it references. To accomplish this import you must first load each resource into a ResourceStream object and add this object to a dictionary that references each resource by the identifier in the management pack. When the management pack is imported with the resource dictionary, Service Manager will attempt to resolve each resource from the dictionary.

To import a management pack with resources

  1. Create a new instance of the EnterpriseManagementGroup class to connect to a management server.

  2. Get reference to a management pack.

  3. For each resource file, create a new instance of the FileStream class. Provide the file name and Open file mode to the constructor.

  4. For each resource file, create a new instance of the ResourceStream class. Provide the FileStream instance from the previous step and the EnterpriseManagementGroup.

  5. Create a new generic Dictionary that will hold each ResourceStream with the appropriate identifier. The TKey should be a String and the TValue should be a

  6. Add the ResourceStream instance to the Dictionary with each corresponding identifier. Each stream will have the same identifier as the management pack resource reference.

  7. To import the management pack, call the ImportManagementPack method on the EnterpriseManagementGroup instance.

Example

The following example demonstrates how to create resource stream objects to use when importing the management pack. The example demonstrates importing images.

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = new ManagementPack("Folder\\RePackaging.Library.xml", mg);

System.IO.FileStream fileStream1 = new System.IO.FileStream("Folder\\Resources\\package_16.png", System.IO.FileMode.Open);
System.IO.FileStream fileStream2 = new System.IO.FileStream("Folder\\Resources\\package_32.png", System.IO.FileMode.Open);
System.IO.FileStream fileStream3 = new System.IO.FileStream("Folder\\Resources\\package_64.png", System.IO.FileMode.Open);

ResourceStream resStream1 = new ResourceStream(mg, fileStream1);
ResourceStream resStream2 = new ResourceStream(mg, fileStream2);
ResourceStream resStream3 = new ResourceStream(mg, fileStream3);

Dictionary<string, ResourceStream> resources = new Dictionary<string, ResourceStream>();
resources.Add("RePackaging.Library.Resources.Images.Package_16", resStream1);
resources.Add("RePackaging.Library.Resources.Images.Package_32", resStream2);
resources.Add("RePackaging.Library.Resources.Images.Package_64", resStream3);

mg.ManagementPacks.ImportManagementPack(mp, resources);

Compiling the Code

Namespaces

Microsoft.EnterpriseManagement

Microsoft.EnterpriseManagement.Common

Microsoft.EnterpriseManagement.Configuration

System.Collections.Generic

Assemblies

Microsoft.EnterpriseManagement.Core

mscorlib

See Also

Tasks

How to Install a Management Pack
How to Uninstall a Management Pack
How to Reference Existing Management Packs

Reference

EnterpriseManagementGroup
ResourceStream

Other Resources

Scenario: Managing Management Packs