ContainerProfile.cs 2.9 KB

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