ISystemProbe.cs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. namespace RackPeek.Domain.Discovery;
  2. /// <summary>
  3. /// Reads raw facts off the host. The only platform-specific code in discovery, and
  4. /// deliberately the only part that is not unit tested — it does IO and nothing else.
  5. /// </summary>
  6. public interface ISystemProbe {
  7. /// <summary>True when this probe can run on the current host.</summary>
  8. bool IsSupported { get; }
  9. Task<RawSystemSnapshot> ReadAsync(CancellationToken cancellationToken = default);
  10. }
  11. /// <summary>
  12. /// Probe selection, shared by every collector so they all describe the host — and
  13. /// seed discovery ids — identically.
  14. /// </summary>
  15. public static class SystemProbes {
  16. /// <summary>Facts from the first supported probe, or null on an unsupported platform.</summary>
  17. public static async Task<SystemFacts?> TryReadHostAsync(
  18. IEnumerable<ISystemProbe> probes,
  19. CancellationToken cancellationToken) {
  20. ISystemProbe? probe = probes.FirstOrDefault(p => p.IsSupported);
  21. if (probe == null)
  22. return null;
  23. return SystemFactsParser.Parse(await probe.ReadAsync(cancellationToken));
  24. }
  25. }