Skip to content

Commit ea90570

Browse files
committed
Add Katana/Microsoft.Owin
1 parent 569ab62 commit ea90570

11 files changed

+413
-1
lines changed
+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
3+
<Import Project="..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProductVersion>
9+
</ProductVersion>
10+
<SchemaVersion>2.0</SchemaVersion>
11+
<ProjectGuid>{AC90B4CC-20B9-4064-8DDB-234D9BC11EE9}</ProjectGuid>
12+
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
13+
<OutputType>Library</OutputType>
14+
<AppDesignerFolder>Properties</AppDesignerFolder>
15+
<RootNamespace>MiddlewareInjector.Owin</RootNamespace>
16+
<AssemblyName>MiddlewareInjector.Owin</AssemblyName>
17+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
18+
<UseIISExpress>true</UseIISExpress>
19+
<Use64BitIISExpress />
20+
<IISExpressSSLPort />
21+
<IISExpressAnonymousAuthentication />
22+
<IISExpressWindowsAuthentication />
23+
<IISExpressUseClassicPipelineMode />
24+
<UseGlobalApplicationHostFile />
25+
<NuGetPackageImportStamp>
26+
</NuGetPackageImportStamp>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
29+
<DebugSymbols>true</DebugSymbols>
30+
<DebugType>full</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\</OutputPath>
33+
<DefineConstants>DEBUG;TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
38+
<DebugSymbols>true</DebugSymbols>
39+
<DebugType>pdbonly</DebugType>
40+
<Optimize>true</Optimize>
41+
<OutputPath>bin\</OutputPath>
42+
<DefineConstants>TRACE</DefineConstants>
43+
<ErrorReport>prompt</ErrorReport>
44+
<WarningLevel>4</WarningLevel>
45+
</PropertyGroup>
46+
<ItemGroup>
47+
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Microsoft.CSharp" />
51+
<Reference Include="Microsoft.Owin, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Microsoft.Owin.3.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
53+
</Reference>
54+
<Reference Include="Microsoft.Owin.Host.SystemWeb, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
55+
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
56+
</Reference>
57+
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
58+
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
59+
</Reference>
60+
<Reference Include="System.Web.DynamicData" />
61+
<Reference Include="System.Web.Entity" />
62+
<Reference Include="System.Web.ApplicationServices" />
63+
<Reference Include="System.ComponentModel.DataAnnotations" />
64+
<Reference Include="System" />
65+
<Reference Include="System.Data" />
66+
<Reference Include="System.Core" />
67+
<Reference Include="System.Data.DataSetExtensions" />
68+
<Reference Include="System.Web.Extensions" />
69+
<Reference Include="System.Xml.Linq" />
70+
<Reference Include="System.Drawing" />
71+
<Reference Include="System.Web" />
72+
<Reference Include="System.Xml" />
73+
<Reference Include="System.Configuration" />
74+
<Reference Include="System.Web.Services" />
75+
<Reference Include="System.EnterpriseServices" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<None Include="packages.config" />
79+
<None Include="Web.Debug.config">
80+
<DependentUpon>Web.config</DependentUpon>
81+
</None>
82+
<None Include="Web.Release.config">
83+
<DependentUpon>Web.config</DependentUpon>
84+
</None>
85+
</ItemGroup>
86+
<ItemGroup>
87+
<Content Include="Web.config" />
88+
</ItemGroup>
89+
<ItemGroup>
90+
<Compile Include="MiddlewareInjectorExtensions.cs" />
91+
<Compile Include="MiddlewareInjectorMiddleware.cs" />
92+
<Compile Include="MiddlewareInjectorOptions.cs" />
93+
<Compile Include="Properties\AssemblyInfo.cs" />
94+
<Compile Include="Startup.cs" />
95+
</ItemGroup>
96+
<PropertyGroup>
97+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
98+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
99+
</PropertyGroup>
100+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
101+
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
102+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
103+
<ProjectExtensions>
104+
<VisualStudio>
105+
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
106+
<WebProjectProperties>
107+
<UseIIS>True</UseIIS>
108+
<AutoAssignPort>True</AutoAssignPort>
109+
<DevelopmentServerPort>59209</DevelopmentServerPort>
110+
<DevelopmentServerVPath>/</DevelopmentServerVPath>
111+
<IISUrl>http://localhost:59209/</IISUrl>
112+
<NTLMAuthentication>False</NTLMAuthentication>
113+
<UseCustomServer>False</UseCustomServer>
114+
<CustomServerUrl>
115+
</CustomServerUrl>
116+
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
117+
</WebProjectProperties>
118+
</FlavorProperties>
119+
</VisualStudio>
120+
</ProjectExtensions>
121+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
122+
<PropertyGroup>
123+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
124+
</PropertyGroup>
125+
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props'))" />
126+
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
127+
</Target>
128+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
129+
Other similar extension points exist, see Microsoft.Common.targets.
130+
<Target Name="BeforeBuild">
131+
</Target>
132+
<Target Name="AfterBuild">
133+
</Target>
134+
-->
135+
</Project>
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Owin;
6+
7+
namespace MiddlewareInjector
8+
{
9+
public static class MiddlewareInjectorExtensions
10+
{
11+
public static IAppBuilder UseMiddlewareInjector(this IAppBuilder builder, MiddlewareInjectorOptions options)
12+
{
13+
return builder.Use<MiddlewareInjectorMiddleware>(builder.New(), options);
14+
}
15+
}
16+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.Owin;
6+
using Microsoft.Owin.Builder;
7+
using Owin;
8+
9+
namespace MiddlewareInjector
10+
{
11+
using AppFunc = Func<IDictionary<string, object>, Task>;
12+
13+
public class MiddlewareInjectorMiddleware
14+
{
15+
private readonly AppFunc _next;
16+
private readonly IAppBuilder _builder;
17+
private readonly MiddlewareInjectorOptions _options;
18+
private AppFunc _subPipeline;
19+
20+
public MiddlewareInjectorMiddleware(AppFunc next, IAppBuilder builder, MiddlewareInjectorOptions options)
21+
{
22+
_next = next ?? throw new ArgumentNullException(nameof(next));
23+
_builder = builder ?? throw new ArgumentNullException(nameof(builder));
24+
_options = options ?? throw new ArgumentNullException(nameof(options));
25+
}
26+
27+
public Task Invoke(IDictionary<string, object> environment)
28+
{
29+
var injector = _options.GetInjector();
30+
if (injector != null)
31+
{
32+
var builder = _builder.New();
33+
injector(builder);
34+
builder.Use(new Func<AppFunc, AppFunc>(_ => _next));
35+
_subPipeline = builder.Build();
36+
}
37+
38+
if (_subPipeline != null)
39+
{
40+
return _subPipeline(environment);
41+
}
42+
43+
return _next(environment);
44+
}
45+
}
46+
}

Diff for: MiddlewareInjector.Owin/MiddlewareInjectorOptions.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Owin;
7+
8+
namespace MiddlewareInjector
9+
{
10+
public class MiddlewareInjectorOptions
11+
{
12+
private Action<IAppBuilder> _injector;
13+
14+
public void InjectMiddleware(Action<IAppBuilder> builder)
15+
{
16+
Interlocked.Exchange(ref _injector, builder);
17+
}
18+
19+
internal Action<IAppBuilder> GetInjector()
20+
{
21+
return Interlocked.Exchange(ref _injector, null);
22+
}
23+
}
24+
}

Diff for: MiddlewareInjector.Owin/Properties/AssemblyInfo.cs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MiddlewareInjector.Owin")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("MiddlewareInjector.Owin")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("ac90b4cc-20b9-4064-8ddb-234d9bc11ee9")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Revision and Build Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

Diff for: MiddlewareInjector.Owin/Startup.cs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.Owin;
4+
using Owin;
5+
6+
[assembly: OwinStartup(typeof(MiddlewareInjector.Owin.Startup))]
7+
8+
namespace MiddlewareInjector.Owin
9+
{
10+
public class Startup
11+
{
12+
public void Configuration(IAppBuilder app)
13+
{
14+
var injectorOptions = new MiddlewareInjectorOptions();
15+
16+
app.UseMiddlewareInjector(injectorOptions);
17+
18+
app.Run(async context =>
19+
{
20+
context.Response.ContentType = "text/html";
21+
await context.Response.WriteAsync("<html><body>");
22+
if (context.Request.Path.Equals(new PathString("/clear")))
23+
{
24+
injectorOptions.InjectMiddleware(_ => { });
25+
await context.Response.WriteAsync("Cleared middleware<br>");
26+
}
27+
else if (context.Request.Path.Equals(new PathString("/inject")))
28+
{
29+
injectorOptions.InjectMiddleware(InjectContent);
30+
31+
await context.Response.WriteAsync("Injected middleware<br>");
32+
}
33+
else
34+
{
35+
await context.Response.WriteAsync("Hello World!<br>");
36+
}
37+
await context.Response.WriteAsync("<a href=\"/inject\">Inject</a><br>");
38+
await context.Response.WriteAsync("<a href=\"/testpath\">Test Path</a><br>");
39+
await context.Response.WriteAsync("<a href=\"/clear\">Clear</a><br>");
40+
await context.Response.WriteAsync("<a href=\"/\">Home</a><br>");
41+
await context.Response.WriteAsync("</body></html>");
42+
});
43+
}
44+
45+
public void InjectContent(IAppBuilder builder)
46+
{
47+
builder.Map("/testpath", subBuilder =>
48+
{
49+
subBuilder.Run(async context =>
50+
{
51+
context.Response.ContentType = "text/html";
52+
await context.Response.WriteAsync("<html><body>");
53+
await context.Response.WriteAsync("Injected content<br>");
54+
await context.Response.WriteAsync("<a href=\"/\">Home</a><br>");
55+
await context.Response.WriteAsync("</body></html>");
56+
});
57+
});
58+
}
59+
}
60+
}

Diff for: MiddlewareInjector.Owin/Web.Debug.config

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->
4+
5+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
6+
<!--
7+
In the example below, the "SetAttributes" transform will change the value of
8+
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
9+
finds an attribute "name" that has a value of "MyDB".
10+
11+
<connectionStrings>
12+
<add name="MyDB"
13+
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
14+
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
15+
</connectionStrings>
16+
-->
17+
<system.web>
18+
<!--
19+
In the example below, the "Replace" transform will replace the entire
20+
<customErrors> section of your web.config file.
21+
Note that because there is only one customErrors section under the
22+
<system.web> node, there is no need to use the "xdt:Locator" attribute.
23+
24+
<customErrors defaultRedirect="GenericError.htm"
25+
mode="RemoteOnly" xdt:Transform="Replace">
26+
<error statusCode="500" redirect="InternalError.htm"/>
27+
</customErrors>
28+
-->
29+
</system.web>
30+
</configuration>

Diff for: MiddlewareInjector.Owin/Web.Release.config

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->
4+
5+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
6+
<!--
7+
In the example below, the "SetAttributes" transform will change the value of
8+
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
9+
finds an attribute "name" that has a value of "MyDB".
10+
11+
<connectionStrings>
12+
<add name="MyDB"
13+
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
14+
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
15+
</connectionStrings>
16+
-->
17+
<system.web>
18+
<compilation xdt:Transform="RemoveAttributes(debug)" />
19+
<!--
20+
In the example below, the "Replace" transform will replace the entire
21+
<customErrors> section of your web.config file.
22+
Note that because there is only one customErrors section under the
23+
<system.web> node, there is no need to use the "xdt:Locator" attribute.
24+
25+
<customErrors defaultRedirect="GenericError.htm"
26+
mode="RemoteOnly" xdt:Transform="Replace">
27+
<error statusCode="500" redirect="InternalError.htm"/>
28+
</customErrors>
29+
-->
30+
</system.web>
31+
</configuration>

0 commit comments

Comments
 (0)