workspace sdk tasks - Genetec/DAP GitHub Wiki
About tasks
A task represents a user-executable action in a client application. Tasks form the primary entry points for functionality in Security Desk and Config Tool: they appear on the home page and can be invoked programmatically through ITaskService.
Tasks serve several roles:
- Home page entries - Tasks appear as clickable items on the application home page, organized into categories with icons and thumbnails
- Page launchers - The
CreatePageTask<T>class links a task to a page type, creating and displaying the page when the task executes - Programmatic actions - Modules execute tasks by ID through
ITaskService, without requiring user interaction
Tasks do not require an SDK certificate. For the full list of component types that require certificates, see About Workspace SDK certificates.
Task base class
Create a task by inheriting from Genetec.Sdk.Workspace.Tasks.Task:
public class MyTask : Task
{
public override bool CanExecute() => true;
public override void Execute()
{
// Perform action
}
}
Task API
| Member | Type | Description |
|---|---|---|
Id |
Guid | Unique task identifier. Auto-generated if not set. |
Name |
string | Display name shown on the home page. |
Description |
string | Task description shown as tooltip text. |
Icon |
ImageSource | 16x16 icon shown in tab headers and task lists. The SDK provides a default icon if not set. |
Thumbnail |
ImageSource | 256x256 image shown on the home page tile. The SDK provides a default thumbnail if not set. |
CategoryId |
Guid | Determines where the task appears on the home page. Set to a TaskCategories constant to place the task under a built-in category header. Set to a TaskGroup ID to nest it under a custom group. When Guid.Empty (the default), the task appears at the root level outside any category. |
PositionIndex |
int (virtual) | Sort priority on the home page (default 0). Higher values appear first. Tasks with the same value are sorted alphabetically by name. |
HideHomePageAfterExecution |
bool | Whether the home page closes after the task executes (default true). When false, the home page remains visible, which is useful for tasks that perform a quick action without opening a page. Operators can override this by holding Ctrl or clicking with the middle mouse button. |
Workspace |
Workspace | Workspace instance. Available after Initialize is called. |
CanExecute and Execute
| Method | Description |
|---|---|
CanExecute() |
Return true if the task can execute. Controls both executability and visibility on the home page. Tasks that return false are hidden. This method is called frequently and can return different values over time based on connection state, privileges, or other conditions. |
Execute() |
Perform the task action |
To restrict a task based on user privileges, check privileges through the SDK engine inside CanExecute():
public override bool CanExecute()
{
return Workspace.Sdk.SecurityManager.IsPrivilegeGranted(MY_PRIVILEGE_ID);
}
Registering tasks
Initialize and register tasks in your module's Load method. Set properties like Name, Icon, Thumbnail, and CategoryId before calling Initialize:
public class SampleModule : Module
{
private MyTask m_task;
public override void Load()
{
m_task = new MyTask();
m_task.Name = "My Task";
m_task.Thumbnail = new BitmapImage(new Uri(@"pack://application:,,,/MY-ASSEMBLY;Component/Resources/MY-THUMBNAIL.png", UriKind.RelativeOrAbsolute));
m_task.CategoryId = new Guid(TaskCategories.Operation);
m_task.Initialize(Workspace);
Workspace.Tasks.Register(m_task);
}
public override void Unload()
{
Workspace.Tasks.Unregister(m_task);
}
}
An overload accepts a priority value that overrides PositionIndex:
m_task.Initialize(Workspace, priority: 50);
Task categories
The home page displays tasks grouped under category headers. Each built-in category appears as a labeled section with its tasks arranged beneath it. Categories that contain no visible tasks are hidden.
The TaskCategories static class defines the built-in categories:
| Constant | Description |
|---|---|
TaskCategories.Operation |
Operational monitoring tasks |
TaskCategories.Investigation |
Investigation and forensic tasks |
TaskCategories.Maintenance |
System maintenance tasks |
TaskCategories.Administration |
Administrative tasks |
TaskCategories.Diagnosis |
Diagnostic tasks |
Set a task's CategoryId to place it under a built-in category:
var task = new MyTask();
task.CategoryId = new Guid(TaskCategories.Operation);
task.Initialize(Workspace);
Workspace.Tasks.Register(task);
Custom task groups
Use TaskGroup to create a custom category. Set parentCategoryId to nest it under a built-in category, or use Guid.Empty to place it at the root level.
var group = new TaskGroup(
uniqueId: new Guid("..."),
parentCategoryId: new Guid(TaskCategories.Operation),
name: "My Tasks",
imageSource: myIcon,
priority: 100);
group.Initialize(Workspace);
Workspace.Tasks.Register(group);
Set a task's CategoryId property to the group's Id to place it in the custom group.
Task hierarchy
Tasks support parent-child nesting through the Register method. This is different from categories: CategoryId determines which category header a task appears under on the home page, while Register creates a direct parent-child relationship within the task tree.
var parentTask = new MyParentTask();
parentTask.Initialize(Workspace);
var childTask = new MyChildTask();
childTask.Initialize(Workspace);
parentTask.Register(childTask);
Workspace.Tasks.Register(parentTask);
Use Unregister(Task) to remove a subtask. Unregistering a task also disposes it.
Disposing tasks
Task implements Dispose(). The framework disposes tasks automatically when they are unregistered through Unregister(Task). Override Dispose(bool) to clean up resources such as event subscriptions:
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Clean up managed resources
}
base.Dispose(disposing);
}
Executing tasks programmatically
Use ITaskService to execute a registered task by its identifier:
var taskService = Workspace.Services.Get<ITaskService>();
taskService.Execute(taskId);
To retrieve the page created by a task:
taskService.Execute(taskId, out Page page);
An async overload is also available:
Page page = await taskService.ExecuteAsync(taskId, cancellationToken);
ITaskService first attempts to create the page associated with the task. If the task does not create a page, it executes the task directly.
Opening pages from tasks
To create a task that opens a page, see About pages.