125 lines
3.7 KiB
C#
125 lines
3.7 KiB
C#
using System.Diagnostics;
|
|
using System.Text.Json;
|
|
using MBN_STOCK_WEBVIEW.Core.Playout;
|
|
using MBN_STOCK_WEBVIEW.Playout;
|
|
using MBN_STOCK_WEBVIEW.Playout.Configuration;
|
|
using MBN_STOCK_WEBVIEW.Playout.Registration;
|
|
|
|
var command = args.Length == 0 ? "--probe" : args[0].ToLowerInvariant();
|
|
|
|
return command switch
|
|
{
|
|
"--probe" => Probe(),
|
|
"--dry-run" => await DryRunAsync(),
|
|
_ => Usage()
|
|
};
|
|
|
|
static int Probe()
|
|
{
|
|
var runtimeRegistration = new K3dRegistrationProbe().Probe();
|
|
var processInspectionAvailable = true;
|
|
var tornadoProcessCount = 0;
|
|
var programWindowDetected = false;
|
|
Process[] processes;
|
|
try
|
|
{
|
|
processes = Process.GetProcesses();
|
|
}
|
|
catch
|
|
{
|
|
processes = [];
|
|
processInspectionAvailable = false;
|
|
}
|
|
|
|
foreach (var process in processes)
|
|
{
|
|
try
|
|
{
|
|
if (!process.ProcessName.StartsWith("Tornado2", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
tornadoProcessCount++;
|
|
var title = process.MainWindowTitle;
|
|
if (title.Contains("PGM", StringComparison.OrdinalIgnoreCase) ||
|
|
title.Contains("PROGRAM", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
programWindowDetected = true;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// A process may exit or deny inspection between enumeration and reading.
|
|
}
|
|
finally
|
|
{
|
|
process.Dispose();
|
|
}
|
|
}
|
|
|
|
Console.WriteLine(JsonSerializer.Serialize(new
|
|
{
|
|
architecture = Environment.Is64BitProcess ? "x64" : "x86",
|
|
runtimeRegistration = new
|
|
{
|
|
ready = runtimeRegistration.IsReady,
|
|
issues = runtimeRegistration.Issues.ToString(),
|
|
engineClassReady = runtimeRegistration.IsEngineClassReady,
|
|
eventHandlerClassReady = runtimeRegistration.IsEventHandlerClassReady,
|
|
message = runtimeRegistration.Message
|
|
},
|
|
tornado = new
|
|
{
|
|
inspectionAvailable = processInspectionAvailable,
|
|
processCount = tornadoProcessCount,
|
|
programWindowDetected
|
|
},
|
|
safety = programWindowDetected
|
|
? "PROGRAM window detected; no COM activation was attempted."
|
|
: "Read-only probe complete; no COM activation was attempted."
|
|
}, new JsonSerializerOptions { WriteIndented = true }));
|
|
|
|
return runtimeRegistration.IsReady && Environment.Is64BitProcess
|
|
? 0
|
|
: 2;
|
|
}
|
|
|
|
static async Task<int> DryRunAsync()
|
|
{
|
|
var options = new PlayoutOptions { Mode = PlayoutMode.DryRun };
|
|
await using var engine = PlayoutEngineFactory.Create(options);
|
|
var cue = new PlayoutCue("DRY_RUN_ONLY.t2s", "DRY_RUN_ONLY");
|
|
|
|
var results = new[]
|
|
{
|
|
await engine.ConnectAsync(),
|
|
await engine.PrepareAsync(cue),
|
|
await engine.TakeInAsync(),
|
|
await engine.NextAsync(cue with { SceneName = "DRY_RUN_NEXT" }),
|
|
await engine.TakeOutAsync(PlayoutTakeOutScope.All),
|
|
await engine.DisconnectAsync()
|
|
};
|
|
|
|
Console.WriteLine(JsonSerializer.Serialize(new
|
|
{
|
|
mode = engine.Status.Mode.ToString(),
|
|
state = engine.Status.State.ToString(),
|
|
commands = results.Select(result => new
|
|
{
|
|
operation = result.Operation.ToString(),
|
|
code = result.Code.ToString(),
|
|
message = result.Message
|
|
})
|
|
}, new JsonSerializerOptions { WriteIndented = true }));
|
|
|
|
return results.All(result => result.IsSuccess) ? 0 : 3;
|
|
}
|
|
|
|
static int Usage()
|
|
{
|
|
Console.Error.WriteLine("Usage: MBN_STOCK_WEBVIEW.PlayoutSmoke [--probe|--dry-run]");
|
|
Console.Error.WriteLine("This tool never enables Test or Live mode and never activates K3D COM in dry-run.");
|
|
return 64;
|
|
}
|