Path: redb-tsak/src/redb.Tsak.Core/Controllers/ContextsController.cs
Snapshot: redb-tsak, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-tsak
Page: https://redbase.app/src/dev-2026-12-06/redb-tsak/src/redb.Tsak.Core/Controllers/ContextsController.cs
----
using redb.Route.Controllers;
using redb.Route.Controllers.Attributes;
using redb.Route.Core;
using redb.Tsak.Contracts;
using redb.Tsak.Core.Contracts;
using redb.Tsak.Core.Security;
using redb.Tsak.Core.Services;
namespace redb.Tsak.Core.Controllers;
///
/// Context lifecycle management: list, start, stop, restart, remove.
/// Route-level operations are in .
///
[Route("/api/contexts")]
public class ContextsController : RedbController
{
private ITsakContextManager GetManager() => Context.GetService()
?? throw new InvalidOperationException("ITsakContextManager not registered in context");
private ContextInfoCollector GetCollector() => Context.GetService()
?? new ContextInfoCollector(GetManager());
[HttpGet("")]
public object ListContexts()
{
var mgr = GetManager();
return mgr.GetAllContexts().Select(c =>
{
var routes = (c.Context as RouteContext)?.Routes;
return new ContextSummary
{
Name = c.Name,
Status = c.Context.IsStarted ? "Running" : "Stopped",
EndpointCount = c.Context.GetEndpoints()?.Count ?? 0,
IsAnonymous = c.Name.Contains("_dyn_", StringComparison.Ordinal),
RouteCount = routes?.Count ?? 0
};
}).ToList();
}
[HttpGet("/{name}")]
public object? GetContext([FromRoute("name")] string name)
{
var collector = GetCollector();
var detail = collector.Collect(name);
if (detail is null)
{
ApiResponse.NotFound(Exchange, $"Context '{name}' not found.");
Exchange.Stop();
return null;
}
return detail;
}
[HttpPost("/{name}/start")]
[AuditAdminAction(ActionName = "StartContext", TargetParam = "name")]
public async Task