|
|
@ -3,11 +3,13 @@ using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
using DryIoc;
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
|
using NzbDrone.Common.EnsureThat;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Common.Reflection;
|
|
|
|
using NzbDrone.Common.Reflection;
|
|
|
|
using NzbDrone.Common.Serializer;
|
|
|
|
using NzbDrone.Common.Serializer;
|
|
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Localization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Lidarr.Http.ClientSchema
|
|
|
|
namespace Lidarr.Http.ClientSchema
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -15,6 +17,12 @@ namespace Lidarr.Http.ClientSchema
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private const string PRIVATE_VALUE = "********";
|
|
|
|
private const string PRIVATE_VALUE = "********";
|
|
|
|
private static Dictionary<Type, FieldMapping[]> _mappings = new Dictionary<Type, FieldMapping[]>();
|
|
|
|
private static Dictionary<Type, FieldMapping[]> _mappings = new Dictionary<Type, FieldMapping[]>();
|
|
|
|
|
|
|
|
private static ILocalizationService _localizationService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void Initialize(IContainer container)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_localizationService = container.Resolve<ILocalizationService>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<Field> ToSchema(object model)
|
|
|
|
public static List<Field> ToSchema(object model)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -106,13 +114,27 @@ namespace Lidarr.Http.ClientSchema
|
|
|
|
if (propertyInfo.PropertyType.IsSimpleType())
|
|
|
|
if (propertyInfo.PropertyType.IsSimpleType())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var fieldAttribute = property.Item2;
|
|
|
|
var fieldAttribute = property.Item2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var label = fieldAttribute.Label.IsNotNullOrWhiteSpace()
|
|
|
|
|
|
|
|
? _localizationService.GetLocalizedString(fieldAttribute.Label,
|
|
|
|
|
|
|
|
GetTokens(type, fieldAttribute.Label, TokenField.Label))
|
|
|
|
|
|
|
|
: fieldAttribute.Label;
|
|
|
|
|
|
|
|
var helpText = fieldAttribute.HelpText.IsNotNullOrWhiteSpace()
|
|
|
|
|
|
|
|
? _localizationService.GetLocalizedString(fieldAttribute.HelpText,
|
|
|
|
|
|
|
|
GetTokens(type, fieldAttribute.Label, TokenField.HelpText))
|
|
|
|
|
|
|
|
: fieldAttribute.HelpText;
|
|
|
|
|
|
|
|
var helpTextWarning = fieldAttribute.HelpTextWarning.IsNotNullOrWhiteSpace()
|
|
|
|
|
|
|
|
? _localizationService.GetLocalizedString(fieldAttribute.HelpTextWarning,
|
|
|
|
|
|
|
|
GetTokens(type, fieldAttribute.Label, TokenField.HelpTextWarning))
|
|
|
|
|
|
|
|
: fieldAttribute.HelpTextWarning;
|
|
|
|
|
|
|
|
|
|
|
|
var field = new Field
|
|
|
|
var field = new Field
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name = prefix + GetCamelCaseName(propertyInfo.Name),
|
|
|
|
Name = prefix + GetCamelCaseName(propertyInfo.Name),
|
|
|
|
Label = fieldAttribute.Label,
|
|
|
|
Label = label,
|
|
|
|
Unit = fieldAttribute.Unit,
|
|
|
|
Unit = fieldAttribute.Unit,
|
|
|
|
HelpText = fieldAttribute.HelpText,
|
|
|
|
HelpText = helpText,
|
|
|
|
HelpTextWarning = fieldAttribute.HelpTextWarning,
|
|
|
|
HelpTextWarning = helpTextWarning,
|
|
|
|
HelpLink = fieldAttribute.HelpLink,
|
|
|
|
HelpLink = fieldAttribute.HelpLink,
|
|
|
|
Order = fieldAttribute.Order,
|
|
|
|
Order = fieldAttribute.Order,
|
|
|
|
Advanced = fieldAttribute.Advanced,
|
|
|
|
Advanced = fieldAttribute.Advanced,
|
|
|
@ -172,6 +194,24 @@ namespace Lidarr.Http.ClientSchema
|
|
|
|
.ToArray();
|
|
|
|
.ToArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Dictionary<string, object> GetTokens(Type type, string label, TokenField field)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var tokens = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var propertyInfo in type.GetProperties())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var attribute in propertyInfo.GetCustomAttributes(true))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (attribute is FieldTokenAttribute fieldTokenAttribute && fieldTokenAttribute.Field == field && fieldTokenAttribute.Label == label)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tokens.Add(fieldTokenAttribute.Token, fieldTokenAttribute.Value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tokens;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static List<SelectOption> GetSelectOptions(Type selectOptions)
|
|
|
|
private static List<SelectOption> GetSelectOptions(Type selectOptions)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (selectOptions.IsEnum)
|
|
|
|
if (selectOptions.IsEnum)
|
|
|
|