BotSharp/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingContext.cs

54 lines
1.1 KiB
C#
Raw Normal View History

using BotSharp.Abstraction.Routing.Settings;
namespace BotSharp.Abstraction.Routing.Models;
public class RoutingContext
{
private readonly RoutingSettings _setting;
public RoutingContext(RoutingSettings setting)
{
_setting = setting;
}
private Stack<string> _stack { get; set; }
= new Stack<string>();
/// <summary>
/// Intent name
/// </summary>
public string IntentName { get; set; }
2023-10-27 01:23:06 +00:00
/// <summary>
2024-01-13 21:17:40 +00:00
/// Agent that can handle user original goal.
2023-10-27 01:23:06 +00:00
/// </summary>
public string OriginAgentId
2024-01-13 21:17:40 +00:00
=> _stack.Where(x => !_setting.AgentIds.Contains(x)).Last();
2023-10-29 01:54:10 +00:00
public bool IsEmpty => !_stack.Any();
public string GetCurrentAgentId()
{
return _stack.Peek();
}
public void Push(string agentId)
{
if (_stack.Count == 0 || _stack.Peek() != agentId)
{
_stack.Push(agentId);
}
}
/// <summary>
/// Pop current agent
/// </summary>
2023-10-29 01:54:10 +00:00
public void Pop()
{
2023-10-29 01:54:10 +00:00
_stack.Pop();
}
2023-10-29 01:54:10 +00:00
public void Empty()
{
_stack.Clear();
}
}