Quantcast
Channel: Marcel Zehner – marcelzehner.ch
Viewing all articles
Browse latest Browse all 99

Visual Studio Authoring Extensions (VSAE) – Part 2: Creating a Folder with a custom Image

$
0
0

In part 2 of this VSAE series I will demonstrate how to create folders with custom images to the Management Pack to have a container ready for creating views later on. Make sure you take a look at the other parts too as I will not go into some details again.

Part 1 – VSAE Part 1: Creating a new CI Class
Part 2 – VSAE Part 2: Creating a Folder with a custom Image (this post)
Part 3 – VSAE Part 3: Creating Views by using Snippet Templates

 

Step 1 – Create a new Folder

When creating new Folders in  Management Pack you need to define what the parent folder will be. In this example I want to create a new folder under “Configuration Items”.

image

By using Powershell with smlets you can quickly find out all the needed details. By using the cmdlet “Get-SCSMFolder” with some filter you can see the ID of the folder you want to use as parent. Also, you need to find out in what MP this folder lives.

image

Before we can use the parent folder we need to make sure that we have a reference to the MP where the folder lives in. In this example, there is no existing reference. The MP we are talking about is part of a MP bundle that is stored in the SCSM installation directory. So let’s add a reference to this MP bundle.

image

image

A warning window may appear telling you that some references could be added, some maybe not. In this case one MP of the bundle could not be referenced because it is unsealed which is a regular behavior as referencing to unsealed MPs is not possible. More important is the fact, that the MP that the folder we are looking for was added successfully.

image

When objects from MPs need to be accesses, we need an alias to reference to a MP. This alias is automatically set when the MP was added.

image

Now let’s add a new MP Fragment to the project.

image

Select the “Folder & Folder Item” template and choose a meaningful name.

image

Now change the code a little bit. First, remove the “Folder Items” area, this is not needed for now. Then the ID as needed and also the Accessibility of the Folder to “Public”. Then also change the parent folder. By using the MP alias you reference to the MP, then set the ID of the folder.

image

You can now build and deploy the MP and check if the new folder is visible.

image

The folder is there, but no image is assigned to it which makes it a bit boring Smiley So let’s add an image.

 

Step 2 – Assign a folder image

First you need an image. For this example I created a simple 24×24 png file and saved it to a folder within the project folder. Now a new MP Fragment needs to be added. Because there’s no template available OOB for Image references, we need an empty MP fragment. Keep in mind that you can create your very own templates or snippets if you want to re-use fragments for later projects. I will demonstrate this in later post.

image

Now we need to do some XML hacking, but thanks to IntelliSense this is pretty easy. First we need to add the Image (Filename) in the Resource section. Then we need an Image Reference to assign the Image to the Folder (Folder ID).

image

As a last step we need to add the image to the project. Add an existing Item and select the image file.

image

image

image

Again, Build and Deploy the solution and check if the image was assigned to the folder.

image

Cool! Now we are ready with our container for the next step to create views. Up for the next part!

Cheers
Marcel



Viewing all articles
Browse latest Browse all 99

Trending Articles