ContainerProfile.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. [XmlAttribute("type")]
  11. public DlnaProfileType Type { get; set; }
  12. public ProfileCondition[]? Conditions { get; set; } = Array.Empty<ProfileCondition>();
  13. [XmlAttribute("container")]
  14. public string Container { get; set; } = string.Empty;
  15. public static string[] SplitValue(string? value)
  16. {
  17. if (string.IsNullOrEmpty(value))
  18. {
  19. return Array.Empty<string>();
  20. }
  21. return value.Split(',', StringSplitOptions.RemoveEmptyEntries);
  22. }
  23. public bool ContainsContainer(string? container)
  24. {
  25. var containers = SplitValue(Container);
  26. return ContainsContainer(containers, container);
  27. }
  28. public static bool ContainsContainer(string? profileContainers, string? inputContainer)
  29. {
  30. var isNegativeList = false;
  31. if (profileContainers != null && profileContainers.StartsWith('-'))
  32. {
  33. isNegativeList = true;
  34. profileContainers = profileContainers.Substring(1);
  35. }
  36. return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
  37. }
  38. public static bool ContainsContainer(string[]? profileContainers, string? inputContainer)
  39. {
  40. return ContainsContainer(profileContainers, false, inputContainer);
  41. }
  42. public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
  43. {
  44. if (profileContainers == null || profileContainers.Length == 0)
  45. {
  46. return isNegativeList;
  47. }
  48. var allInputContainers = SplitValue(inputContainer);
  49. foreach (var container in allInputContainers)
  50. {
  51. if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
  52. {
  53. return !isNegativeList;
  54. }
  55. }
  56. return isNegativeList;
  57. }
  58. }
  59. }