Welcome to MSDN Blogs Sign
in | Join
| Help

Search

CarlosAg Blog

RSS 2.0

Atom 1.0

Home

About

Email

<

August 2006

>

Su

Mo

Tu

We

Th

Fr

Sa

30

31

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

1

2

3

4

5

6

7

8

9

Archives

August 2006
(1)

June 2006
(1)

May 2006
(1)

April 2006
(2)

November
2005 (1)

September
2005 (1)

August 2005
(1)

July 2005
(1)

Post Categories

.NET (4)

IIS (5)

WinForms
(1)

IIS

IIS.NET

Saturday, August 12, 2006 1:58 AM by CarlosAg

Extending the TreeView in IIS 7 in Windows Vista

Extending the Hierarchy Tree View in InetMgr

InetMgr exposes several extensibility points that developers can use to
plug-in their own features and make them look and feel just as the built-in
functionality. One of those extensibility features is the hierarchy tree view
and is exposed mainly through three classes:

HierarchyService. This class is the class that handles the entire
hierarchy and an instance is provided by the UI and you can get a reference to
it through a ServiceProvider. It is used to manipulate the tree view
programmatically, exposing methods to perform actions such as Select, Delete,
Refresh, etc.

HierarchyInfo. This abstract class represents a node in the tree
view, for example the Web Sites node, the Default Web Site's node, the
connections node are examples of instances of HierarchyInfo’s. This class has
properties like Text, Image and allows you to react to actions such as
selection, deletion, etc. Developers extending the tree view will need to
create their own derived classes to implement the behavior as explained below.

c) HierarchyProvider. This abstract class is the base class for all
the features that want to extend the tree view. HierarchyService will query
each of the registered providers to create the treeview. Developers that wish
to add their own nodes should register a HierarchyProvider through the
IExtensibilityManager interface.

To extend the Tree view to add your own set of nodes or context menu tasks,
developers need to perform the following actions:

Create a class that derives from HierarchyProvider and handles the
GetChildren and/or GetTaskItems to provide any nodes or tasks as needed.

Register the HierarchyProvider using the IExtensibilityManager, this is
typically done during the Module initialization phase.

3) Handle navigation and syncronization as needed.

Tasks illustrated in this walkthrough include:

Creating a HierarchyProvider and creating HierarchyInfo classes

Registering a HierarchyProvider

Testing the new feature

Note:
This walkthrough is a continuation from the
previous three walkthroughs you can find on how to extend InetMgr.

You can find the first three at:

Creating
a Simple UI Module

Creating
a Module Page for IIS7 Administration Tool

Adding
Configuration Functionality to IIS7 Admin Tool Extensions

Task 1: Creating a HierarchyProvider

HierarchyProvider is the base class that developers need to inherit from in
order to get calls from the UI whenever a node needs to be loaded. This way they
can choose to add nodes or tasks to the HierarchyInfo node that is passed as an
argument.

To create a HierarchyProvider

Back in Microsoft Visual Studio 2005 in the ExtensibilityDemo
solution, select the option Add New Item from the Project Menu.
In the Add New Item dialog select the Class template and type
DemoHierarchyProvider.cs as the name for the file.

Change the code so that it looks as follows:

using System;
using Microsoft.Web.Management.Client;

namespace ExtensibilityDemo {

internal class DemoHierarchyProvider : HierarchyProvider {

public DemoHierarchyProvider(IServiceProvider serviceProvider)
: base(serviceProvider) {
}

public override HierarchyInfo[] GetChildren(HierarchyInfo item) {
if (item.NodeType == HierarchyInfo.ServerConnection) {
return new HierarchyInfo[] { new DemoHierarchyInfo(this) };
}

return null;
}

internal class DemoHierarchyInfo : HierarchyInfo {

public DemoHierarchyInfo(IServiceProvider serviceProvider)
: base(serviceProvider) {
}

public override string NodeType {
get {
return "DemoHierarchyInfo";
}
}

public override bool SupportsChildren {
get {
return false;
}
}

public override string Text {
get {
return "Demo Page";
}
}

protected override bool OnSelected() {
return Navigate(typeof(DemoPage));
}
}
}
}

The code above creates a class derived from HierarchyProvider that implements
the base GetChildren method verifying that the node that is being
expanded is a ServerConnection; if that is the case it returns an
instance of a DemoHierarchyInfo node that will be added to that connection. The
class DemoHierarchyInfo simply specifies its NodeType (a non-localized string
that identifies the type of this node), SupportsChildren (false so that the +
sign is not offered in tree view) and Text (the localized text that will be
displayed in the tree view). Finally it overrides the OnSelected method and
performs navigation to the DemoPage as needed.

Task 2: Registering the HierarchyProvider

In this task we will register the hierarchy provider created in the previous
task so that the HierarchyService starts calling this type to extend the tree
view.

To register the provider

Back in Microsoft Visual Studio 2005, open the file
DemoModule.cs, and add the following code at the end of the
method to register the provider:

IExtensibilityManager extensibilityManager =
(IExtensibilityManager)GetService(typeof(IExtensibilityManager));

extensibilityManager.RegisterExtension(
typeof(HierarchyProvider),
new DemoHierarchyProvider(serviceProvider));

The entire code should look as follows:

protected override void Initialize(IServiceProvider serviceProvider,
ModuleInfo moduleInfo) {
base.Initialize(serviceProvider, moduleInfo);

IControlPanel controlPanel =
(IControlPanel)GetService(typeof(IControlPanel));

ModulePageInfo modulePageInfo =
new ModulePageInfo(this, typeof(DemoPage), "Demo", "Demo Page");

controlPanel.RegisterPage(modulePageInfo);

IExtensibilityManager extensibilityManager =
(IExtensibilityManager)GetService(typeof(IExtensibilityManager));

extensibilityManager.RegisterExtension(
typeof(HierarchyProvider),
new DemoHierarchyProvider(serviceProvider));
}

Task 3: Testing the new feature

To test the feature

Compile everything using Build Solution from the Build Menu and run
InetMgr.exe from the <Windows>\System32\InetSrv directory.

Connect to localhost using the TreeView and expand the server
connection node.

This will show the new node underneath the connection. When you
click on it, it will navigate to the demo page just as expected:

Furthermore, the breadcrumb at the top of the UI will automatically
discover it and you will be able to navigate to the page by clicking on
it, as well as using the text editing and intellisense feature it
provides.

Next Steps

In this lab, you learned how to extend the tree view to customize any node on
it and add your own nodes to it. You can also override the GetTasks method to
provide context menu tasks for existing nodes, and you can also override the
SyncSelection method to customize the way synchronization of navigation
works.

Filed Under: IIS

Comment Notification

If you would like to receive an email when updates are made to this post,
please register here

You can also stay up to date using your favorite aggregator by subscribing to
the CommentRss
Feed

Comments

No Comments

What do you think?

Name
(required)*

Your URL
(optional)

Comments
(required)*

Remember Me?