From bfcd1b520fd79b893e721ba916ae5e1656407d2f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 16 Aug 2017 02:43:41 -0400 Subject: merge common implementations and server implementations --- Emby.Server.Implementations/IO/IsoManager.cs | 75 ++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Emby.Server.Implementations/IO/IsoManager.cs (limited to 'Emby.Server.Implementations/IO/IsoManager.cs') diff --git a/Emby.Server.Implementations/IO/IsoManager.cs b/Emby.Server.Implementations/IO/IsoManager.cs new file mode 100644 index 000000000..903d5f301 --- /dev/null +++ b/Emby.Server.Implementations/IO/IsoManager.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Model.IO; + +namespace Emby.Server.Implementations.IO +{ + /// + /// Class IsoManager + /// + public class IsoManager : IIsoManager + { + /// + /// The _mounters + /// + private readonly List _mounters = new List(); + + /// + /// Mounts the specified iso path. + /// + /// The iso path. + /// The cancellation token. + /// IsoMount. + /// isoPath + /// + public Task Mount(string isoPath, CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(isoPath)) + { + throw new ArgumentNullException("isoPath"); + } + + var mounter = _mounters.FirstOrDefault(i => i.CanMount(isoPath)); + + if (mounter == null) + { + throw new ArgumentException(string.Format("No mounters are able to mount {0}", isoPath)); + } + + return mounter.Mount(isoPath, cancellationToken); + } + + /// + /// Determines whether this instance can mount the specified path. + /// + /// The path. + /// true if this instance can mount the specified path; otherwise, false. + public bool CanMount(string path) + { + return _mounters.Any(i => i.CanMount(path)); + } + + /// + /// Adds the parts. + /// + /// The mounters. + public void AddParts(IEnumerable mounters) + { + _mounters.AddRange(mounters); + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + foreach (var mounter in _mounters) + { + mounter.Dispose(); + } + } + } +} -- cgit v1.2.3