2026-02-24 20:44:16 +00:00
|
|
|
|
using System;
|
2026-06-19 08:49:49 +00:00
|
|
|
|
using System.Linq;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Sozsoft.Platform.Entities;
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2026-06-19 08:49:49 +00:00
|
|
|
|
using Sozsoft.Platform.Identity;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
|
|
|
|
|
|
using Volo.Abp.Data;
|
|
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
|
using Volo.Abp.Domain.Entities;
|
|
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
2026-06-19 08:49:49 +00:00
|
|
|
|
using Volo.Abp.Identity;
|
|
|
|
|
|
using Volo.Abp.Users;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Sozsoft.Platform.Extensions;
|
|
|
|
|
|
|
|
|
|
|
|
public class PlatformApplicationConfigurationContributor : IApplicationConfigurationContributor, ITransientDependency
|
|
|
|
|
|
{
|
|
|
|
|
|
public async Task ContributeAsync(ApplicationConfigurationContributorContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
var hostEnvironment = context.ServiceProvider.GetRequiredService<IHostEnvironment>();
|
|
|
|
|
|
context.ApplicationConfiguration.SetProperty("environment", hostEnvironment.EnvironmentName);
|
|
|
|
|
|
|
|
|
|
|
|
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
|
|
|
|
|
|
context.ApplicationConfiguration.SetProperty("version", configuration.GetValue<string>("App:Version"));
|
|
|
|
|
|
|
|
|
|
|
|
var routeRepository = context.ServiceProvider.GetRequiredService<IRepository<Route, Guid>>();
|
|
|
|
|
|
var items = await routeRepository.GetListAsync() ?? throw new EntityNotFoundException("RecordNotFound");
|
|
|
|
|
|
context.ApplicationConfiguration.SetProperty("routes", items);
|
|
|
|
|
|
|
|
|
|
|
|
var customComponentRepository = context.ServiceProvider.GetRequiredService<IRepository<CustomComponent, Guid>>();
|
|
|
|
|
|
var customComponents = await customComponentRepository.GetListAsync() ?? throw new EntityNotFoundException("RecordNotFound");
|
|
|
|
|
|
context.ApplicationConfiguration.SetProperty("customComponents", customComponents);
|
2026-06-19 08:49:49 +00:00
|
|
|
|
|
|
|
|
|
|
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
|
|
|
|
|
|
if (currentUser.Id.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
var sessionRepository = context.ServiceProvider.GetRequiredService<IIdentitySessionRepository>();
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|