Skip to content

Add OWIN-hosted REST API for proxy connection management#6

Open
mvsnak wants to merge 12 commits into
GridProtectionAlliance:masterfrom
mvsnak:feature/web-api
Open

Add OWIN-hosted REST API for proxy connection management#6
mvsnak wants to merge 12 commits into
GridProtectionAlliance:masterfrom
mvsnak:feature/web-api

Conversation

@mvsnak

@mvsnak mvsnak commented Jun 12, 2026

Copy link
Copy Markdown

Summary

  • Embeds a self-hosted OWIN/Web API 2 server inside ServiceHost, listening on http://localhost:8283 by default (configurable via app.config).

  • Exposes a ConnectionsController with full CRUD coverage of proxy connections:

    Method Route Description
    GET /api/connections List all configured connections
    GET /api/connections/{id} Get a single connection by GUID
    POST /api/connections Create a new connection
    POST /api/connections/import Import connections from an .s3config file
    PATCH /api/connections/{id} Update individual fields of a connection
    GET /api/connections/{id}/status Operational metrics for a running connection
    DELETE /api/connections/{id} Delete a connection with StreamProxy shutdown
  • Swagger UI available at http://localhost:8283 (powered by Swashbuckle + XML docs).

  • All write operations broadcast an [API_CONFIG_CHANGED] message over the GSF remoting channel so that any connected StreamSplitterManager instance reloads its view.

  • Updates StreamSplitterSetup (WiX) with OWIN/Web API dependency components and fixes WiX targets path resolution for Visual Studio 2022+ (MSBuild v17/v18).

Configuration

New entries added to app.config under <systemSettings>:

Key Default Description
WebHostingEnabled True Enable/disable the Web API at startup
WebHostURL http://localhost:8283 Listening endpoint
AuthenticationSchemes Anonymous Auth scheme for API clients
AnonymousResourceExpression ^/api/ Paths accessible without credentials

New dependencies

Package Version Role
Microsoft.Owin.Hosting (GSF) OWIN self-host infrastructure
Microsoft.AspNet.WebApi 5.3.0 HTTP routing and controllers
Swashbuckle.Core 5.6.0 Swagger / OpenAPI UI
Newtonsoft.Json 13.0.4 JSON serialization

Test plan

  • Build solution in Debug configuration; service starts and GET http://localhost:8283/api/connections returns [] when no connections are configured.
  • Open Swagger UI at http://localhost:8283; all 7 endpoints are listed with correct schemas.
  • POST /api/connections creates a connection; a connected StreamSplitterManager reloads automatically.
  • DELETE /api/connections/{id} removes the connection; StreamSplitterManager does not restore it on the next refresh.
  • GET /api/connections/{id}/status returns frame counts and latency for a running StreamProxy.
  • PATCH /api/connections/{id} with { "enabled": false } disables only the targeted connection.
  • Set WebHostingEnabled=False in app.config; service starts normally without binding a port.
  • Build StreamSplitterSetup in Release|x64 and Release|x86; MSIs install and register the Windows service correctly.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR embeds a self-hosted OWIN/Web API 2 HTTP server into the StreamSplitter Windows service to enable REST-based management of proxy connections (including Swagger UI), and updates the Manager + WiX installer to support the new runtime dependencies and configuration refresh behavior.

Changes:

  • Add OWIN self-host + Web API controllers/models (with Swagger) to expose CRUD/status operations for proxy connections.
  • Extend ServiceHost with web-host startup/shutdown plus helper APIs to add/remove connections and query runtime status.
  • Update installer/project/configuration to ship required assemblies and enable Manager auto-refresh when the service signals configuration changes.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Source/Applications/StreamSplitterSetup/StreamSplitterSetup.wxs Adds a WiX component group to deploy OWIN/Web API/Swagger + JSON dependencies.
Source/Applications/StreamSplitterSetup/StreamSplitterSetup.wixproj Adjusts WiX targets path resolution for newer MSBuild/VS installs.
Source/Applications/StreamSplitterManager/StreamSplitterManager.cs Auto-triggers DownloadConfig when the service broadcasts the API config-changed marker.
Source/Applications/StreamSplitter/StreamSplitter.csproj Adds Web API source files + references and enables XML doc output for Swagger.
Source/Applications/StreamSplitter/ServiceHost.cs Starts/stops the OWIN host and adds connection add/remove + status helpers for the API.
Source/Applications/StreamSplitter/packages.config Introduces NuGet dependencies needed for Web API + Swashbuckle + JSON.
Source/Applications/StreamSplitter/app.config Adds system settings for web hosting + binding redirects needed by new deps.
Source/Applications/StreamSplitter/Api/Startup.cs Configures Web API routing/formatters and Swashbuckle Swagger UI.
Source/Applications/StreamSplitter/Api/Models/UpdateConnectionRequest.cs DTO for PATCH partial updates.
Source/Applications/StreamSplitter/Api/Models/CreateConnectionRequest.cs DTO for creating connections from a GSF connection string.
Source/Applications/StreamSplitter/Api/Models/ConnectionStatusDto.cs DTO for runtime status/metrics returned by /status.
Source/Applications/StreamSplitter/Api/Models/ConnectionDto.cs DTO for returning configured connections + runtime state.
Source/Applications/StreamSplitter/Api/Filters/FileUploadOperationFilter.cs Swagger operation filter to show file upload UI for /import.
Source/Applications/StreamSplitter/Api/Controllers/ConnectionsController.cs Implements the REST API endpoints for list/get/create/import/patch/status/delete.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +83 to +85
ConnectionDto[] dtos = configuration
.Select(c => ConnectionDto.FromProxyConnection(c, ServiceHost.Current.GetRuntimeConnectionState(c.ID)))
.ToArray();
Comment on lines +170 to +173
[HttpPost, Route("")]
[ResponseType(typeof(ConnectionDto[]))]
public IHttpActionResult CreateConnections([FromBody] CreateConnectionRequest[] requests)
{
Comment on lines +392 to +404
CategorizedSettingsElementCollection systemSettings =
ConfigurationFile.Current.Settings["systemSettings"];

if (!systemSettings["WebHostingEnabled"].ValueAs(DefaultWebHostingEnabled))
{
DisplayStatusMessage("Web API hosting is disabled per configuration.", UpdateType.Information);
return;
}

string webHostURL = systemSettings["WebHostURL"].ValueAs(DefaultWebHostURL);

m_webAppHost = WebApp.Start<Startup>(webHostURL);

Comment on lines +280 to +282
MultipartMemoryStreamProvider provider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(provider);

Comment on lines +439 to +441
if (request.Enabled.HasValue)
settings["enabled"] = request.Enabled.Value.ToString().ToLower();

Comment on lines +11 to +13
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets') ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
Comment on lines +21 to +23
// 06/05/2026 - Marcos Vinicius Snak
// ApplyStreamProxyStatusUpdates: detect connections added externally (e.g. via REST API)
// and trigger automatic DownloadConfig so the Manager list stays in sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants