using System; using System.Linq; using System.Threading.Tasks; using Sozsoft.Platform.Entities; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Sozsoft.Platform.Identity; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.Identity; using Volo.Abp.Users; namespace Sozsoft.Platform.Extensions; public class PlatformApplicationConfigurationContributor : IApplicationConfigurationContributor, ITransientDependency { public async Task ContributeAsync(ApplicationConfigurationContributorContext context) { var hostEnvironment = context.ServiceProvider.GetRequiredService(); context.ApplicationConfiguration.SetProperty("environment", hostEnvironment.EnvironmentName); var configuration = context.ServiceProvider.GetRequiredService(); context.ApplicationConfiguration.SetProperty("version", configuration.GetValue("App:Version")); var routeRepository = context.ServiceProvider.GetRequiredService>(); var items = await routeRepository.GetListAsync() ?? throw new EntityNotFoundException("RecordNotFound"); context.ApplicationConfiguration.SetProperty("routes", items); var customComponentRepository = context.ServiceProvider.GetRequiredService>(); var customComponents = await customComponentRepository.GetListAsync() ?? throw new EntityNotFoundException("RecordNotFound"); context.ApplicationConfiguration.SetProperty("customComponents", customComponents); var currentUser = context.ServiceProvider.GetRequiredService(); if (currentUser.Id.HasValue) { var sessionRepository = context.ServiceProvider.GetRequiredService(); var sessions = await sessionRepository.GetListAsync(userId: currentUser.Id.Value); var claimSessionId = currentUser.FindClaim(PlatformClaimTypes.SessionId.Key)?.Value; var sessionId = sessions.Exists(session => session.SessionId == claimSessionId) ? claimSessionId : sessions.OrderByDescending(session => session.SignedIn).FirstOrDefault()?.SessionId; context.ApplicationConfiguration.CurrentUser.SessionId = sessionId; context.ApplicationConfiguration.SetProperty("currentUserSessionId", sessionId); } } }