Skip to main content

Setup sample application

In this step, you'll create a small console program to create and interact with some tasks.

To ensure the security of your access token, this sample includes additional configuration to prevent checking the PAT into source control.

Create a console application

  1. Create a sample directory:
mkdir tasks-console-sample
cd tasks-console-sample
  1. Create a new sample console application:
info

.NET 8.0 SDK is recommended for this example.

dotnet new console --framework net8.0
  1. Add Taskurai SDK:
dotnet add package Taskurai
  1. Add configuration libraries:
dotnet add package Microsoft.Extensions.Configuration
dotnet add package Microsoft.Extensions.Configuration.Json
dotnet add package Microsoft.Extensions.Configuration.Binder
dotnet add package Microsoft.Extensions.Configuration.UserSecrets
  1. Setup the Taskurai client:

Add the following code to your Program.cs file:

Program.cs
using Taskurai;
using Taskurai.Models;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using System.Text.Json.Serialization;

Console.WriteLine("Testing Taskurai client library...");

// Load configuration - defaults to Development
var environment = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Development";

IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
.AddUserSecrets<Program>()
.Build();

// Setup Taskurai client
var taskurai = new TaskuraiClient(configuration["Taskurai:Pat"], new TaskuraiClientOptions()
{
IsolationMode = configuration.GetValue<bool>("Taskurai:IsolationMode", true)
});

// Setup serializer options
var serializerOptions = new JsonSerializerOptions()
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,

Converters =
{
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase),
}
};
  1. Add application configuration:

Add the following configuration files:

appsettings.json
{
"Taskurai": {
"IsolationMode": false
}
}
appsettings.Development.json
{
"Taskurai": {
"IsolationMode": true
}
}

  1. Add the personal access token as a user secret, replace the PAT with the one created in the previous step:
dotnet user-secrets init
dotnet user-secrets set "Taskurai:Pat" "e8gFaA8ZaetAHiS257opAr..."
  1. Next, run the console application to validate the setup:
dotnet run

Sample output:

Testing Taskurai client library...
Entering isolation mode, looking up token information...
Running in isolation mode (isolation key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx').
info

The console application runs in Isolation Mode when the environment is set to Development mode.

In Isolation Mode, the tasks created and returned are isolated to your local session, and will not affect workers running in the Taskurai instance.