I18NCommander/I18N Commander/Processor/Generators/Generator.cs

39 lines
1.3 KiB
C#

namespace Processor.Generators;
public static class Generator
{
private static readonly Dictionary<Type, IGenerator> GENERATORS = new();
private static readonly IGenerator VOID_GENERATOR = new VoidGenerator();
public static IGenerator Get(Type genType) => genType switch
{
Type.DOTNET => GENERATORS.TryGetValue(genType, out var value) ? value : GENERATORS[genType] = new DotnetBigFile(),
Type.GODOT => GENERATORS.TryGetValue(genType, out var value) ? value : GENERATORS[genType] = new GodotCSV(),
_ => VOID_GENERATOR,
};
public static async Task<ProcessorResult<long>> TriggerAllAsync()
{
long bytesWritten = 0;
if (await AppSettings.GetGeneratorDotnetEnabled())
{
var result = await Generator.Get(Type.DOTNET).GenerateAsync();
if(!result.Successful)
return result;
bytesWritten += result.Result;
}
if(await AppSettings.GetGeneratorGodotEnabled())
{
var result = await Generator.Get(Type.GODOT).GenerateAsync();
if(!result.Successful)
return result;
bytesWritten += result.Result;
}
return new ProcessorResult<long>(bytesWritten);
}
}