Browse Source

Better error handling in bootstrapper

Former-commit-id: 12c65e1a08a6b8d4ba38b26e7b51c2ec9d762242
af/merge-core
James South 12 years ago
parent
commit
611073fac8
  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. 3
      src/ImageProcessorConsole/images/output/120430.gif
  5. 1
      src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id
  6. 3
      src/ImageProcessorConsole/images/output/Tl4Yb.gif
  7. 1
      src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id
  8. 3
      src/ImageProcessorConsole/images/output/circle.png
  9. 3
      src/ImageProcessorConsole/images/output/nLpfllv.gif
  10. 1
      src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id
  11. 4
      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

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

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:896b26b0129a335a91a5f8820ef9c5bc036dd60fae64690c0f8d281ca97bbc8d
size 8581

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

@ -0,0 +1 @@
30ec5c05548fd350f9b7c699715848b9fbfb8ca9

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

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0e47e2ea079ce001c59cab3f7c3801d86b270d752d4399fd35779fb0e5ec9473
size 12875

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

@ -0,0 +1 @@
fdc62fc2d056ab885eb9e8fd12b9155ee86d7c43

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

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f31110b7933864eff3b149371c962174a8855a1c65f4fee7cb3bc63a79b71467
size 2905

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

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a06d1e40bfed07eaaf26e416be8abdec8b762e744cde4123e1606e0c89d33cb0
size 18930

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

@ -0,0 +1 @@
23a1c81a2d1422076373796e0c47f5d968c56d0b

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

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5b7215a59e681f4100078aeb74b5d423dcea54b9d2ea924a2bb7c74b2db3ee3a
size 26227
oid sha256:fbb53b552f559d93ea5d04ac1dd099938405d497362275ff669070e746f89d35
size 17821

Loading…
Cancel
Save