zhmdff.uc.Client 1.0.6

dotnet add package zhmdff.uc.Client --version 1.0.6
                    
NuGet\Install-Package zhmdff.uc.Client -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="zhmdff.uc.Client" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="zhmdff.uc.Client" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="zhmdff.uc.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add zhmdff.uc.Client --version 1.0.6
                    
#r "nuget: zhmdff.uc.Client, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package zhmdff.uc.Client@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=zhmdff.uc.Client&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=zhmdff.uc.Client&version=1.0.6
                    
Install as a Cake Tool

zhmdff.uc.Client

A fail-open .NET 8 client SDK for the zhmdffUC control-plane. Provides ASP.NET Core middleware, background polling, Serilog sink, and log transport with zero impact on your application's reliability during control-plane downtime.


Features

  • Middleware: automatically short-circuits requests when your project status is Paused or Disabled
  • Heartbeat Endpoint: Built-in /_uc/status endpoint to allow the control-plane to ping, wake up, and sync with your container.
  • Fail-Open: if the control-plane is unreachable and FailOpen = true, all requests pass through
  • Background polling: dual IHostedService loop — status poll + log flush. Supports ETag optimization to reduce bandwidth.
  • Log Transport: ships logs to the control-plane respecting per-project enabled log levels. Supports optional GZIP compression.
  • Metadata & Profile Sync: Read and write project-specific private metadata (UpdateMetadataAsync) and fetch centralized app profiles.
  • SDK registration: announces itself to the control-plane on startup (version, hostname, runtime)
  • Dual-Key Auth Support: Supports both project-specific API keys and the global Master API Key for authentication.

Package Structure

zhmdff.uc.Client/
  MasterControlExtensions.cs   — AddMasterControl() + UseMasterControl()
  MasterControlMiddleware.cs   — ASP.NET Core middleware (with /_uc/status heartbeat + ETags)
  MasterControlService.cs      — IHostedService (status poll + log flush + ping loops)
  ZhmdffUcClient.cs            — On-demand polling client (Metadata, Status, Profile)
  ZhmdffUcOptions.cs           — Options class
  IZhmdffUcClient.cs           — Interface for mocking
  Http/
    MasterControlHttpClient.cs — Centralized HttpClient with ETags and GZIP support

Logging/ MasterControlSink.cs — Serilog ILogEventSink LogBuffer.cs — ConcurrentQueue<LogEntry> (max 1000, drop-oldest) Models/ ProjectStatus.cs LogBatch.cs SdkRegistration.cs DependencyInjection/ — Internal DI helpers Cache/ — IMemoryCache slot management


---

## Quick Start

### 1. Configure `appsettings.json`
```json
{
  "MasterControl": {
    "BaseUrl": "https://uc.zhmdff.dev",
    "ProjectId": "your-project-guid",
    "ApiKey": "your-project-api-key",
    "PollIntervalSeconds": 30,
    "LogFlushIntervalSeconds": 45,
    "FailOpen": true,
    "GzipLogs": false,
    "GzipThreshold": 1024
  }
}

2. Register in Program.cs

using zhmdff.uc.Client;

// Registers typed HttpClient, IHostedService, and Serilog sink
builder.Services.AddMasterControl(builder.Configuration);

// Optional: Serilog integration
builder.Host.UseSerilog((ctx, cfg) =>
    cfg.WriteTo.Console()
       .WriteTo.MasterControl());

var app = builder.Build();

// Must be first middleware in the pipeline
app.UseMasterControl();

3. Middleware Behaviour

On each request MasterControlMiddleware reads the cached ProjectStatus from IMemoryCache:

Path Behavior
/_uc/status Returns 200 OK with cached status (Internal Heartbeat)
Any other path Short-circuits if Paused/Disabled, otherwise calls next

Response body for /_uc/status:

{
  "projectId": "guid",
  "status": "Active",
  "statusCode": 200,
  "isFromCache": true
}

Options Reference

Option Default Description
BaseUrl required zhmdffUC backend URL
ProjectId required Project GUID
ApiKey null Project API key (X-Project-Key header)
PollIntervalSeconds 30 How often to refresh status from the API
LogFlushIntervalSeconds 45 How often to flush LogBuffer to /api/logs/ingest
FailOpen true Pass requests through when status is unknown

Serilog Sink

MasterControlSink checks the EnabledLogLevels returned by the last status poll before enqueuing. Only matching log levels are buffered.

// Wired automatically by AddMasterControl() — or manually:
.WriteTo.MasterControl()

LogBuffer is a ConcurrentQueue<LogEntry> capped at 1,000 entries. Oldest entries are dropped on overflow.


Resilience Guarantees

Scenario Behavior
Backend offline Last cached status served; FailOpen passes requests
Poll timeout / 5xx Failure swallowed, cache unchanged
Startup (no cache yet) FailOpen = true → pass through; false → block
Log flush failure Buffer retained, retry on next interval

Running Tests

cd Packages/nuget
dotnet test zhmdff.uc.Client.Tests\zhmdff.uc.Client.Tests.csproj --logger "console;verbosity=normal"

Current version: 1.0.6.


Part of the zhmdffUC ecosystem. See usage.md for full integration guide.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 126 4/6/2026
1.0.5 138 3/28/2026
1.0.3 174 3/28/2026
1.0.2 171 3/28/2026
1.0.1 119 3/28/2026
1.0.0 117 3/27/2026