| 1 | using CascadeIDE.Cockpit.DataBus; |
| 2 | using CascadeIDE.Contracts; |
| 3 | using CascadeIDE.Features.SolutionWarmup.Application; |
| 4 | using CascadeIDE.Models; |
| 5 | using CommunityToolkit.Mvvm.ComponentModel; |
| 6 | |
| 7 | namespace CascadeIDE.ViewModels; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Solution warm-up: оркестратор фаз загрузки решения, лампа статуса и подписка на DataBus (ADR 0141). |
| 11 | /// </summary> |
| 12 | public partial class MainWindowViewModel |
| 13 | { |
| 14 | private SolutionWarmupOrchestrator? _solutionWarmup; |
| 15 | private IDisposable? _solutionWarmupStateSubscription; |
| 16 | |
| 17 | [ObservableProperty] |
| 18 | [NotifyPropertyChangedFor(nameof(SolutionWarmupStatusText))] |
| 19 | [NotifyPropertyChangedFor(nameof(SolutionWarmupLampItem))] |
| 20 | [NotifyPropertyChangedFor(nameof(HybridIndexMsgLine2), nameof(SolutionWarmupStatusText), nameof(ShowPfdBackgroundStatusBar))] |
| 21 | private SolutionWarmupStateChanged? _solutionWarmupLast; |
| 22 | |
| 23 | public string SolutionWarmupStatusText => |
| 24 | SolutionWarmupHisPresentationProjection.StatusLine(SolutionWarmupLast); |
| 25 | |
| 26 | public AnnunciatorLampItem SolutionWarmupLampItem => |
| 27 | SolutionWarmupHisPresentationProjection.LampItem(SolutionWarmupLast); |
| 28 | |
| 29 | private void EnsureSolutionWarmupOrchestrator() |
| 30 | { |
| 31 | if (_solutionWarmup is not null) |
| 32 | return; |
| 33 | |
| 34 | _solutionWarmup = new SolutionWarmupOrchestrator( |
| 35 | _ideDataBus, |
| 36 | new SolutionWarmupHostCallbacks |
| 37 | { |
| 38 | GetActiveCsFilePath = () => CurrentFilePath, |
| 39 | GetOpenCsFilePaths = () => Documents.OpenDocuments |
| 40 | .Select(d => d.FilePath) |
| 41 | .Where(p => !string.IsNullOrWhiteSpace(p)) |
| 42 | .ToList(), |
| 43 | RunFeedAnchorsOnUi = () => UiScheduler.Default.Post( |
| 44 | () => ChatPanel.RefreshAttachmentAnchorsForCurrentScope(), |
| 45 | Avalonia.Threading.DispatcherPriority.Background), |
| 46 | GetWarmupSettings = () => _settings.SolutionWarmup, |
| 47 | GetHybridIndexSettings = () => _settings.HybridIndex, |
| 48 | GetLatestHybridIndexState = () => HybridIndexLast, |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | private void EnsureSolutionWarmupSubscription() |
| 53 | { |
| 54 | if (_solutionWarmupStateSubscription is not null) |
| 55 | return; |
| 56 | |
| 57 | _solutionWarmupStateSubscription = SolutionWarmupStateBusSubscription.Subscribe( |
| 58 | _ideDataBus, |
| 59 | UiScheduler.Default, |
| 60 | evt => SolutionWarmupLast = evt); |
| 61 | } |
| 62 | |
| 63 | private void ApplySolutionWarmupForCurrentSolution() |
| 64 | { |
| 65 | EnsureSolutionWarmupOrchestrator(); |
| 66 | EnsureSolutionWarmupSubscription(); |
| 67 | |
| 68 | var value = Workspace.SolutionPath ?? ""; |
| 69 | var ws = WorkspaceDirectoryFromSolutionPath.Resolve(value); |
| 70 | _solutionWarmup!.OnSolutionScopeChanged(ws, string.IsNullOrWhiteSpace(value) ? null : value); |
| 71 | } |
| 72 | } |
| 73 | |