diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 91965e469..202bd3cab 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -197,7 +197,6 @@ namespace MediaBrowser.Common.Kernel /// Gets the web socket listeners. /// /// The web socket listeners. - [ImportMany(typeof(IWebSocketListener))] public IEnumerable WebSocketListeners { get; private set; } /// @@ -236,6 +235,11 @@ namespace MediaBrowser.Common.Kernel /// The rest services. public IEnumerable RestServices { get; private set; } + /// + /// The disposable parts + /// + private readonly List _disposableParts = new List(); + /// /// The _protobuf serializer initialized /// @@ -497,6 +501,7 @@ namespace MediaBrowser.Common.Kernel protected virtual void ComposePartsWithIocContainer(Type[] allTypes, Container container) { RestServices = GetExports(allTypes); + WebSocketListeners = GetExports(allTypes); } /// @@ -511,7 +516,11 @@ namespace MediaBrowser.Common.Kernel Logger.Info("Composing instances of " + currentType.Name); - return allTypes.Where(currentType.IsAssignableFrom).Select(Instantiate).Cast().ToArray(); + var parts = allTypes.Where(currentType.IsAssignableFrom).Select(Instantiate).Cast().ToArray(); + + _disposableParts.AddRange(parts.OfType()); + + return parts; } /// @@ -528,6 +537,7 @@ namespace MediaBrowser.Common.Kernel /// Composes the exported values. /// /// The container. + /// protected virtual void ComposeExportedValues(CompositionContainer container, Container iocContainer) { container.ComposeExportedValue("logger", Logger); @@ -733,6 +743,13 @@ namespace MediaBrowser.Common.Kernel DisposeHttpManager(); DisposeComposableParts(); + + foreach (var part in _disposableParts) + { + part.Dispose(); + } + + _disposableParts.Clear(); } } diff --git a/MediaBrowser.Common/Kernel/IWebSocketListener.cs b/MediaBrowser.Common/Kernel/IWebSocketListener.cs index 00be28ed3..b04bb6885 100644 --- a/MediaBrowser.Common/Kernel/IWebSocketListener.cs +++ b/MediaBrowser.Common/Kernel/IWebSocketListener.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Net; -using System; using System.Threading.Tasks; namespace MediaBrowser.Common.Kernel @@ -7,7 +6,7 @@ namespace MediaBrowser.Common.Kernel /// ///This is an interface for listening to messages coming through a web socket connection /// - public interface IWebSocketListener : IDisposable + public interface IWebSocketListener { /// /// Processes the message. diff --git a/MediaBrowser.Controller/Drawing/ImageManager.cs b/MediaBrowser.Controller/Drawing/ImageManager.cs index 16fd4a5b8..a0ba9d550 100644 --- a/MediaBrowser.Controller/Drawing/ImageManager.cs +++ b/MediaBrowser.Controller/Drawing/ImageManager.cs @@ -541,7 +541,7 @@ namespace MediaBrowser.Controller.Drawing /// Type of the image. /// Guid. /// item - public Guid GetImageCacheTag(string originalImagePath, DateTime dateModified, IEnumerable imageEnhancers, BaseItem item, ImageType imageType) + public Guid GetImageCacheTag(string originalImagePath, DateTime dateModified, IEnumerable imageEnhancers, BaseItem item, ImageType imageType) { if (item == null) { @@ -574,7 +574,7 @@ namespace MediaBrowser.Controller.Drawing /// Type of the image. /// Index of the image. /// Task{EnhancedImage}. - private async Task ExecuteImageEnhancers(IEnumerable imageEnhancers, Image originalImage, BaseItem item, ImageType imageType, int imageIndex) + private async Task ExecuteImageEnhancers(IEnumerable imageEnhancers, Image originalImage, BaseItem item, ImageType imageType, int imageIndex) { var result = originalImage; diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index ea868ec45..25a049435 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -217,8 +217,7 @@ namespace MediaBrowser.Controller /// Image processors are specialized metadata providers that run after the normal ones /// /// The image enhancers. - [ImportMany(typeof(BaseImageEnhancer))] - public BaseImageEnhancer[] ImageEnhancers { get; private set; } + public IEnumerable ImageEnhancers { get; private set; } /// /// Gets the list of currently registered entity resolvers @@ -387,6 +386,7 @@ namespace MediaBrowser.Controller WeatherProviders = GetExports(allTypes); IntroProviders = GetExports(allTypes); PluginConfigurationPages = GetExports(allTypes); + ImageEnhancers = GetExports(allTypes); } /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index b1a1dc567..26107b9c9 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -138,7 +138,7 @@ - + diff --git a/MediaBrowser.Controller/Providers/BaseImageEnhancer.cs b/MediaBrowser.Controller/Providers/BaseImageEnhancer.cs deleted file mode 100644 index aeceeaf5f..000000000 --- a/MediaBrowser.Controller/Providers/BaseImageEnhancer.cs +++ /dev/null @@ -1,99 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Model.Drawing; -using MediaBrowser.Model.Entities; -using System; -using System.Drawing; -using System.Threading.Tasks; - -namespace MediaBrowser.Controller.Providers -{ - /// - /// Class BaseImageEnhancer - /// - public abstract class BaseImageEnhancer : IDisposable - { - /// - /// Return true only if the given image for the given item will be enhanced by this enhancer. - /// - /// The item. - /// Type of the image. - /// true if this enhancer will enhance the supplied image for the supplied item, false otherwise - public abstract bool Supports(BaseItem item, ImageType imageType); - - /// - /// Gets the priority or order in which this enhancer should be run. - /// - /// The priority. - public abstract MetadataProviderPriority Priority { get; } - - /// - /// Return the date of the last configuration change affecting the provided baseitem and image type - /// - /// The item. - /// Type of the image. - /// Date of last config change - public virtual DateTime LastConfigurationChange(BaseItem item, ImageType imageType) - { - return DateTime.MinValue; - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Releases unmanaged and - optionally - managed resources. - /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) - { - } - - /// - /// Gets the size of the enhanced image. - /// - /// The item. - /// Type of the image. - /// Index of the image. - /// Size of the original image. - /// ImageSize. - public virtual ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize) - { - return originalImageSize; - } - - /// - /// Enhances the supplied image and returns it - /// - /// The item. - /// The original image. - /// Type of the image. - /// Index of the image. - /// Task{System.Drawing.Image}. - protected abstract Task EnhanceImageAsyncInternal(BaseItem item, Image originalImage, ImageType imageType, int imageIndex); - - /// - /// Enhances the image async. - /// - /// The item. - /// The original image. - /// Type of the image. - /// Index of the image. - /// Task{Image}. - /// - public Task EnhanceImageAsync(BaseItem item, Image originalImage, ImageType imageType, int imageIndex) - { - if (item == null || originalImage == null) - { - throw new ArgumentNullException(); - } - - return EnhanceImageAsyncInternal(item, originalImage, imageType, imageIndex); - } - } -} diff --git a/MediaBrowser.Controller/Providers/IImageEnhancer.cs b/MediaBrowser.Controller/Providers/IImageEnhancer.cs new file mode 100644 index 000000000..24296b664 --- /dev/null +++ b/MediaBrowser.Controller/Providers/IImageEnhancer.cs @@ -0,0 +1,55 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Drawing; +using MediaBrowser.Model.Entities; +using System; +using System.Drawing; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Providers +{ + public interface IImageEnhancer + { + /// + /// Return true only if the given image for the given item will be enhanced by this enhancer. + /// + /// The item. + /// Type of the image. + /// true if this enhancer will enhance the supplied image for the supplied item, false otherwise + bool Supports(BaseItem item, ImageType imageType); + + /// + /// Gets the priority or order in which this enhancer should be run. + /// + /// The priority. + MetadataProviderPriority Priority { get; } + + /// + /// Return the date of the last configuration change affecting the provided baseitem and image type + /// + /// The item. + /// Type of the image. + /// Date of last config change + DateTime LastConfigurationChange(BaseItem item, ImageType imageType); + + /// + /// Gets the size of the enhanced image. + /// + /// The item. + /// Type of the image. + /// Index of the image. + /// Size of the original image. + /// ImageSize. + ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize); + + /// + /// Enhances the image async. + /// + /// The item. + /// The original image. + /// Type of the image. + /// Index of the image. + /// Task{Image}. + /// + Task EnhanceImageAsync(BaseItem item, Image originalImage, ImageType imageType, int imageIndex); + } +} \ No newline at end of file