You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/src/Sonarr.Api.V3/ProviderResource.cs

71 lines
2.5 KiB

8 years ago
using System.Collections.Generic;
using NzbDrone.Common.Reflection;
using NzbDrone.Core.ThingiProvider;
using Sonarr.Http.ClientSchema;
using Sonarr.Http.REST;
namespace Sonarr.Api.V3
{
public class ProviderResource<T> : RestResource
8 years ago
{
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; }
public List<T> Presets { get; set; }
8 years ago
}
public class ProviderResourceMapper<TProviderResource, TProviderDefinition>
where TProviderResource : ProviderResource<TProviderResource>, new()
8 years ago
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),
InfoLink = $"https://wiki.servarr.com/sonarr/supported#{definition.Implementation.ToLower()}"
8 years ago
};
}
public virtual TProviderDefinition ToModel(TProviderResource resource)
{
3 years ago
if (resource == null)
{
return default(TProviderDefinition);
}
8 years ago
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;
}
}
3 years ago
}