38 lines
1.7 KiB
C#
38 lines
1.7 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RudderSdk.Core;
|
|
|
|
/// <summary>Session of a scenario quest node.</summary>
|
|
public sealed class QuestSession
|
|
{
|
|
internal QuestSession(ScenarioNodeContext context) => Context = context;
|
|
|
|
/// <summary>Underlying node context.</summary>
|
|
public ScenarioNodeContext Context { get; }
|
|
|
|
/// <summary>Node id.</summary>
|
|
public string Id => Context.NodeId;
|
|
|
|
/// <summary>Reads a typed value from the node data.</summary>
|
|
public T Get<T>(string key, T defaultValue = default!) => Context.Get(key, defaultValue);
|
|
|
|
/// <summary>Adds progress to one of the node's counters.</summary>
|
|
public Task AddProgressAsync(string counterKey, long amount, CancellationToken cancellationToken = default) => Context.AddProgressAsync(counterKey, amount, cancellationToken);
|
|
|
|
/// <summary>Adds progress to one of the node's counters (fire-and-forget).</summary>
|
|
public void AddProgress(string counterKey, long amount) => _ = AddProgressAsync(counterKey, amount);
|
|
|
|
/// <summary>Advances the run through the onComplete handle.</summary>
|
|
public Task CompleteAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onComplete", cancellationToken);
|
|
|
|
/// <summary>Advances the run through the onComplete handle (fire-and-forget).</summary>
|
|
public void Complete() => Context.Complete("onComplete");
|
|
|
|
/// <summary>Advances the run through the onFail handle.</summary>
|
|
public Task FailAsync(CancellationToken cancellationToken = default) => Context.CompleteAsync("onFail", cancellationToken);
|
|
|
|
/// <summary>Advances the run through the onFail handle (fire-and-forget).</summary>
|
|
public void Fail() => Context.Complete("onFail");
|
|
}
|