extracted more interfaces

This commit is contained in:
LukePulverenti 2013-02-22 19:44:20 -05:00
parent 881bf8b9cb
commit 6a5bf9cc78
7 changed files with 80 additions and 108 deletions

View File

@ -197,7 +197,6 @@ namespace MediaBrowser.Common.Kernel
/// Gets the web socket listeners.
/// </summary>
/// <value>The web socket listeners.</value>
[ImportMany(typeof(IWebSocketListener))]
public IEnumerable<IWebSocketListener> WebSocketListeners { get; private set; }
/// <summary>
@ -236,6 +235,11 @@ namespace MediaBrowser.Common.Kernel
/// <value>The rest services.</value>
public IEnumerable<IRestfulService> RestServices { get; private set; }
/// <summary>
/// The disposable parts
/// </summary>
private readonly List<IDisposable> _disposableParts = new List<IDisposable>();
/// <summary>
/// The _protobuf serializer initialized
/// </summary>
@ -497,6 +501,7 @@ namespace MediaBrowser.Common.Kernel
protected virtual void ComposePartsWithIocContainer(Type[] allTypes, Container container)
{
RestServices = GetExports<IRestfulService>(allTypes);
WebSocketListeners = GetExports<IWebSocketListener>(allTypes);
}
/// <summary>
@ -511,7 +516,11 @@ namespace MediaBrowser.Common.Kernel
Logger.Info("Composing instances of " + currentType.Name);
return allTypes.Where(currentType.IsAssignableFrom).Select(Instantiate).Cast<T>().ToArray();
var parts = allTypes.Where(currentType.IsAssignableFrom).Select(Instantiate).Cast<T>().ToArray();
_disposableParts.AddRange(parts.OfType<IDisposable>());
return parts;
}
/// <summary>
@ -528,6 +537,7 @@ namespace MediaBrowser.Common.Kernel
/// Composes the exported values.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="iocContainer"></param>
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();
}
}

View File

@ -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
/// <summary>
///This is an interface for listening to messages coming through a web socket connection
/// </summary>
public interface IWebSocketListener : IDisposable
public interface IWebSocketListener
{
/// <summary>
/// Processes the message.

View File

@ -541,7 +541,7 @@ namespace MediaBrowser.Controller.Drawing
/// <param name="imageType">Type of the image.</param>
/// <returns>Guid.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
public Guid GetImageCacheTag(string originalImagePath, DateTime dateModified, IEnumerable<BaseImageEnhancer> imageEnhancers, BaseItem item, ImageType imageType)
public Guid GetImageCacheTag(string originalImagePath, DateTime dateModified, IEnumerable<IImageEnhancer> imageEnhancers, BaseItem item, ImageType imageType)
{
if (item == null)
{
@ -574,7 +574,7 @@ namespace MediaBrowser.Controller.Drawing
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <returns>Task{EnhancedImage}.</returns>
private async Task<Image> ExecuteImageEnhancers(IEnumerable<BaseImageEnhancer> imageEnhancers, Image originalImage, BaseItem item, ImageType imageType, int imageIndex)
private async Task<Image> ExecuteImageEnhancers(IEnumerable<IImageEnhancer> imageEnhancers, Image originalImage, BaseItem item, ImageType imageType, int imageIndex)
{
var result = originalImage;

View File

@ -217,8 +217,7 @@ namespace MediaBrowser.Controller
/// Image processors are specialized metadata providers that run after the normal ones
/// </summary>
/// <value>The image enhancers.</value>
[ImportMany(typeof(BaseImageEnhancer))]
public BaseImageEnhancer[] ImageEnhancers { get; private set; }
public IEnumerable<IImageEnhancer> ImageEnhancers { get; private set; }
/// <summary>
/// Gets the list of currently registered entity resolvers
@ -387,6 +386,7 @@ namespace MediaBrowser.Controller
WeatherProviders = GetExports<IWeatherProvider>(allTypes);
IntroProviders = GetExports<IIntroProvider>(allTypes);
PluginConfigurationPages = GetExports<IPluginConfigurationPage>(allTypes);
ImageEnhancers = GetExports<IImageEnhancer>(allTypes);
}
/// <summary>

View File

@ -138,7 +138,7 @@
<Compile Include="Plugins\IPluginConfigurationPage.cs" />
<Compile Include="Plugins\PluginSecurityManager.cs" />
<Compile Include="Providers\FanartBaseProvider.cs" />
<Compile Include="Providers\BaseImageEnhancer.cs" />
<Compile Include="Providers\IImageEnhancer.cs" />
<Compile Include="Providers\ImagesByNameProvider.cs" />
<Compile Include="Providers\MediaInfo\BaseFFMpegImageProvider.cs" />
<Compile Include="Providers\MediaInfo\BaseFFMpegProvider.cs" />

View File

@ -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
{
/// <summary>
/// Class BaseImageEnhancer
/// </summary>
public abstract class BaseImageEnhancer : IDisposable
{
/// <summary>
/// Return true only if the given image for the given item will be enhanced by this enhancer.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <returns><c>true</c> if this enhancer will enhance the supplied image for the supplied item, <c>false</c> otherwise</returns>
public abstract bool Supports(BaseItem item, ImageType imageType);
/// <summary>
/// Gets the priority or order in which this enhancer should be run.
/// </summary>
/// <value>The priority.</value>
public abstract MetadataProviderPriority Priority { get; }
/// <summary>
/// Return the date of the last configuration change affecting the provided baseitem and image type
/// </summary>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <returns>Date of last config change</returns>
public virtual DateTime LastConfigurationChange(BaseItem item, ImageType imageType)
{
return DateTime.MinValue;
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool dispose)
{
}
/// <summary>
/// Gets the size of the enhanced image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="originalImageSize">Size of the original image.</param>
/// <returns>ImageSize.</returns>
public virtual ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize)
{
return originalImageSize;
}
/// <summary>
/// Enhances the supplied image and returns it
/// </summary>
/// <param name="item">The item.</param>
/// <param name="originalImage">The original image.</param>
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <returns>Task{System.Drawing.Image}.</returns>
protected abstract Task<Image> EnhanceImageAsyncInternal(BaseItem item, Image originalImage, ImageType imageType, int imageIndex);
/// <summary>
/// Enhances the image async.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="originalImage">The original image.</param>
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <returns>Task{Image}.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public Task<Image> EnhanceImageAsync(BaseItem item, Image originalImage, ImageType imageType, int imageIndex)
{
if (item == null || originalImage == null)
{
throw new ArgumentNullException();
}
return EnhanceImageAsyncInternal(item, originalImage, imageType, imageIndex);
}
}
}

View File

@ -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
{
/// <summary>
/// Return true only if the given image for the given item will be enhanced by this enhancer.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <returns><c>true</c> if this enhancer will enhance the supplied image for the supplied item, <c>false</c> otherwise</returns>
bool Supports(BaseItem item, ImageType imageType);
/// <summary>
/// Gets the priority or order in which this enhancer should be run.
/// </summary>
/// <value>The priority.</value>
MetadataProviderPriority Priority { get; }
/// <summary>
/// Return the date of the last configuration change affecting the provided baseitem and image type
/// </summary>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <returns>Date of last config change</returns>
DateTime LastConfigurationChange(BaseItem item, ImageType imageType);
/// <summary>
/// Gets the size of the enhanced image.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <param name="originalImageSize">Size of the original image.</param>
/// <returns>ImageSize.</returns>
ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize);
/// <summary>
/// Enhances the image async.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="originalImage">The original image.</param>
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <returns>Task{Image}.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
Task<Image> EnhanceImageAsync(BaseItem item, Image originalImage, ImageType imageType, int imageIndex);
}
}