ContainerProfile.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Xml.Serialization;
  3. using MediaBrowser.Model.Extensions;
  4. namespace MediaBrowser.Model.Dlna
  5. {
  6. public class ContainerProfile
  7. {
  8. [XmlAttribute("type")]
  9. public DlnaProfileType Type { get; set; }
  10. public ProfileCondition[] Conditions { get; set; }
  11. [XmlAttribute("container")]
  12. public string Container { get; set; }
  13. public ContainerProfile()
  14. {
  15. Conditions = Array.Empty<ProfileCondition>();
  16. }
  17. public string[] GetContainers()
  18. {
  19. return SplitValue(Container);
  20. }
  21. public static string[] SplitValue(string value)
  22. {
  23. if (string.IsNullOrEmpty(value))
  24. {
  25. return Array.Empty<string>();
  26. }
  27. return value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  28. }
  29. public bool ContainsContainer(string container)
  30. {
  31. var containers = GetContainers();
  32. return ContainsContainer(containers, container);
  33. }
  34. public static bool ContainsContainer(string profileContainers, string inputContainer)
  35. {
  36. var isNegativeList = false;
  37. if (profileContainers != null && profileContainers.StartsWith("-"))
  38. {
  39. isNegativeList = true;
  40. profileContainers = profileContainers.Substring(1);
  41. }
  42. return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
  43. }
  44. public static bool ContainsContainer(string[] profileContainers, string inputContainer)
  45. {
  46. return ContainsContainer(profileContainers, false, inputContainer);
  47. }
  48. public static bool ContainsContainer(string[] profileContainers, bool isNegativeList, string inputContainer)
  49. {
  50. if (profileContainers.Length == 0)
  51. {
  52. return true;
  53. }
  54. if (isNegativeList)
  55. {
  56. var allInputContainers = SplitValue(inputContainer);
  57. foreach (var container in allInputContainers)
  58. {
  59. if (ListHelper.ContainsIgnoreCase(profileContainers, container))
  60. {
  61. return false;
  62. }
  63. }
  64. return true;
  65. }
  66. else
  67. {
  68. var allInputContainers = SplitValue(inputContainer);
  69. foreach (var container in allInputContainers)
  70. {
  71. if (ListHelper.ContainsIgnoreCase(profileContainers, container))
  72. {
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78. }
  79. }
  80. }