namespace Yes.Application.Admins.Themes { public record GetThemesQuery() : IRequest>; public record GetThemesQueryResponse( string Name, string Version, string Author, string Description, string Homepage, string DirName, bool IsInUse ); public class GetThemesQueryHandler(IOptionsMonitor options, IMapper mapper, IWebHostEnvironment env) : IRequestHandler> { private readonly BlogSettings _settings = options.CurrentValue; private readonly IMapper _mapper = mapper; private readonly IWebHostEnvironment _env = env; public async Task> Handle(GetThemesQuery request, CancellationToken cancellationToken) { var themes = new List(); var themePath = Path.Combine(_env.ContentRootPath, "files", "themes"); var directories = Directory.GetDirectories(themePath); foreach (var directory in directories) { DirectoryInfo dir = new DirectoryInfo(directory); var jsonPath = Path.Combine(directory, "config.json"); if(!File.Exists(jsonPath)) continue; var json = File.ReadAllText(jsonPath); var theme = JsonConvert.DeserializeObject(json); theme.DirName = dir.Name; if (theme.DirName == _settings.Theme) { theme.IsInUse = true; } themes.Add(_mapper.Map(theme)); } themes = themes.OrderByDescending(x=>x.IsInUse).ToList(); return themes; } } }