Add WebAPI middleware for multi-instance Roslyn Bridge routing

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>
This commit is contained in:
2025-10-26 23:51:33 -04:00
parent 716827a665
commit 1cbfba3893
76 changed files with 4322 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
namespace RoslynBridge.WebApi.Models;
/// <summary>
/// Health check response for service status
/// </summary>
public class HealthCheckResponse
{
/// <summary>
/// Overall health status
/// </summary>
public string Status { get; set; } = "Healthy";
/// <summary>
/// Web API service status
/// </summary>
public string WebApiStatus { get; set; } = "Running";
/// <summary>
/// Visual Studio plugin connection status
/// </summary>
public string VsPluginStatus { get; set; } = "Unknown";
/// <summary>
/// Timestamp of the health check
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
/// <summary>
/// API version
/// </summary>
public string Version { get; set; } = "1.0.0";
}

View File

@@ -0,0 +1,52 @@
namespace RoslynBridge.WebApi.Models;
/// <summary>
/// Represents a single query history entry with request and response information
/// </summary>
public class QueryHistoryEntry
{
/// <summary>
/// Unique identifier for this history entry
/// </summary>
public string Id { get; set; } = Guid.NewGuid().ToString();
/// <summary>
/// Timestamp when the request was received
/// </summary>
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
/// <summary>
/// The endpoint path that was called
/// </summary>
public string Path { get; set; } = string.Empty;
/// <summary>
/// HTTP method used
/// </summary>
public string Method { get; set; } = string.Empty;
/// <summary>
/// The Roslyn query request
/// </summary>
public RoslynQueryRequest? Request { get; set; }
/// <summary>
/// The Roslyn query response
/// </summary>
public RoslynQueryResponse? Response { get; set; }
/// <summary>
/// Request duration in milliseconds
/// </summary>
public long DurationMs { get; set; }
/// <summary>
/// Whether the request was successful
/// </summary>
public bool Success { get; set; }
/// <summary>
/// Client IP address
/// </summary>
public string? ClientIp { get; set; }
}

View File

@@ -0,0 +1,65 @@
using System.ComponentModel.DataAnnotations;
namespace RoslynBridge.WebApi.Models;
/// <summary>
/// Request model for Roslyn query operations
/// </summary>
public class RoslynQueryRequest
{
/// <summary>
/// Type of query to execute (e.g., "getsymbol", "getdocument", "findreferences")
/// </summary>
[Required]
public string QueryType { get; set; } = string.Empty;
/// <summary>
/// File path for file-based operations
/// </summary>
public string? FilePath { get; set; }
/// <summary>
/// Symbol name for symbol-based operations
/// </summary>
public string? SymbolName { get; set; }
/// <summary>
/// Line number (1-based) for position-based operations
/// </summary>
public int? Line { get; set; }
/// <summary>
/// Column number (0-based) for position-based operations
/// </summary>
public int? Column { get; set; }
/// <summary>
/// Additional parameters for the query
/// </summary>
public Dictionary<string, string>? Parameters { get; set; }
/// <summary>
/// Project name for project operations
/// </summary>
public string? ProjectName { get; set; }
/// <summary>
/// Package name for NuGet operations
/// </summary>
public string? PackageName { get; set; }
/// <summary>
/// Version for NuGet package operations
/// </summary>
public string? Version { get; set; }
/// <summary>
/// Build configuration (Debug/Release)
/// </summary>
public string? Configuration { get; set; }
/// <summary>
/// Directory path for directory operations
/// </summary>
public string? DirectoryPath { get; set; }
}

View File

@@ -0,0 +1,27 @@
namespace RoslynBridge.WebApi.Models;
/// <summary>
/// Response model for Roslyn query operations
/// </summary>
public class RoslynQueryResponse
{
/// <summary>
/// Indicates whether the operation was successful
/// </summary>
public bool Success { get; set; }
/// <summary>
/// Optional message providing additional context
/// </summary>
public string? Message { get; set; }
/// <summary>
/// The response data (structure varies by query type)
/// </summary>
public object? Data { get; set; }
/// <summary>
/// Error message if the operation failed
/// </summary>
public string? Error { get; set; }
}

View File

@@ -0,0 +1,42 @@
namespace RoslynBridge.WebApi.Models;
/// <summary>
/// Information about a registered Visual Studio instance
/// </summary>
public class VSInstanceInfo
{
/// <summary>
/// The port number where this VS instance is listening
/// </summary>
public int Port { get; set; }
/// <summary>
/// The process ID of the Visual Studio instance
/// </summary>
public int ProcessId { get; set; }
/// <summary>
/// The solution file path (if any solution is open)
/// </summary>
public string? SolutionPath { get; set; }
/// <summary>
/// The solution name (if any solution is open)
/// </summary>
public string? SolutionName { get; set; }
/// <summary>
/// When this instance was registered
/// </summary>
public DateTime RegisteredAt { get; set; }
/// <summary>
/// Last heartbeat time
/// </summary>
public DateTime LastHeartbeat { get; set; }
/// <summary>
/// List of project names in the solution
/// </summary>
public List<string> Projects { get; set; } = new();
}