ContainerProfile.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Xml.Serialization;
  6. namespace MediaBrowser.Model.Dlna
  7. {
  8. public class ContainerProfile
  9. {
  10. [Required]
  11. [XmlAttribute("type")]
  12. public DlnaProfileType Type { get; set; }
  13. public ProfileCondition[]? Conditions { get; set; } = Array.Empty<ProfileCondition>();
  14. [Required]
  15. [XmlAttribute("container")]
  16. public string Container { get; set; } = string.Empty;
  17. public static string[] SplitValue(string? value)
  18. {
  19. if (string.IsNullOrEmpty(value))
  20. {
  21. return Array.Empty<string>();
  22. }
  23. return value.Split(',', StringSplitOptions.RemoveEmptyEntries);
  24. }
  25. public bool ContainsContainer(string? container)
  26. {
  27. var containers = SplitValue(Container);
  28. return ContainsContainer(containers, container);
  29. }
  30. public static bool ContainsContainer(string? profileContainers, string? inputContainer)
  31. {
  32. var isNegativeList = false;
  33. if (profileContainers != null && profileContainers.StartsWith('-'))
  34. {
  35. isNegativeList = true;
  36. profileContainers = profileContainers.Substring(1);
  37. }
  38. return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
  39. }
  40. public static bool ContainsContainer(string[]? profileContainers, string? inputContainer)
  41. {
  42. return ContainsContainer(profileContainers, false, inputContainer);
  43. }
  44. public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
  45. {
  46. if (profileContainers == null || profileContainers.Length == 0)
  47. {
  48. return isNegativeList;
  49. }
  50. var allInputContainers = SplitValue(inputContainer);
  51. foreach (var container in allInputContainers)
  52. {
  53. if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
  54. {
  55. return !isNegativeList;
  56. }
  57. }
  58. return isNegativeList;
  59. }
  60. }
  61. }