ContainerProfile.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 = new string[] { };
  24. public static string[] SplitValue(string value)
  25. {
  26. if (string.IsNullOrWhiteSpace(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. return ContainsContainer(SplitValue(profileContainers), inputContainer);
  40. }
  41. public static bool ContainsContainer(string[] profileContainers, string inputContainer)
  42. {
  43. if (profileContainers.Length == 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. }