sozsoft-platform/api/src/Sozsoft.Platform.Domain/BackgroundWorkers/PlatformTemplateManager.cs

34 lines
1.1 KiB
C#
Raw Normal View History

2026-02-24 20:44:16 +00:00
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
using Volo.Abp.TextTemplating;
using Volo.Abp.TextTemplating.Razor;
namespace Sozsoft.Platform.BackgroundWorkers;
public class PlatformTemplateManager : DomainService
{
private readonly ITemplateDefinitionManager templateDefinitionManager;
public PlatformTemplateManager(ITemplateDefinitionManager templateDefinitionManager)
{
this.templateDefinitionManager = templateDefinitionManager;
}
public async Task AddOrUpdateTemplateAsync(string name, string template)
{
var templateDefinition = await templateDefinitionManager.GetOrNullAsync(name);
if (templateDefinition == null)
{
templateDefinition = new TemplateDefinition(name)
.WithRazorEngine()
.WithProperty(PropertyTemplateContentContributor.PropertyContentPropertyName, template);
PlatformTemplateDynamicStore.TemplateDefinitions.Add(name, templateDefinition);
}
else
{
templateDefinition.WithProperty(PropertyTemplateContentContributor.PropertyContentPropertyName, template);
}
}
}