suspend fun addAspireOrchestration()

in rider/src/main/kotlin/com/jetbrains/aspire/rider/orchestration/AspireOrchestrationService.kt [79:118]


    suspend fun addAspireOrchestration(
        projectEntities: List<ProjectModelEntity>,
    ) = withBackgroundProgress(project, AspireRiderBundle.message("progress.adding.aspire.orchestration")) {
        val existingAppHostEntity = findExistingAppHost()

        val appHostEntity = if (existingAppHostEntity != null) {
            LOG.trace { "Using existing AppHost" }
            existingAppHostEntity
        } else {
            LOG.trace { "Generating new AppHost project" }
            generateAppHost()
        }

        if (appHostEntity == null) {
            LOG.warn("Unable to find or generate AppHost project")
            return@withBackgroundProgress
        }

        val appHostFileWasModified = updateAppHostProject(appHostEntity, projectEntities)

        val projectsByType = projectEntities.groupBy { getProjectType(it) }
        var anyProjectModified = false

        for ((projectType, projects) in projectsByType) {
            if (projectType == null) continue

            val handler = AspireProjectOrchestrationHandler.getHandlerForType(projectType)
            if (handler != null) {
                LOG.trace { "Group of ${projects.size} projects of type $projectType using ${handler::class.simpleName}" }
                val modified = handler.generateServiceDefaultsAndModifyProjects(projects, project)
                anyProjectModified = anyProjectModified || modified
            } else {
                LOG.debug { "No handler found for project type: $projectType" }
            }
        }

        if (!appHostFileWasModified && !anyProjectModified) {
            notifyAboutAlreadyAddedOrchestration()
        }
    }