IsoManager.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using MediaBrowser.Model.IO;
  8. namespace Emby.Server.Implementations.IO
  9. {
  10. /// <summary>
  11. /// Class IsoManager.
  12. /// </summary>
  13. public class IsoManager : IIsoManager
  14. {
  15. /// <summary>
  16. /// The _mounters.
  17. /// </summary>
  18. private readonly List<IIsoMounter> _mounters = new List<IIsoMounter>();
  19. /// <summary>
  20. /// Mounts the specified iso path.
  21. /// </summary>
  22. /// <param name="isoPath">The iso path.</param>
  23. /// <param name="cancellationToken">The cancellation token.</param>
  24. /// <returns><see creaf="IsoMount" />.</returns>
  25. public Task<IIsoMount> Mount(string isoPath, CancellationToken cancellationToken)
  26. {
  27. if (string.IsNullOrEmpty(isoPath))
  28. {
  29. throw new ArgumentNullException(nameof(isoPath));
  30. }
  31. var mounter = _mounters.FirstOrDefault(i => i.CanMount(isoPath));
  32. if (mounter == null)
  33. {
  34. throw new ArgumentException(
  35. string.Format(
  36. CultureInfo.InvariantCulture,
  37. "No mounters are able to mount {0}",
  38. isoPath));
  39. }
  40. return mounter.Mount(isoPath, cancellationToken);
  41. }
  42. /// <summary>
  43. /// Determines whether this instance can mount the specified path.
  44. /// </summary>
  45. /// <param name="path">The path.</param>
  46. /// <returns><c>true</c> if this instance can mount the specified path; otherwise, <c>false</c>.</returns>
  47. public bool CanMount(string path)
  48. {
  49. return _mounters.Any(i => i.CanMount(path));
  50. }
  51. /// <summary>
  52. /// Adds the parts.
  53. /// </summary>
  54. /// <param name="mounters">The mounters.</param>
  55. public void AddParts(IEnumerable<IIsoMounter> mounters)
  56. {
  57. _mounters.AddRange(mounters);
  58. }
  59. }
  60. }