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
- Create a sample directory:
- macOS
- Windows
- Linux
mkdir tasks-console-sample
cd tasks-console-sample
md tasks-console-sample
cd tasks-console-sample
mkdir tasks-console-sample
cd tasks-console-sample
- Create a new sample console application:
- C#
info
.NET 8.0 SDK is recommended for this example.
dotnet new console --framework net8.0
- Add Taskurai SDK:
dotnet add package Taskurai
- 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
- 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)
});
- Add application configuration:
Add the following configuration files:
appsettings.json
{
"Taskurai": {
"IsolationMode": false
}
}
appsettings.Development.json
{
"Taskurai": {
"IsolationMode": true
}
}
- 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..."
- Next, run the console application to validate the setup:
dotnet run
The expected output should be:
Testing Taskurai client library...
Entering isolation mode, looking up token information...
Running in isolation mode.
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.