Forge
csharpdeeb25a2
1using CascadeIDE.Models;
2
3namespace CascadeIDE.Cockpit.Composition.HostSurface;
4
5internal readonly record struct InstrumentMountPolicyMatchContext(
6 string SurfaceId,
7 string SlotId,
8 string InstrumentId,
9 bool SurfaceExact,
10 bool SlotExact,
11 bool InstrumentExact);
12
13internal interface IInstrumentMountPolicyRuleSpecification
14{
15 bool IsSatisfiedBy(InstrumentMountPolicyRuleSettings rule, in InstrumentMountPolicyMatchContext context);
16}
17
18internal sealed class InstrumentMountPolicyRuleMatchesSpecification : IInstrumentMountPolicyRuleSpecification
19{
20 public bool IsSatisfiedBy(InstrumentMountPolicyRuleSettings rule, in InstrumentMountPolicyMatchContext context)
21 {
22 var ruleSurface = Normalize(rule.Surface);
23 var ruleSlot = Normalize(rule.Slot);
24 var ruleInstrument = Normalize(rule.Instrument);
25
26 var surfaceMatches = context.SurfaceExact
27 ? ruleSurface == context.SurfaceId
28 : IsWildcard(ruleSurface);
29 var slotMatches = context.SlotExact
30 ? ruleSlot == context.SlotId
31 : IsWildcard(ruleSlot);
32 var instrumentMatches = context.InstrumentExact
33 ? ruleInstrument == context.InstrumentId
34 : IsWildcard(ruleInstrument);
35
36 return surfaceMatches && slotMatches && instrumentMatches;
37 }
38
39 private static bool IsWildcard(string value) => value is "*" or "";
40
41 private static string Normalize(string? value) => (value ?? string.Empty).Trim().ToLowerInvariant();
42}
43
View only · write via MCP/CIDE