| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Contracts; |
| 4 | |
| 5 | namespace CascadeIDE.Cockpit.ComputingUnits.Launch; |
| 6 | |
| 7 | /// <summary> |
| 8 | /// CCU «готовность запуска» (pre-MSBuild): выбирает источник старта (профиль / startup project) |
| 9 | /// и фиксирует причину, если попытка разрешения цели невозможна. |
| 10 | /// </summary> |
| 11 | [ComputingUnit] |
| 12 | public sealed class LaunchReadinessUnit : ICockpitComputeUnit |
| 13 | { |
| 14 | public static LaunchReadinessUnit Default { get; } = new(); |
| 15 | |
| 16 | private LaunchReadinessUnit() |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | public LaunchReadinessSnapshot Compose( |
| 21 | bool hasSolutionPath, |
| 22 | bool hasWorkspaceRoot, |
| 23 | string? profileId, |
| 24 | string? profileProjectRelative, |
| 25 | string? profileProjectFullPath, |
| 26 | string? startupProjectFullPath) |
| 27 | { |
| 28 | if (!hasSolutionPath) |
| 29 | return LaunchReadinessSnapshot.NotReady("solution_missing"); |
| 30 | if (!hasWorkspaceRoot) |
| 31 | return LaunchReadinessSnapshot.NotReady("workspace_root_unresolved"); |
| 32 | |
| 33 | var hasProfileProject = !string.IsNullOrWhiteSpace(profileProjectFullPath); |
| 34 | var hasStartupProject = !string.IsNullOrWhiteSpace(startupProjectFullPath); |
| 35 | if (hasProfileProject) |
| 36 | { |
| 37 | return new LaunchReadinessSnapshot( |
| 38 | CanAttemptResolve: true, |
| 39 | Source: LaunchReadinessSource.Profile, |
| 40 | ReasonCode: null, |
| 41 | ProfileId: profileId, |
| 42 | ProfileProjectRelative: profileProjectRelative, |
| 43 | SelectedProjectFullPath: profileProjectFullPath); |
| 44 | } |
| 45 | |
| 46 | if (hasStartupProject) |
| 47 | { |
| 48 | return new LaunchReadinessSnapshot( |
| 49 | CanAttemptResolve: true, |
| 50 | Source: LaunchReadinessSource.StartupProject, |
| 51 | ReasonCode: null, |
| 52 | ProfileId: profileId, |
| 53 | ProfileProjectRelative: profileProjectRelative, |
| 54 | SelectedProjectFullPath: startupProjectFullPath); |
| 55 | } |
| 56 | |
| 57 | return LaunchReadinessSnapshot.NotReady( |
| 58 | !string.IsNullOrWhiteSpace(profileId) ? "profile_project_not_found" : "startup_project_missing", |
| 59 | profileId, |
| 60 | profileProjectRelative); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | public enum LaunchReadinessSource |
| 65 | { |
| 66 | None = 0, |
| 67 | Profile = 1, |
| 68 | StartupProject = 2 |
| 69 | } |
| 70 | |
| 71 | public readonly record struct LaunchReadinessSnapshot( |
| 72 | bool CanAttemptResolve, |
| 73 | LaunchReadinessSource Source, |
| 74 | string? ReasonCode, |
| 75 | string? ProfileId, |
| 76 | string? ProfileProjectRelative, |
| 77 | string? SelectedProjectFullPath) : ICockpitComputeUnitPayload |
| 78 | { |
| 79 | public static LaunchReadinessSnapshot NotReady( |
| 80 | string reasonCode, |
| 81 | string? profileId = null, |
| 82 | string? profileProjectRelative = null) => |
| 83 | new( |
| 84 | CanAttemptResolve: false, |
| 85 | Source: LaunchReadinessSource.None, |
| 86 | ReasonCode: reasonCode, |
| 87 | ProfileId: profileId, |
| 88 | ProfileProjectRelative: profileProjectRelative, |
| 89 | SelectedProjectFullPath: null); |
| 90 | } |
| 91 | |