From 611073fac8b69076ccf295e6a8c2fbe813fc5cba Mon Sep 17 00:00:00 2001 From: James South Date: Tue, 19 Aug 2014 18:56:11 +0100 Subject: [PATCH] Better error handling in bootstrapper Former-commit-id: 12c65e1a08a6b8d4ba38b26e7b51c2ec9d762242 --- .../ImageProcessorBootstrapper.cs | 48 ++++++++++--------- src/ImageProcessorConsole/Program.cs | 4 +- .../images/input/rotate.jpg.REMOVED.git-id | 2 +- .../images/output/120430.gif | 3 -- .../images/output/120430.gif.REMOVED.git-id | 1 + .../images/output/Tl4Yb.gif | 3 -- .../images/output/Tl4Yb.gif.REMOVED.git-id | 1 + .../images/output/circle.png | 3 ++ .../images/output/nLpfllv.gif | 3 -- .../images/output/nLpfllv.gif.REMOVED.git-id | 1 + .../images/output/rotate.jpg | 4 +- 11 files changed, 37 insertions(+), 36 deletions(-) delete mode 100644 src/ImageProcessorConsole/images/output/120430.gif create mode 100644 src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id delete mode 100644 src/ImageProcessorConsole/images/output/Tl4Yb.gif create mode 100644 src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id create mode 100644 src/ImageProcessorConsole/images/output/circle.png delete mode 100644 src/ImageProcessorConsole/images/output/nLpfllv.gif create mode 100644 src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id diff --git a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs index e2d61b54ad..abb4033a95 100644 --- a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs +++ b/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 found = new HashSet(); - foreach (FileInfo fileInfo in files) + HashSet found = new HashSet(); + 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 availableTypes = AppDomain.CurrentDomain - .GetAssemblies() - .SelectMany(a => a.GetLoadableTypes()) - .Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract) - .ToList(); + List 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(); } } diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs index a84e4a5dbd..73490f97c6 100644 --- a/src/ImageProcessorConsole/Program.cs +++ b/src/ImageProcessorConsole/Program.cs @@ -40,8 +40,8 @@ namespace ImageProcessorConsole di.Create(); } - IEnumerable files = GetFilesByExtensions(di, ".webp"); - //IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png"); + //IEnumerable files = GetFilesByExtensions(di, ".jpg"); + IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png"); foreach (FileInfo fileInfo in files) { diff --git a/src/ImageProcessorConsole/images/input/rotate.jpg.REMOVED.git-id b/src/ImageProcessorConsole/images/input/rotate.jpg.REMOVED.git-id index bf0538b247..7170f80e11 100644 --- a/src/ImageProcessorConsole/images/input/rotate.jpg.REMOVED.git-id +++ b/src/ImageProcessorConsole/images/input/rotate.jpg.REMOVED.git-id @@ -1 +1 @@ -406a6a7916628c0c0bea8243565a7162ebd5a505 \ No newline at end of file +166cc5e22c4caf8740e5771fe7b52e23637dd7fa \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/120430.gif b/src/ImageProcessorConsole/images/output/120430.gif deleted file mode 100644 index b8bc8a2da4..0000000000 --- a/src/ImageProcessorConsole/images/output/120430.gif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:896b26b0129a335a91a5f8820ef9c5bc036dd60fae64690c0f8d281ca97bbc8d -size 8581 diff --git a/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id new file mode 100644 index 0000000000..71ce555c11 --- /dev/null +++ b/src/ImageProcessorConsole/images/output/120430.gif.REMOVED.git-id @@ -0,0 +1 @@ +30ec5c05548fd350f9b7c699715848b9fbfb8ca9 \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/Tl4Yb.gif b/src/ImageProcessorConsole/images/output/Tl4Yb.gif deleted file mode 100644 index 8019bafa38..0000000000 --- a/src/ImageProcessorConsole/images/output/Tl4Yb.gif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0e47e2ea079ce001c59cab3f7c3801d86b270d752d4399fd35779fb0e5ec9473 -size 12875 diff --git a/src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id new file mode 100644 index 0000000000..6515d65a0b --- /dev/null +++ b/src/ImageProcessorConsole/images/output/Tl4Yb.gif.REMOVED.git-id @@ -0,0 +1 @@ +fdc62fc2d056ab885eb9e8fd12b9155ee86d7c43 \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/circle.png b/src/ImageProcessorConsole/images/output/circle.png new file mode 100644 index 0000000000..a96f1ecf39 --- /dev/null +++ b/src/ImageProcessorConsole/images/output/circle.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f31110b7933864eff3b149371c962174a8855a1c65f4fee7cb3bc63a79b71467 +size 2905 diff --git a/src/ImageProcessorConsole/images/output/nLpfllv.gif b/src/ImageProcessorConsole/images/output/nLpfllv.gif deleted file mode 100644 index fd350d4372..0000000000 --- a/src/ImageProcessorConsole/images/output/nLpfllv.gif +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:a06d1e40bfed07eaaf26e416be8abdec8b762e744cde4123e1606e0c89d33cb0 -size 18930 diff --git a/src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id b/src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id new file mode 100644 index 0000000000..4487aede0f --- /dev/null +++ b/src/ImageProcessorConsole/images/output/nLpfllv.gif.REMOVED.git-id @@ -0,0 +1 @@ +23a1c81a2d1422076373796e0c47f5d968c56d0b \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/rotate.jpg b/src/ImageProcessorConsole/images/output/rotate.jpg index a9b8b74dc3..2d23e99352 100644 --- a/src/ImageProcessorConsole/images/output/rotate.jpg +++ b/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