Browse Source

Merge remote-tracking branch 'origin/dev' into V2

Former-commit-id: 2c43388625a486f4eda3ef296ab69d17ce51d650
pull/17/head
James South 12 years ago
parent
commit
49cf0c42d2
  1. 2
      build/Build.bat
  2. 9
      src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs
  3. 41
      src/ImageProcessor/Common/Extensions/AssemblyExtensions.cs
  4. 6
      src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs
  5. 1
      src/ImageProcessor/ImageProcessor.csproj

2
build/Build.bat

@ -8,7 +8,7 @@ ECHO Building ImageProcessor %version%, ImageProcess.Web %webversion% and ImageP
ECHO Installing the Microsoft.Bcl.Build package before anything else, otherwise you'd have to run build.cmd twice
SET nuGetFolder=%CD%\..\src\packages\
..\src\.nuget\NuGet.exe install ..\src\ImageProcessor.Web\NET45\packages.config -OutputDirectory %nuGetFolder%
..\src\.nuget\NuGet.exe install ..\src\ImageProcessor.Web\NET4\packages.config -OutputDirectory %nuGetFolder%
ECHO Removing _BuildOutput directory so everything is nice and clean
RD _BuildOutput /q /s

9
src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs

@ -10,18 +10,17 @@
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Web.Configuration
{
#region Using
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Compilation;
using ImageProcessor.Common.Extensions;
using ImageProcessor.Processors;
using ImageProcessor.Web.Processors;
#endregion
/// <summary>
/// Encapsulates methods to allow the retrieval of ImageProcessor settings.
/// <see href="http://csharpindepth.com/Articles/General/Singleton.aspx"/>
@ -301,8 +300,8 @@ namespace ImageProcessor.Web.Configuration
// Build a list of native IGraphicsProcessor instances.
List<Type> availableTypes = BuildManager.GetReferencedAssemblies()
.Cast<Assembly>()
.SelectMany(s => s.GetTypes())
.Where(t => t != null && type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.SelectMany(s => s.GetLoadableTypes())
.Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.ToList();
// Create them and add.

41
src/ImageProcessor/Common/Extensions/AssemblyExtensions.cs

@ -0,0 +1,41 @@

namespace ImageProcessor.Common.Extensions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
/// <summary>
/// Encapsulates a series of time saving extension methods to the <see cref="T:System.Reflection.Assembly"/> class.
/// </summary>
public static class AssemblyExtensions
{
/// <summary>
/// Gets a collection of loadable types from the given assembly.
/// Adapted from <see href="http://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes"/>
/// </summary>
/// <param name="assembly">
/// The <see cref="System.Reflection.Assembly"/> to load the types from.
/// </param>
/// <returns>
/// The loadable <see cref="System.Collections.Generic.IEnumerable{Type}"/>.
/// </returns>
public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
{
if (assembly == null)
{
throw new ArgumentNullException("assembly");
}
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
return ex.Types.Where(t => t != null);
}
}
}
}

6
src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs

@ -13,8 +13,8 @@ namespace ImageProcessor.Configuration
using System;
using System.Collections.Generic;
using System.Linq;
using ImageProcessor.Common.Exceptions;
using ImageProcessor.Common.Extensions;
using ImageProcessor.Imaging.Formats;
/// <summary>
@ -65,8 +65,8 @@ namespace ImageProcessor.Configuration
Type type = typeof(ISupportedImageFormat);
List<Type> availableTypes = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(t => t != null && type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.SelectMany(s => s.GetLoadableTypes())
.Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.ToList();
this.SupportedImageFormats = availableTypes

1
src/ImageProcessor/ImageProcessor.csproj

@ -59,6 +59,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\Extensions\AssemblyExtensions.cs" />
<Compile Include="Configuration\ImageProcessorBootstrapper.cs" />
<Compile Include="Common\Exceptions\ImageProcessingException.cs" />
<Compile Include="Common\Extensions\DoubleExtensions.cs" />

Loading…
Cancel
Save