<# OMIKA - Demarrage complet en mode test local ============================================ Compile puis lance les 3 composants du projet : 1. Omika.Api (API) -> http://localhost:5097 2. Omika.Worker (sync) -> service d'arriere-plan 3. Omika.App.Desktop (application) -> fenetre Avalonia Mode test = environnement "Development" : - charge config/hfsql-test.local.json (connexions HFSQL locales de test) ; - l'application de bureau utilise la licence de developpement locale (%LOCALAPPDATA%\Omika\development-license.json, dont le champ ApiUrl pointe vers http://localhost:5097). Utilisation : powershell -NoProfile -ExecutionPolicy Bypass -File .\docs\start_omika_test.ps1 .\docs\start_omika_test.ps1 -NoBuild # sans recompiler .\docs\start_omika_test.ps1 -SkipDesktop # sans l'application de bureau .\docs\start_omika_test.ps1 -SkipWorker # sans le Worker .\docs\start_omika_test.ps1 -Clean # purge la SQLite locale avant lancement Pour arreter : .\docs\stop_omika_test.ps1 #> [CmdletBinding()] param( [switch]$NoBuild, [switch]$SkipDesktop, [switch]$SkipWorker, [switch]$Clean ) $ErrorActionPreference = 'Stop' # Racine du depot = parent du dossier docs/ contenant ce script. $root = Split-Path -Parent $PSScriptRoot # Fichiers de logs (racine du depot). $logApiOut = Join-Path $root 'omika-test-api.out.log' $logApiErr = Join-Path $root 'omika-test-api.err.log' $logWorkerOut = Join-Path $root 'omika-test-worker.out.log' $logWorkerErr = Join-Path $root 'omika-test-worker.err.log' $logDesktopOut = Join-Path $root 'omika-test-desktop.out.log' $logDesktopErr = Join-Path $root 'omika-test-desktop.err.log' function Reset-Log([string]$Path) { if (Test-Path $Path) { Remove-Item $Path -Force -ErrorAction SilentlyContinue } } function Banner([string]$Text) { Write-Host '' Write-Host '============================================================' -ForegroundColor Cyan Write-Host " $Text" -ForegroundColor Cyan Write-Host '============================================================' -ForegroundColor Cyan } Banner 'OMIKA - Demarrage en mode test local' # ---------- Preparation de la config locale de l'application de bureau ---------- $appData = Join-Path $env:LOCALAPPDATA 'Omika' if (-not (Test-Path $appData)) { New-Item -ItemType Directory -Path $appData | Out-Null } # ---------- Nettoyage optionnel de la base SQLite locale (-Clean) ---------- # Uniquement lors d'un changement d'environnement (ex. Batik -> Omika) : repartir # avec une base locale vierge pour ne pas melanger les snapshots de deux bases. # Ne supprime JAMAIS development-license.json, ni documents/, ni logs/. if ($Clean) { Write-Host '' Write-Host 'Nettoyage de la base SQLite locale (-Clean)...' -ForegroundColor Yellow foreach ($db in @('omika.db', 'omika-diagnostics.db')) { $dbPath = Join-Path $appData $db if (Test-Path $dbPath) { Remove-Item -Path $dbPath -Force -ErrorAction SilentlyContinue if (Test-Path $dbPath) { Write-Warning " Impossible de supprimer (fichier verrouille ?) : $dbPath" } else { Write-Host " Supprime : $dbPath" -ForegroundColor Green } } } } $devLicenseConfig = Join-Path $appData 'development-license.json' $devLicenseApiUrl = 'http://localhost:5097' if (-not (Test-Path $devLicenseConfig)) { [ordered]@{ Enabled = $true ClientCode = 'LOCAL-DEV' UserDisplayName = 'Alexandre SALVADOR (ASA)' ExpirationDays = 365 ApiUrl = $devLicenseApiUrl } | ConvertTo-Json | Set-Content -Path $devLicenseConfig -Encoding UTF8 Write-Host " Config creee : $devLicenseConfig" -ForegroundColor Yellow } else { # Le fichier existe : si le champ ApiUrl est absent ou vide, on l'ajoute # proprement (sans ecraser les autres champs). Necessaire au flux # DevelopmentLicense, qui lit ApiUrl pour joindre l'API locale. try { $license = Get-Content -Raw -Path $devLicenseConfig | ConvertFrom-Json if ($null -eq $license.PSObject.Properties['ApiUrl'] -or [string]::IsNullOrWhiteSpace($license.ApiUrl)) { $license | Add-Member -NotePropertyName 'ApiUrl' -NotePropertyValue $devLicenseApiUrl -Force $license | ConvertTo-Json | Set-Content -Path $devLicenseConfig -Encoding UTF8 Write-Host " ApiUrl ajoute a : $devLicenseConfig" -ForegroundColor Yellow } } catch { Write-Warning " $devLicenseConfig illisible : laisse tel quel." } } $hfsqlConfig = Join-Path $root 'config\hfsql-test.local.json' if (-not (Test-Path $hfsqlConfig)) { Write-Warning "config/hfsql-test.local.json introuvable : l'API et le Worker n'utiliseront pas la configuration HFSQL de test." } # ---------- 1. Compilation ---------- if ($NoBuild) { Write-Host '' Write-Host 'Compilation ignoree (-NoBuild).' -ForegroundColor DarkGray } else { Banner '1/4 - Compilation des projets (Debug)' $projects = @( (Join-Path $root 'src\Omika.Api\Omika.Api.csproj'), (Join-Path $root 'src\Omika.Worker\Omika.Worker.csproj'), (Join-Path $root 'src\Omika.App.Desktop\Omika.App.Desktop.csproj') ) foreach ($project in $projects) { Write-Host " > $project" -ForegroundColor Yellow # CONTOURNEMENT TEMPORAIRE : --no-restore -m:1 evite l'echec MSB4276 lie au # workload Android/iOS corrompu de cette machine (resolution SDK parallele). # A retirer apres 'dotnet workload repair'. dotnet build $project -c Debug --nologo --no-restore -m:1 if ($LASTEXITCODE -ne 0) { throw "Echec de compilation : $project" } } } # Environnement de test : Development (charge config/hfsql-test.local.json). $env:ASPNETCORE_ENVIRONMENT = 'Development' $env:DOTNET_ENVIRONMENT = 'Development' # ---------- 2. API ---------- Banner "2/4 - Demarrage de l'API (http://localhost:5097)" Reset-Log $logApiOut; Reset-Log $logApiErr $env:ASPNETCORE_URLS = 'http://localhost:5097' $api = Start-Process -FilePath 'dotnet' ` -ArgumentList (Join-Path $root 'src\Omika.Api\bin\Debug\net10.0\Omika.Api.dll') ` -WorkingDirectory (Join-Path $root 'src\Omika.Api\bin\Debug\net10.0') ` -RedirectStandardOutput $logApiOut ` -RedirectStandardError $logApiErr ` -NoNewWindow -PassThru Write-Host " API demarree (PID $($api.Id))." -ForegroundColor Green # ---------- 3. Worker ---------- if ($SkipWorker) { Write-Host 'Worker ignore (-SkipWorker).' -ForegroundColor DarkGray } else { Banner '3/4 - Demarrage du Worker de synchronisation' Reset-Log $logWorkerOut; Reset-Log $logWorkerErr $worker = Start-Process -FilePath 'dotnet' ` -ArgumentList (Join-Path $root 'src\Omika.Worker\bin\Debug\net10.0\Omika.Worker.dll') ` -WorkingDirectory (Join-Path $root 'src\Omika.Worker\bin\Debug\net10.0') ` -RedirectStandardOutput $logWorkerOut ` -RedirectStandardError $logWorkerErr ` -NoNewWindow -PassThru Write-Host " Worker demarre (PID $($worker.Id))." -ForegroundColor Green } # ---------- 4. Application desktop ---------- if ($SkipDesktop) { Write-Host 'Application desktop ignoree (-SkipDesktop).' -ForegroundColor DarkGray } else { Banner "4/4 - Demarrage de l'application de bureau" Reset-Log $logDesktopOut; Reset-Log $logDesktopErr $desktop = Start-Process -FilePath (Join-Path $root 'src\Omika.App.Desktop\bin\Debug\net10.0\Omika.App.Desktop.exe') ` -WorkingDirectory (Join-Path $root 'src\Omika.App.Desktop\bin\Debug\net10.0') ` -RedirectStandardOutput $logDesktopOut ` -RedirectStandardError $logDesktopErr ` -PassThru Write-Host " Application de bureau demarree (PID $($desktop.Id))." -ForegroundColor Green } # ---------- Verification ---------- Banner 'Verification' Write-Host " Attente de quelques secondes avant le controle de sante de l'API..." -ForegroundColor Yellow Start-Sleep -Seconds 6 try { $health = Invoke-RestMethod -Uri 'http://localhost:5097/health' -TimeoutSec 10 Write-Host " /health => $($health | ConvertTo-Json -Compress)" -ForegroundColor Green } catch { Write-Warning " Impossible de joindre http://localhost:5097/health : $($_.Exception.Message)" Write-Host " Consultez les logs : $logApiOut / $logApiErr" -ForegroundColor DarkGray } Banner 'Termine' Write-Host ' Logs :' -ForegroundColor Cyan Write-Host " API : $logApiOut" -ForegroundColor Cyan Write-Host " Worker : $logWorkerOut" -ForegroundColor Cyan Write-Host " Desktop : $logDesktopOut" -ForegroundColor Cyan Write-Host ' Pour arreter : .\docs\stop_omika_test.ps1' -ForegroundColor Cyan