Skip to content

Commit

Permalink
Added embedded httpmodule declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Mar 18, 2014
1 parent e254510 commit d730995
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 37 deletions.
7 changes: 7 additions & 0 deletions src/ImageProcessor.Web/NET4/ImageProcessor.Web_NET4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
<HintPath>..\..\packages\Microsoft.Bcl.Async.1.0.165\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -86,6 +90,9 @@
<Link>ImageHelpers.cs</Link>
</Compile>
<Compile Include="..\NET45\Helpers\RemoteFile.cs" />
<Compile Include="..\NET45\Helpers\StartUp.cs">
<Link>StartUp.cs</Link>
</Compile>
<Compile Include="..\NET45\Helpers\TaskHelpers.cs" />
<Compile Include="..\NET45\HttpModules\ImageProcessingModule.cs" />
<Compile Include="..\NET45\ImageFactoryExtensions.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/ImageProcessor.Web/NET4/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="Microsoft.Bcl" version="1.1.6" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.165" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.13" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
</packages>
7 changes: 2 additions & 5 deletions src/ImageProcessor.Web/NET45/Config/ImageProcessorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ namespace ImageProcessor.Web.Config
#region Using
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web.Compilation;

using ImageProcessor.Processors;
#endregion

Expand Down Expand Up @@ -300,7 +297,7 @@ private void LoadGraphicsProcessors()
.SelectMany(s => s.GetTypes())
.Where(t => t != null && type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract)
.ToList();

// Create them and add.
this.GraphicsProcessors = availableTypes.Select(x => (Activator.CreateInstance(x) as IGraphicsProcessor)).ToList();

Expand All @@ -310,7 +307,7 @@ private void LoadGraphicsProcessors()
processor.Settings = this.GetPluginSettings(processor.GetType().Name);
}
}
catch (ReflectionTypeLoadException ex)
catch (ReflectionTypeLoadException)
{
this.LoadGraphicsProcessorsFromConfiguration();
}
Expand Down
31 changes: 31 additions & 0 deletions src/ImageProcessor.Web/NET45/Helpers/StartUp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StartUp.cs" company="James South">
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// <summary>
// Provides methods to handle startup events.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

[assembly: System.Web.PreApplicationStartMethod(typeof(ImageProcessor.Web.Helpers.StartUp), "PreApplicationStart")]

namespace ImageProcessor.Web.Helpers
{
using ImageProcessor.Web.HttpModules;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;

/// <summary>
/// Provides methods to handle startup events.
/// </summary>
public static class StartUp
{
/// <summary>
/// The pre application start.
/// </summary>
public static void PreApplicationStart()
{
DynamicModuleUtility.RegisterModule(typeof(ImageProcessingModule));
}
}
}
25 changes: 14 additions & 11 deletions src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace ImageProcessor.Web.HttpModules
using ImageProcessor.Web.Caching;
using ImageProcessor.Web.Config;
using ImageProcessor.Web.Helpers;

using Microsoft.Web.Infrastructure.DynamicModuleHelper;

#endregion

/// <summary>
Expand All @@ -49,11 +52,6 @@ public sealed class ImageProcessingModule : IHttpModule
/// </summary>
private static readonly Regex PresetRegex = new Regex(@"preset=[^&]*", RegexOptions.Compiled);

/// <summary>
/// The value to prefix any remote image requests with to ensure they get captured.
/// </summary>
private static readonly string RemotePrefix = ImageProcessorConfig.Instance.RemotePrefix;

/// <summary>
/// The assembly version.
/// </summary>
Expand All @@ -64,6 +62,11 @@ public sealed class ImageProcessingModule : IHttpModule
/// </summary>
private static readonly Dictionary<string, SemaphoreSlim> SemaphoreSlims = new Dictionary<string, SemaphoreSlim>();

/// <summary>
/// The value to prefix any remote image requests with to ensure they get captured.
/// </summary>
private static string remotePrefix;

/// <summary>
/// A value indicating whether this instance of the given entity has been disposed.
/// </summary>
Expand Down Expand Up @@ -109,17 +112,17 @@ public sealed class ImageProcessingModule : IHttpModule
/// </param>
public void Init(HttpApplication context)
{
#if NET45
if (remotePrefix == null)
{
remotePrefix = ImageProcessorConfig.Instance.RemotePrefix;
}

#if NET45
EventHandlerTaskAsyncHelper wrapper = new EventHandlerTaskAsyncHelper(this.PostAuthorizeRequest);
context.AddOnPostAuthorizeRequestAsync(wrapper.BeginEventHandler, wrapper.EndEventHandler);

#else

context.PostAuthorizeRequest += this.PostAuthorizeRequest;

#endif

context.PreSendRequestHeaders += this.ContextPreSendRequestHeaders;
}

Expand Down Expand Up @@ -264,7 +267,7 @@ private async Task ProcessImageAsync(HttpContext context)
HttpRequest request = context.Request;

// Fixes issue 10.
bool isRemote = request.Path.EndsWith(RemotePrefix, StringComparison.OrdinalIgnoreCase);
bool isRemote = request.Path.EndsWith(remotePrefix, StringComparison.OrdinalIgnoreCase);
string requestPath = string.Empty;
string queryString = string.Empty;

Expand Down
8 changes: 8 additions & 0 deletions src/ImageProcessor.Web/NET45/ImageProcessor.Web_NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -53,6 +57,7 @@
<Compile Include="Config\ImageProcessingSection.cs" />
<Compile Include="Config\ImageProcessorConfig.cs" />
<Compile Include="Config\ImageSecuritySection.cs" />
<Compile Include="Helpers\StartUp.cs" />
<Compile Include="Helpers\ImageHelpers.cs" />
<Compile Include="Helpers\RemoteFile.cs" />
<Compile Include="Helpers\TaskHelpers.cs" />
Expand All @@ -66,6 +71,9 @@
<Name>ImageProcessor</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
7 changes: 5 additions & 2 deletions src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
using System.Web;

using ImageProcessor.Web.HttpModules;

[assembly: AssemblyTitle("ImageProcessor.Web")]
[assembly: AssemblyDescription("A library for on-the-fly processing of image files with ASP.NET written in C#")]
[assembly: AssemblyConfiguration("James South")]
Expand Down Expand Up @@ -32,5 +36,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("3.1.2.0")]
[assembly: AssemblyFileVersion("3.1.2.0")]

[assembly: AssemblyFileVersion("3.1.2.0")]
4 changes: 4 additions & 0 deletions src/ImageProcessor.Web/NET45/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>56639</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:51117/</IISUrl>
<IISUrl>http://localhost:56639/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
25 changes: 8 additions & 17 deletions src/TestWebsites/NET45/Test_Website_NET45/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

<configuration>
<configSections>
<sectionGroup name="imageProcessor">
<!--<sectionGroup name="imageProcessor">
<section name="security" requirePermission="false" type="ImageProcessor.Web.Config.ImageSecuritySection, ImageProcessor.Web"/>
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Config.ImageProcessingSection, ImageProcessor.Web"/>
<section name="cache" requirePermission="false" type="ImageProcessor.Web.Config.ImageCacheSection, ImageProcessor.Web"/>
</sectionGroup>
</sectionGroup>-->
</configSections>
<imageProcessor >
<!--<imageProcessor >
<security configSource="config\imageprocessor\security.config"/>
<cache configSource="config\imageprocessor\cache.config"/>
<processing configSource="config\imageprocessor\processing.config"/>
</imageProcessor>
</imageProcessor>-->
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
</appSettings>

<system.web>

Expand All @@ -41,16 +41,9 @@
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>

<httpModules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>
</httpModules>

</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />

<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
Expand All @@ -60,8 +53,6 @@
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

<modules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>
</modules>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
1 change: 1 addition & 0 deletions src/packages/repositories.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\ImageProcessor.Web\NET4\packages.config" />
<repository path="..\ImageProcessor.Web\NET45\packages.config" />
<repository path="..\TestWebsites\NET4\packages.config" />
<repository path="..\TestWebsites\NET45\Test_Website_MVC5_NET45\packages.config" />
<repository path="..\TestWebsites\NET45\Test_Website_NET45\packages.config" />
Expand Down

0 comments on commit d730995

Please sign in to comment.