Browse Source

Better error handling in bootstrapper

Former-commit-id: 005a7e795e74e6ccb3ca5e3c6a40b4c2770f67e6
pull/17/head
James South 12 years ago
parent
commit
dc462edf6c
  1. 48
      src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs
  2. 4
      src/ImageProcessorConsole/Program.cs
  3. 2
      src/ImageProcessorConsole/images/input/rotate.jpg.REMOVED.git-id
  4. BIN
      src/ImageProcessorConsole/images/output/120430.gif
  5. 1
      src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id
  6. BIN
      src/ImageProcessorConsole/images/output/Tl4Yb.gif
  7. 1
      src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id
  8. BIN
      src/ImageProcessorConsole/images/output/circle.png
  9. BIN
      src/ImageProcessorConsole/images/output/nLpfllv.gif
  10. 1
      src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id
  11. BIN
      src/ImageProcessorConsole/images/output/rotate.jpg

48
src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs

@ -13,6 +13,7 @@ namespace ImageProcessor.Configuration
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
@ -70,19 +71,19 @@ namespace ImageProcessor.Configuration
{
if (this.SupportedImageFormats == null)
{
try
{
Type type = typeof(ISupportedImageFormat);
Type type = typeof(ISupportedImageFormat);
// Get any referenced but not used assemblies.
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string targetBasePath = Path.GetDirectoryName(new Uri(executingAssembly.Location).LocalPath);
// Get any referenced but not used assemblies.
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string targetBasePath = Path.GetDirectoryName(new Uri(executingAssembly.Location).LocalPath);
// ReSharper disable once AssignNullToNotNullAttribute
FileInfo[] files = new DirectoryInfo(targetBasePath).GetFiles("*.dll", SearchOption.AllDirectories);
// ReSharper disable once AssignNullToNotNullAttribute
FileInfo[] files = new DirectoryInfo(targetBasePath).GetFiles("*.dll", SearchOption.AllDirectories);
HashSet<string> found = new HashSet<string>();
foreach (FileInfo fileInfo in files)
HashSet<string> found = new HashSet<string>();
foreach (FileInfo fileInfo in files)
{
try
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(fileInfo.FullName);
@ -91,23 +92,26 @@ namespace ImageProcessor.Configuration
{
// In a web app, this assembly will automatically be bound from the
// Asp.Net Temporary folder from where the site actually runs.
Assembly.Load(assemblyName);
this.LoadReferencedAssemblies(found, Assembly.Load(assemblyName));
}
}
catch (Exception ex)
{
// Log the exception for debugging only. There could be any old junk
// thrown in to the bin folder by someone else.
Debug.WriteLine(ex.Message);
}
}
List<Type> availableTypes = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(a => a.GetLoadableTypes())
.Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.ToList();
List<Type> availableTypes = AppDomain.CurrentDomain
.GetAssemblies()
.SelectMany(a => a.GetLoadableTypes())
.Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.ToList();
this.SupportedImageFormats = availableTypes
.Select(f => (Activator.CreateInstance(f) as ISupportedImageFormat)).ToList();
}
catch (Exception ex)
{
throw new ImageFormatException(ex.Message, ex.InnerException);
}
this.SupportedImageFormats = availableTypes
.Select(f => (Activator.CreateInstance(f) as ISupportedImageFormat)).ToList();
}
}

4
src/ImageProcessorConsole/Program.cs

@ -40,8 +40,8 @@ namespace ImageProcessorConsole
di.Create();
}
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".webp");
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png");
//IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".jpg");
IEnumerable<FileInfo> files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png");
foreach (FileInfo fileInfo in files)
{

2
src/ImageProcessorConsole/images/input/rotate.jpg.REMOVED.git-id

@ -1 +1 @@
406a6a7916628c0c0bea8243565a7162ebd5a505
166cc5e22c4caf8740e5771fe7b52e23637dd7fa

BIN
src/ImageProcessorConsole/images/output/120430.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

1
src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id

@ -0,0 +1 @@
30ec5c05548fd350f9b7c699715848b9fbfb8ca9

BIN
src/ImageProcessorConsole/images/output/Tl4Yb.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

1
src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id

@ -0,0 +1 @@
fdc62fc2d056ab885eb9e8fd12b9155ee86d7c43

BIN
src/ImageProcessorConsole/images/output/circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
src/ImageProcessorConsole/images/output/nLpfllv.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

1
src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id

@ -0,0 +1 @@
23a1c81a2d1422076373796e0c47f5d968c56d0b

BIN
src/ImageProcessorConsole/images/output/rotate.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Loading…
Cancel
Save