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

41 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.ContainsKey(genType) ? GENERATORS[genType] : GENERATORS[genType] = new DotnetBigFile(),
_ => VOID_GENERATOR,
};
public static async Task<ProcessorResult<long>> TriggerAllAsync()
{
var dotnetEnabled = await AppSettings.GetGeneratorDotnetEnabled();
var godotEnabled = await AppSettings.GetGeneratorGodotEnabled();
long bytesWritten = 0;
if (dotnetEnabled)
{
var result = await Generator.Get(Type.DOTNET).GenerateAsync();
if(!result.Successful)
return result;
bytesWritten += result.Result;
}
if(godotEnabled)
{
var result = await Generator.Get(Type.GODOT).GenerateAsync();
if(!result.Successful)
return result;
bytesWritten += result.Result;
}
return new ProcessorResult<long>(bytesWritten);
}
}