How to Create a Folder Task

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.]

Tasks in the Service Manager console can appear on folders, folder items, or object instances inside a view. The time at which the task appears depends on the type of object targeted by the task and whether the object is currently selected or in scope. A task always points to handler class from a Microsoft .NET assembly. Parameters can be sent to the task handler. If a task action makes a call out to custom code in an unsigned assembly, the system prompts the end user to optionally cancel the task. For more information about tasks in Service Manager, see Presentation Overview.

To create a console task

  1. Create an instance of the ManagementPackConsoleTask class. Specify the management pack that will host the task, the identifier of the task, and whether the task will be is public or private.

  2. Set the DisplayName and Description properties.

  3. If the task will start enabled, set the Enabled property to true.

  4. Set the Target property to the object instance you want to target. For example, if you are creating a task that will be displayed when a certain folder is selected or within context of the selected item, set the target to a ManagementPackFolder instance.

  5. Set the Assembly and Handler properties to the appropriate values, depending on what action the task will take. For more information, see Presentation Overview.

  6. Add any argument name and value pairs that are required for the handler to the ArgumentCollection collection.

  7. Call the AcceptChanges method on the management pack that will host the task.

Example

The following example creates a task that uses the Microsoft.EnterpriseManagement.UI.SdkDataAccess.ConsoleTaskHandler handler. This handler lets you execute the task’s action through custom code. For more information about creating your own custom task handler, see How to Create Task Handlers.

EnterpriseManagementGroup mg = new EnterpriseManagementGroup("localhost");
ManagementPack mp = new ManagementPack("Folder\\RePackaging.Library.xml", mg);
ManagementPack consolemp = mg.ManagementPacks.GetManagementPack("Microsoft.EnterpriseManagement.ServiceManager.UI.Console", "31bf3856ad364e35", new Version());

ManagementPackFolder folder = mp.GetFolder("Folder.Packaging.Requests");
ManagementPackClass classRequest = mp.GetClass("RePackaging.Request");

ManagementPackConsoleTask taskAccept = new ManagementPackConsoleTask(mp, "Task.Accept", ManagementPackAccessibility.Public);
taskAccept.DisplayName = "Accept";
taskAccept.Description = "Accepts a new request.";
taskAccept.Enabled = true;
taskAccept.Target = classRequest;
taskAccept.Assembly = consolemp.GetResource<ManagementPackAssemblyResource>("SdkDataAccessAssembly");
taskAccept.Handler = "Microsoft.EnterpriseManagement.UI.SdkDataAccess.ConsoleTaskHandler";
taskAccept.ArgumentCollection.Add(new ManagementPackConsoleTaskParameter() { Name = "Assembly", MixedValue = "RePackaging" });
taskAccept.ArgumentCollection.Add(new ManagementPackConsoleTaskParameter() { Name = "Type", MixedValue = "RePackaging.Handlers.AcceptRequest" });
taskAccept.ArgumentCollection.Add(new ManagementPackConsoleTaskParameter() { MixedValue = "Accepting" });

mp.AcceptChanges();

Compiling the Code

Namespaces

Microsoft.EnterpriseManagement

Microsoft.EnterpriseManagement.Configuration

System

Assemblies

Microsoft.EnterpriseManagement.Core

mscorlib

See Also

Tasks

How to Create Task Handlers

Other Resources

Scenario: Working with Console Tasks