using System.Diagnostics; using System.Reflection; namespace w4c_workflows.Services; /// /// Static self-description of this workflows-api instance, served at /// GET /api/about. Used by the platform to show a runtime's name/version in /// the runtime selector and by self-hosted runtimes to report themselves when they /// connect over the outbound channel. /// public sealed record RuntimeSelfInfo( string Name, string Version, DateTimeOffset StartedAt, bool MultiTenant); /// /// Produces from configuration + process state. /// nameRuntime:Name (default APP_NAME / app name), /// version ← assembly informational version, startedAt ← process /// start, multiTenant!UseLiteMode (overridable via /// Runtime:MultiTenant). /// public sealed class RuntimeSelfInfoProvider { private readonly RuntimeSelfInfo _info; public RuntimeSelfInfoProvider(IConfiguration config) { var name = FirstNonEmpty( config["Runtime:Name"], config["APP_NAME"], "w4c-workflows-api")!; var version = Assembly.GetExecutingAssembly() .GetCustomAttribute()?.InformationalVersion ?? Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown"; DateTimeOffset startedAt; try { startedAt = Process.GetCurrentProcess().StartTime.ToUniversalTime(); } catch { startedAt = DateTimeOffset.UtcNow; } var liteMode = config.GetValue("UseLiteMode"); var multiTenant = !liteMode; if (config["Runtime:MultiTenant"] is { Length: > 0 } raw && bool.TryParse(raw, out var parsed)) { multiTenant = parsed; } _info = new RuntimeSelfInfo(name, version, startedAt, multiTenant); } public RuntimeSelfInfo Get() => _info; private static string? FirstNonEmpty(params string?[] values) { foreach (var value in values) if (!string.IsNullOrWhiteSpace(value)) return value.Trim(); return null; } }