IsoManager.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using MediaBrowser.Model.IO;
  7. namespace Emby.Server.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. GC.SuppressFinalize(this);
  66. }
  67. }
  68. }