JD2022-TU1/main/tools/apps/TeaBox/Script/Data/MapValidation/MapValidationMacros.cs

82 lines
No EOL
3.4 KiB
C#

using System.ComponentModel;
using System.Linq;
using JD.Asset.Types.Map;
using TeaBox.AssetValidation;
using TeaBox.Macros;
using TeaBox.SourceControl;
namespace TeaBox.MapValidation
{
[Module(Icon = "verify.png"), Category("Data"), DisplayName("Validations")]
public class MapValidationMacros
{
[Macro(Icon = "verify.png")]
[DisplayName("Validate maps")]
public static void RunMapValidations(
MapList maps,
[DefaultValue(true),
Description("If false, this macro will use your local data and could detect some errors that are already fixed."),
Category("Advanced")]
bool getLatestData,
[DefaultValue(false),
Description("If true, errors and warnings on maps will be fixed if possible (a changelist will be created)."),
Category("Advanced")]
bool autoFix,
[DefaultValue(""), Description("(Optional) When set, it will export as json instead of html"),
Category("Output")]
string jsonOutputFile,
[DefaultValue(true), Description("Indicates whether validation errors fail the macro result or not"),
Category("Output")]
bool logErrorsInTeaBox,
IExecutionContext context)
{
if (maps.Count == 0)
{
context.LogWarning("No maps, no work done.");
return;
}
if (getLatestData)
{
using (var steps = context.ExecuteSteps())
{
steps.AddStep($"Get latest data", step =>
{
foreach (var map in maps)
{
Source_ControlMacros.GetLatestData(step, syncEngine: false, maps: null, folder: map.Folder);
}
});
}
}
if (string.IsNullOrEmpty(jsonOutputFile))
{
var validator = new MapValidatorWithHtmlDigest { LogValidationSteps = logErrorsInTeaBox };
validator.RunAndOpenReport(context, maps, autoFix);
}
else
{
var validator = new AssetValidatorJson<Map> { LogValidationSteps = logErrorsInTeaBox };
validator.RunAndOpenReport(context, maps, autoFix, jsonOutputFile);
}
}
[Macro(Icon = "verify.png")]
[DisplayName(@"Validate all maps")]
public static void RunAllMapValidations(
[DefaultValue(true), Description("If false, this macro will use your local data and could detect some errors that are already fixed."), Category("Advanced")]
bool getLatestData,
[DefaultValue(""), Description("(Optional) When set, it will export as json instead of html"), Category("Advanced")]
string jsonOutputFile,
[DefaultValue(false), Description("Indicates whether validation errors fail the macro result or not"), Category("Advanced")]
bool logErrorsInTeaBox,
IExecutionContext context)
{
var allMaps = new MapList();
allMaps.AddRange(Map.AllMaps.Where(x => !x.Name.Contains("Test")).OrderBy(x => x.Name));
RunMapValidations(allMaps, getLatestData, false, jsonOutputFile, logErrorsInTeaBox, context);
}
}
}