IsoManager.cs 2.4 KB

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