2017-09-04 02:20:56 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Lidarr.Http.ClientSchema;
|
|
|
|
using Lidarr.Http.REST;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Common.Reflection;
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
2021-04-26 20:56:39 +00:00
|
|
|
public class ProviderResource<T> : RestResource
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
public string Name { get; set; }
|
|
|
|
public List<Field> Fields { get; set; }
|
|
|
|
public string ImplementationName { get; set; }
|
|
|
|
public string Implementation { get; set; }
|
|
|
|
public string ConfigContract { get; set; }
|
|
|
|
public string InfoLink { get; set; }
|
|
|
|
public ProviderMessage Message { get; set; }
|
|
|
|
public HashSet<int> Tags { get; set; }
|
|
|
|
|
2021-04-26 20:56:39 +00:00
|
|
|
public List<T> Presets { get; set; }
|
2017-09-04 02:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class ProviderResourceMapper<TProviderResource, TProviderDefinition>
|
2021-04-26 20:56:39 +00:00
|
|
|
where TProviderResource : ProviderResource<TProviderResource>, new()
|
2017-09-04 02:20:56 +00:00
|
|
|
where TProviderDefinition : ProviderDefinition, new()
|
|
|
|
{
|
|
|
|
public virtual TProviderResource ToResource(TProviderDefinition definition)
|
|
|
|
{
|
|
|
|
return new TProviderResource
|
|
|
|
{
|
|
|
|
Id = definition.Id,
|
|
|
|
|
|
|
|
Name = definition.Name,
|
|
|
|
ImplementationName = definition.ImplementationName,
|
|
|
|
Implementation = definition.Implementation,
|
|
|
|
ConfigContract = definition.ConfigContract,
|
|
|
|
Message = definition.Message,
|
|
|
|
Tags = definition.Tags,
|
|
|
|
Fields = SchemaBuilder.ToSchema(definition.Settings),
|
|
|
|
|
2020-12-17 22:17:26 +00:00
|
|
|
InfoLink = string.Format("https://wiki.servarr.com/Lidarr_Supported_{0}",
|
2017-09-04 02:20:56 +00:00
|
|
|
definition.Implementation.ToLower())
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual TProviderDefinition ToModel(TProviderResource resource)
|
|
|
|
{
|
2020-01-03 12:49:24 +00:00
|
|
|
if (resource == null)
|
|
|
|
{
|
|
|
|
return default(TProviderDefinition);
|
|
|
|
}
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
var definition = new TProviderDefinition
|
|
|
|
{
|
|
|
|
Id = resource.Id,
|
|
|
|
|
|
|
|
Name = resource.Name,
|
|
|
|
ImplementationName = resource.ImplementationName,
|
|
|
|
Implementation = resource.Implementation,
|
|
|
|
ConfigContract = resource.ConfigContract,
|
|
|
|
Message = resource.Message,
|
|
|
|
Tags = resource.Tags
|
|
|
|
};
|
|
|
|
|
|
|
|
var configContract = ReflectionExtensions.CoreAssembly.FindTypeByName(definition.ConfigContract);
|
|
|
|
definition.Settings = (IProviderConfig)SchemaBuilder.ReadFromSchema(resource.Fields, configContract);
|
|
|
|
|
|
|
|
return definition;
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 02:25:19 +00:00
|
|
|
}
|