Creating a Task

This example will demonstrate a simple task implementation, focusing on the areas of importance when creating
a custom task. The example task will simply log a "Hello, World" string to the administration website. To get
started, a new project needs to be created. Visual Studio 2017 will be used for this example, but any .NET compatible
development environment can be used to create a task project.

Open Visual Studio and select File -> New -> Project. When the new project dialog opens, select the Visual C# project
templates from the template list on the left and then select the Class Library template from the list on the right.
For this example, location and naming of the project are not particularly relevant, but developers creating task projects
should ensure that they name their projects according to their organization's coding/naming standards.

Once a name is assigned, click the OK button to be brought into the project. Some editors will create a dummy class file named Class1.cs. This file can
either be deleted and a new one with the appropriate name can be created or it can be renamed to the appropriate name. For
this example, create a new class file by right clicking on the project in the Solution Explorer and selecting Add -> New Item
from the context menu and selecting Class from the dialog. Give the class a name of HelloTask.cs.

At this time, a reference to the Taskmatics Scheduler API is required. In order to facilitate the development of Scheduler components,
a NuGet package called Taskmatics Scheduler Core is available from the NuGet online gallery. To install this package into the project,
right click on the project in the solution explorer and select Manage NuGet Packages from the context menu. When the dialog window appears,
ensure that the Online scope is selected at the left, then search for "Taskmatics". The Taskmatics Scheduler Core package should appear, at
which point it can be selected. Once selected, click the Install button to install the dependency into the project. Once completed, the
Taskmatics API will now be available.

Back on the HelloTask.cs file, the class declaration will need to be augmented to inherit from the Taskmatics.Scheduler.Core.TaskBase class. This
class is the base class for all custom tasks and has only one required method to implement, aptly called Execute. This is the method that will
contain all logic for the task being created. Since the only goal of this example task is to log a message out to the administration website, the
method body will be quite small. The entire body of the HelloTask.cs class will look like the following:

The Thread.Sleep() command in the method body simply pauses the execution of the task for a bit so that when the task is run in the following section
the task state notifications can be demonstrated, but notice the call to Context.Logger.Log() in the method body. The TaskBase class has a Context
property available to it that contains access to various data relevant to the executing task as well as the Logger, which can be used to log both messages
and exceptions. These messages are transmitted in real time by the agent running the task to the coordinator and displayed to any user that may be viewing
the Task Detail screen for this task while it is running. The messages are also persisted to the database so they can be viewed in the Task Detail screen
when viewing a task that has already completed execution. In this example, a simple text output of "Hello World!" will be written to the log.

Ensure that the project builds and do any cleanup necessary. The task is now ready to be installed into the administrative site.