Add RoslynBridge.WebApi - ASP.NET Core 8.0 middleware that: - Provides a centralized REST API for accessing multiple VS instances - Manages instance registry with discovery by port, solution, or PID - Proxies requests to the appropriate VS instance - Tracks request/response history for debugging - Auto-cleanup of stale instances via background service Features: - Health endpoints: /api/health, /api/health/ping - Roslyn endpoints: /api/roslyn/projects, /api/roslyn/diagnostics, etc. - Instance management: /api/instances (register, heartbeat, unregister) - History tracking: /api/history, /api/history/stats - Swagger UI at root (/) for API documentation - CORS enabled for web applications Services: - InstanceRegistryService: Thread-safe registry of VS instances - HistoryService: In-memory request/response history (max 1000 entries) - InstanceCleanupService: Background service to remove stale instances - RoslynBridgeClient: HTTP client for proxying to VS instances Update RoslynBridge.sln to include RoslynBridge.WebApi project. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
using System.Collections.Concurrent;
|
|
using RoslynBridge.WebApi.Models;
|
|
|
|
namespace RoslynBridge.WebApi.Services;
|
|
|
|
/// <summary>
|
|
/// In-memory implementation of history service
|
|
/// </summary>
|
|
public class HistoryService : IHistoryService
|
|
{
|
|
private readonly ConcurrentQueue<QueryHistoryEntry> _entries = new();
|
|
private readonly ILogger<HistoryService> _logger;
|
|
private readonly int _maxEntries;
|
|
|
|
public HistoryService(ILogger<HistoryService> logger, IConfiguration configuration)
|
|
{
|
|
_logger = logger;
|
|
_maxEntries = configuration.GetValue<int>("History:MaxEntries", 1000);
|
|
}
|
|
|
|
public void Add(QueryHistoryEntry entry)
|
|
{
|
|
_entries.Enqueue(entry);
|
|
|
|
// Trim old entries if we exceed max
|
|
while (_entries.Count > _maxEntries)
|
|
{
|
|
_entries.TryDequeue(out _);
|
|
}
|
|
|
|
_logger.LogDebug("Added history entry: {Id} - {Path}", entry.Id, entry.Path);
|
|
}
|
|
|
|
public IEnumerable<QueryHistoryEntry> GetAll()
|
|
{
|
|
return _entries.Reverse();
|
|
}
|
|
|
|
public QueryHistoryEntry? GetById(string id)
|
|
{
|
|
return _entries.FirstOrDefault(e => e.Id == id);
|
|
}
|
|
|
|
public IEnumerable<QueryHistoryEntry> GetRecent(int count = 50)
|
|
{
|
|
return _entries.Reverse().Take(count);
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_entries.Clear();
|
|
_logger.LogInformation("History cleared");
|
|
}
|
|
|
|
public int GetCount()
|
|
{
|
|
return _entries.Count;
|
|
}
|
|
}
|