2018-08-05 14:28:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.CustomFormats
|
|
|
|
|
{
|
|
|
|
|
public class CustomFormat : ModelBase, IEquatable<CustomFormat>
|
|
|
|
|
{
|
2019-12-18 21:56:41 +00:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public List<FormatTag> FormatTags { get; set; }
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
public CustomFormat()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CustomFormat(string name, params string[] tags)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
FormatTags = tags.Select(t => new FormatTag(t)).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 21:56:41 +00:00
|
|
|
|
public static implicit operator CustomFormatDefinition(CustomFormat format) => new CustomFormatDefinition { Id = format.Id, Name = format.Name, FormatTags = format.FormatTags };
|
2018-08-05 14:28:05 +00:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static CustomFormat None => new CustomFormat("None");
|
|
|
|
|
|
|
|
|
|
public bool Equals(CustomFormat other)
|
|
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
|
if (ReferenceEquals(null, other))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ReferenceEquals(this, other))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
|
return int.Equals(Id, other.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
|
if (ReferenceEquals(null, obj))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ReferenceEquals(this, obj))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj.GetType() != GetType())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Equals((CustomFormat)obj);
|
2018-08-05 14:28:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
2019-10-14 21:07:40 +00:00
|
|
|
|
return Id.GetHashCode();
|
2018-08-05 14:28:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-10 19:25:10 +00:00
|
|
|
|
|
|
|
|
|
public static class CustomFormatExtensions
|
|
|
|
|
{
|
|
|
|
|
public static string ToExtendedString(this IEnumerable<CustomFormat> formats)
|
|
|
|
|
{
|
|
|
|
|
return string.Join(", ", formats.Select(f => f.ToString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<CustomFormat> WithNone(this IEnumerable<CustomFormat> formats)
|
|
|
|
|
{
|
|
|
|
|
var list = formats.ToList();
|
2019-12-22 22:08:53 +00:00
|
|
|
|
if (list.Any())
|
|
|
|
|
{
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2018-09-10 19:25:10 +00:00
|
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
|
return new List<CustomFormat> { CustomFormat.None };
|
2018-09-10 19:25:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
|
}
|