ContainerProfile.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections.Generic;
  2. using System.Xml.Serialization;
  3. using MediaBrowser.Model.Dlna;
  4. using MediaBrowser.Model.Extensions;
  5. namespace MediaBrowser.Model.Dlna
  6. {
  7. public class ContainerProfile
  8. {
  9. [XmlAttribute("type")]
  10. public DlnaProfileType Type { get; set; }
  11. public ProfileCondition[] Conditions { get; set; }
  12. [XmlAttribute("container")]
  13. public string Container { get; set; }
  14. public ContainerProfile()
  15. {
  16. Conditions = new ProfileCondition[] { };
  17. }
  18. public List<string> GetContainers()
  19. {
  20. return SplitValue(Container);
  21. }
  22. public static List<string> SplitValue(string value)
  23. {
  24. List<string> list = new List<string>();
  25. foreach (string i in (value ?? string.Empty).Split(','))
  26. {
  27. if (!string.IsNullOrWhiteSpace(i)) list.Add(i);
  28. }
  29. return list;
  30. }
  31. public bool ContainsContainer(string container)
  32. {
  33. List<string> containers = GetContainers();
  34. return ContainsContainer(containers, container);
  35. }
  36. public static bool ContainsContainer(string profileContainers, string inputContainer)
  37. {
  38. return ContainsContainer(SplitValue(profileContainers), inputContainer);
  39. }
  40. public static bool ContainsContainer(List<string> profileContainers, string inputContainer)
  41. {
  42. if (profileContainers.Count == 0)
  43. {
  44. return true;
  45. }
  46. var allInputContainers = SplitValue(inputContainer);
  47. foreach (var container in allInputContainers)
  48. {
  49. if (ListHelper.ContainsIgnoreCase(profileContainers, container))
  50. {
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. }
  57. }