Merge pull request #5943 from Maxr1998/device-profile-defaults

(cherry picked from commit 9d3f614527)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
Bond-009
2021-05-05 00:40:32 +02:00
committed by Joshua M. Boniface
parent 9798bf29f3
commit 4c8df4c5bb
6 changed files with 115 additions and 124 deletions

View File

@@ -1,7 +1,7 @@
#nullable disable
#pragma warning disable CS1591
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Xml.Serialization;
@@ -9,25 +9,17 @@ namespace MediaBrowser.Model.Dlna
{
public class ContainerProfile
{
[Required]
[XmlAttribute("type")]
public DlnaProfileType Type { get; set; }
public ProfileCondition[] Conditions { get; set; }
public ProfileCondition[]? Conditions { get; set; } = Array.Empty<ProfileCondition>();
[Required]
[XmlAttribute("container")]
public string Container { get; set; }
public string Container { get; set; } = string.Empty;
public ContainerProfile()
{
Conditions = Array.Empty<ProfileCondition>();
}
public string[] GetContainers()
{
return SplitValue(Container);
}
public static string[] SplitValue(string value)
public static string[] SplitValue(string? value)
{
if (string.IsNullOrEmpty(value))
{
@@ -37,14 +29,14 @@ namespace MediaBrowser.Model.Dlna
return value.Split(',', StringSplitOptions.RemoveEmptyEntries);
}
public bool ContainsContainer(string container)
public bool ContainsContainer(string? container)
{
var containers = GetContainers();
var containers = SplitValue(Container);
return ContainsContainer(containers, container);
}
public static bool ContainsContainer(string profileContainers, string inputContainer)
public static bool ContainsContainer(string? profileContainers, string? inputContainer)
{
var isNegativeList = false;
if (profileContainers != null && profileContainers.StartsWith('-'))
@@ -56,46 +48,29 @@ namespace MediaBrowser.Model.Dlna
return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
}
public static bool ContainsContainer(string[] profileContainers, string inputContainer)
public static bool ContainsContainer(string[]? profileContainers, string? inputContainer)
{
return ContainsContainer(profileContainers, false, inputContainer);
}
public static bool ContainsContainer(string[] profileContainers, bool isNegativeList, string inputContainer)
public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
{
if (profileContainers.Length == 0)
if (profileContainers == null || profileContainers.Length == 0)
{
return true;
return isNegativeList;
}
if (isNegativeList)
{
var allInputContainers = SplitValue(inputContainer);
var allInputContainers = SplitValue(inputContainer);
foreach (var container in allInputContainers)
foreach (var container in allInputContainers)
{
if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
{
if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
{
return false;
}
return !isNegativeList;
}
return true;
}
else
{
var allInputContainers = SplitValue(inputContainer);
foreach (var container in allInputContainers)
{
if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
return isNegativeList;
}
}
}