Files
mixtape/zero.Core/Configuration/Integrations/IntegrationOptions.cs
T

43 lines
1.2 KiB
C#
Raw Normal View History

2021-11-19 14:59:24 +01:00
using FluentValidation;
2021-11-20 13:52:28 +01:00
namespace zero.Configuration;
2021-11-19 14:59:24 +01:00
2021-11-24 15:49:25 +01:00
public class IntegrationOptions : List<IntegrationType>
2021-11-19 14:59:24 +01:00
{
2021-12-22 15:41:11 +01:00
public void Add<T>(string alias, string name, string description, string editorAlias = null, List<string> tags = default, string imagePath = null, IValidator validator = null) where T : Integration , new()
2021-11-19 14:59:24 +01:00
{
2021-11-24 15:49:25 +01:00
Add(new IntegrationType(typeof(T))
2021-11-19 14:59:24 +01:00
{
Alias = alias,
Name = name,
Description = description,
ImagePath = imagePath,
Tags = tags,
2021-12-22 00:14:48 +01:00
Validator = validator,
Construct = cfg => new T(),
EditorAlias = editorAlias
2021-11-19 14:59:24 +01:00
});
}
2021-12-22 00:14:48 +01:00
public void Add(Type type, string alias, string name, string description, string editorAlias = null, List<string> tags = default, string imagePath = null, IValidator validator = null)
2021-11-19 14:59:24 +01:00
{
2021-12-22 15:41:11 +01:00
if (!typeof(Integration).IsAssignableFrom(type))
{
throw new ArgumentException("Type has to inherit the Integration base model", nameof(type));
}
2021-11-24 15:49:25 +01:00
Add(new IntegrationType(type)
2021-11-19 14:59:24 +01:00
{
Alias = alias,
Name = name,
Description = description,
ImagePath = imagePath,
Tags = tags,
2021-12-22 00:14:48 +01:00
Validator = validator,
2021-12-22 15:41:11 +01:00
Construct = cfg => Activator.CreateInstance(type) as Integration,
2021-12-22 00:14:48 +01:00
EditorAlias = editorAlias
2021-11-19 14:59:24 +01:00
});
}
}