ContainerProfile.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 List<string> GetContainers()
  20. {
  21. return SplitValue(Container);
  22. }
  23. public static List<string> SplitValue(string value)
  24. {
  25. List<string> list = new List<string>();
  26. foreach (string i in (value ?? string.Empty).Split(','))
  27. {
  28. if (!string.IsNullOrWhiteSpace(i)) list.Add(i);
  29. }
  30. return list;
  31. }
  32. public bool ContainsContainer(string container)
  33. {
  34. List<string> containers = GetContainers();
  35. return ContainsContainer(containers, container);
  36. }
  37. public static bool ContainsContainer(string profileContainers, string inputContainer)
  38. {
  39. return ContainsContainer(SplitValue(profileContainers), inputContainer);
  40. }
  41. public static bool ContainsContainer(List<string> profileContainers, string inputContainer)
  42. {
  43. if (profileContainers.Count == 0)
  44. {
  45. return true;
  46. }
  47. var allInputContainers = SplitValue(inputContainer);
  48. foreach (var container in allInputContainers)
  49. {
  50. if (ListHelper.ContainsIgnoreCase(profileContainers, container))
  51. {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. }
  58. }