Rouging out feature interfaces and default abstraction implementations

This commit is contained in:
Louis DeJardin 2014-01-31 13:25:12 -08:00
parent 4de6abb7b5
commit af0923b68f
45 changed files with 711 additions and 750 deletions

View File

@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.FeatureModel.Tests", "test\Microsoft.AspNet.FeatureModel.Tests\Microsoft.AspNet.FeatureModel.Tests.csproj", "{8C671AE3-1188-499F-A2A2-3A0B117B33CE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractions.net45", "src\Microsoft.AspNet.Abstractions\Microsoft.AspNet.Abstractions.net45.csproj", "{659F2FD7-D44F-4953-A69D-94AF3D41BA21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractions.k10", "src\Microsoft.AspNet.Abstractions\Microsoft.AspNet.Abstractions.k10.csproj", "{7A5C31E4-97FD-479F-8938-D818436ADFDD}"
@ -21,26 +19,32 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.PipelineCo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.PipelineCore.k10", "src\Microsoft.AspNet.PipelineCore\Microsoft.AspNet.PipelineCore.k10.csproj", "{E31CF247-FDA9-4007-B194-A7DBAC18532C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractions.Owin.net45", "src\Microsoft.AspNet.Abstractions.Owin\Microsoft.AspNet.Abstractions.Owin.net45.csproj", "{E6B7056F-547E-4B96-9E58-858DDDAE75D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Abstractions.Owin.k10", "src\Microsoft.AspNet.Abstractions.Owin\Microsoft.AspNet.Abstractions.Owin.k10.csproj", "{C5C104A4-EE38-4D77-AC77-DF599FD5443A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A5A15F1C-885A-452A-A731-B0173DDBD913}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k10", "k10", "{ADDAE1B2-094E-4DA8-86DE-13E8708072D8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net45", "net45", "{4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.AppBuilderSupport.net45", "src\Microsoft.AspNet.AppBuilderSupport\Microsoft.AspNet.AppBuilderSupport.net45.csproj", "{C2E0CB24-159D-422F-B8D1-ACA7353B5C44}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{F31FF137-390C-49BF-A3BD-7C6ED3597C21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.AppBuilderSupport.Tests.net45", "test\Microsoft.AspNet.AppBuilderSupport.Tests\Microsoft.AspNet.AppBuilderSupport.Tests.net45.csproj", "{9DF61BB6-65EC-466B-8A86-FA1CE1F1DA03}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net45", "net45", "{04077455-D4A2-43AF-ABA2-E68968856E17}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k10", "k10", "{8C87E051-8A68-439A-A6C3-B16948126606}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.FeatureModel.Tests.net45", "test\Microsoft.AspNet.FeatureModel.Tests\Microsoft.AspNet.FeatureModel.Tests.net45.csproj", "{4C82EE1A-9B93-4374-91E0-75476AABF5CD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.PipelineCore.Tests.net45", "test\Microsoft.AspNet.PipelineCore.Tests\Microsoft.AspNet.PipelineCore.Tests.net45.csproj", "{00A03235-B248-4079-A7EE-4F77AB3A84E4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C671AE3-1188-499F-A2A2-3A0B117B33CE}.Release|Any CPU.Build.0 = Release|Any CPU
{659F2FD7-D44F-4953-A69D-94AF3D41BA21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{659F2FD7-D44F-4953-A69D-94AF3D41BA21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{659F2FD7-D44F-4953-A69D-94AF3D41BA21}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -73,14 +77,22 @@ Global
{E31CF247-FDA9-4007-B194-A7DBAC18532C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E31CF247-FDA9-4007-B194-A7DBAC18532C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E31CF247-FDA9-4007-B194-A7DBAC18532C}.Release|Any CPU.Build.0 = Release|Any CPU
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6B7056F-547E-4B96-9E58-858DDDAE75D3}.Release|Any CPU.Build.0 = Release|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5C104A4-EE38-4D77-AC77-DF599FD5443A}.Release|Any CPU.Build.0 = Release|Any CPU
{C2E0CB24-159D-422F-B8D1-ACA7353B5C44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2E0CB24-159D-422F-B8D1-ACA7353B5C44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2E0CB24-159D-422F-B8D1-ACA7353B5C44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2E0CB24-159D-422F-B8D1-ACA7353B5C44}.Release|Any CPU.Build.0 = Release|Any CPU
{9DF61BB6-65EC-466B-8A86-FA1CE1F1DA03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DF61BB6-65EC-466B-8A86-FA1CE1F1DA03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DF61BB6-65EC-466B-8A86-FA1CE1F1DA03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DF61BB6-65EC-466B-8A86-FA1CE1F1DA03}.Release|Any CPU.Build.0 = Release|Any CPU
{4C82EE1A-9B93-4374-91E0-75476AABF5CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C82EE1A-9B93-4374-91E0-75476AABF5CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C82EE1A-9B93-4374-91E0-75476AABF5CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C82EE1A-9B93-4374-91E0-75476AABF5CD}.Release|Any CPU.Build.0 = Release|Any CPU
{00A03235-B248-4079-A7EE-4F77AB3A84E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00A03235-B248-4079-A7EE-4F77AB3A84E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00A03235-B248-4079-A7EE-4F77AB3A84E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00A03235-B248-4079-A7EE-4F77AB3A84E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -88,15 +100,19 @@ Global
GlobalSection(NestedProjects) = preSolution
{ADDAE1B2-094E-4DA8-86DE-13E8708072D8} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
{4B39A6DA-68BD-4F50-BE76-0399EB82DCBF} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
{7A5C31E4-97FD-479F-8938-D818436ADFDD} = {ADDAE1B2-094E-4DA8-86DE-13E8708072D8}
{C5C104A4-EE38-4D77-AC77-DF599FD5443A} = {ADDAE1B2-094E-4DA8-86DE-13E8708072D8}
{D3242B56-EA73-4F41-86A4-DF6C70271592} = {ADDAE1B2-094E-4DA8-86DE-13E8708072D8}
{3A586BF4-08D4-46E3-B74D-5D514A3B84CC} = {ADDAE1B2-094E-4DA8-86DE-13E8708072D8}
{E31CF247-FDA9-4007-B194-A7DBAC18532C} = {ADDAE1B2-094E-4DA8-86DE-13E8708072D8}
{659F2FD7-D44F-4953-A69D-94AF3D41BA21} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{E6B7056F-547E-4B96-9E58-858DDDAE75D3} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{70095525-BD99-45F9-8A6A-3BD3503FC3EE} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{7A5C31E4-97FD-479F-8938-D818436ADFDD} = {ADDAE1B2-094E-4DA8-86DE-13E8708072D8}
{8A6EE89E-8ACC-44C1-8B1E-D2FB4C7189EE} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{A195DDE4-CFB0-4A6C-9798-10658236C97B} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{659F2FD7-D44F-4953-A69D-94AF3D41BA21} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{70095525-BD99-45F9-8A6A-3BD3503FC3EE} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{C2E0CB24-159D-422F-B8D1-ACA7353B5C44} = {4B39A6DA-68BD-4F50-BE76-0399EB82DCBF}
{04077455-D4A2-43AF-ABA2-E68968856E17} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
{8C87E051-8A68-439A-A6C3-B16948126606} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
{9DF61BB6-65EC-466B-8A86-FA1CE1F1DA03} = {04077455-D4A2-43AF-ABA2-E68968856E17}
{4C82EE1A-9B93-4374-91E0-75476AABF5CD} = {04077455-D4A2-43AF-ABA2-E68968856E17}
{00A03235-B248-4079-A7EE-4F77AB3A84E4} = {04077455-D4A2-43AF-ABA2-E68968856E17}
EndGlobalSection
EndGlobal

View File

@ -1,177 +0,0 @@
#if NET45
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.Owin;
namespace Microsoft.AspNet.Abstractions.Owin
{
public class MicrosoftOwinHttpContext : HttpContext
{
private readonly IOwinContext _context;
private readonly HttpRequest _request;
private readonly HttpResponse _response;
public MicrosoftOwinHttpContext(IOwinContext context)
{
_context = context;
_request = new OwinHttpRequest(this, context.Request);
_response = new OwinHttpResponse(this, context.Response);
}
public override void Dispose()
{
}
public override object GetInterface(Type type)
{
return null;
}
public override HttpRequest Request
{
get { return _request; }
}
public override HttpResponse Response
{
get { return _response; }
}
public override void SetInterface(Type type, object instance)
{
}
private class OwinHttpRequest : HttpRequest
{
private HttpContext _context;
private IOwinRequest _request;
public OwinHttpRequest(HttpContext context, IOwinRequest request)
{
_context = context;
_request = request;
}
public override Stream Body
{
get
{
return _request.Body;
}
set
{
_request.Body = value;
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override Microsoft.AspNet.Abstractions.PathString Path
{
get
{
return new Microsoft.AspNet.Abstractions.PathString(_request.Path.Value);
}
set
{
_request.Path = new Microsoft.Owin.PathString(value.Value);
}
}
public override Microsoft.AspNet.Abstractions.PathString PathBase
{
get
{
return new Microsoft.AspNet.Abstractions.PathString(_request.PathBase.Value);
}
set
{
_request.PathBase = new Microsoft.Owin.PathString(value.Value);
}
}
public override Microsoft.AspNet.Abstractions.QueryString QueryString
{
get
{
return new Microsoft.AspNet.Abstractions.QueryString(_request.QueryString.Value);
}
set
{
_request.QueryString = new Microsoft.Owin.QueryString(value.Value);
}
}
public override Uri Uri
{
get { return _request.Uri; }
}
}
private class OwinHttpResponse : HttpResponse
{
private readonly HttpContext _context;
private readonly IOwinResponse _response;
public OwinHttpResponse(HttpContext context, IOwinResponse response)
{
_context = context;
_response = response;
}
public override Stream Body
{
get
{
return _response.Body;
}
set
{
_response.Body = value;
}
}
public override string ContentType
{
get
{
return _response.ContentType;
}
set
{
_response.ContentType = value;
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override int StatusCode
{
get
{
return _response.StatusCode;
}
set
{
_response.StatusCode = value;
}
}
public override Task WriteAsync(string data)
{
return _response.WriteAsync(data);
}
}
}
}
#endif

View File

@ -1,22 +0,0 @@
#if NET45
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Abstractions.Owin;
namespace Owin
{
public static class OwinExtensions
{
public static void RunHttpContext(this IAppBuilder app, Func<HttpContext, Task> handler)
{
app.Run(context =>
{
var httpContext = new MicrosoftOwinHttpContext(context);
return handler(httpContext);
});
}
}
}
#endif

View File

@ -1,199 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Abstractions.Owin
{
public class RawOwinHttpContext : HttpContext
{
private readonly HttpRequest _request;
private readonly HttpResponse _response;
public RawOwinHttpContext(IDictionary<string, object> env)
{
_request = new RawOwinHttpRequest(this, env);
_response = new RawOwinHttpResponse(this, env);
}
public override void Dispose()
{
}
public override object GetInterface(Type type)
{
return null;
}
public override HttpRequest Request
{
get { return _request; }
}
public override HttpResponse Response
{
get { return _response; }
}
public override void SetInterface(Type type, object instance)
{
}
private class RawOwinHttpRequest : HttpRequest
{
private HttpContext _context;
private readonly IDictionary<string, object> _env;
public RawOwinHttpRequest(HttpContext context, IDictionary<string, object> env)
{
_context = context;
_env = env;
}
public override Stream Body
{
get
{
return (Stream)_env["owin.ResponseBody"];
}
set
{
_env["owin.ResponseBody"] = value;
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override PathString Path
{
get
{
return new PathString((string)_env["owin.RequestPath"]);
}
set
{
_env["owin.RequestPath"] = value.Value;
}
}
public override PathString PathBase
{
get
{
return new PathString((string)_env["owin.RequestPathBase"]);
}
set
{
_env["owin.RequestPathBase"] = value.Value;
}
}
public override QueryString QueryString
{
get
{
return new QueryString((string)_env["owin.RequestQueryString"]);
}
set
{
_env["owin.RequestQueryString"] = value.Value;
}
}
public override Uri Uri
{
get
{
// TODO: Implement this sometime
throw new NotImplementedException();
}
}
}
private class RawOwinHttpResponse : HttpResponse
{
private readonly HttpContext _context;
private readonly IDictionary<string, object> _env;
public RawOwinHttpResponse(HttpContext context, IDictionary<string, object> env)
{
_context = context;
_env = env;
}
public override Stream Body
{
get
{
return (Stream)_env["owin.ResponseBody"];
}
set
{
_env["owin.ResponseBody"] = value;
}
}
public override string ContentType
{
get
{
return GetHeader("Content-Type");
}
set
{
SetHeader("Content-Type", value);
}
}
public override HttpContext HttpContext
{
get { return _context; }
}
public override int StatusCode
{
get
{
return (int)_env["owin.ResponseStatusCode"];
}
set
{
_env["owin.ResponseStatusCode"] = value;
}
}
public override Task WriteAsync(string data)
{
var bytes = Encoding.UTF8.GetBytes(data);
return Body.WriteAsync(bytes, 0, bytes.Length);
}
private void SetHeader(string name, string value)
{
var headers = (IDictionary<string, string[]>)_env["owin.ResponseHeaders"];
headers[name] = new[] { value };
}
private string GetHeader(string name)
{
var headers = (IDictionary<string, string[]>)_env["owin.ResponseHeaders"];
string[] values;
if (headers.TryGetValue(name, out values) && values.Length > 0)
{
return values[0];
}
return null;
}
}
}
}

View File

@ -1,15 +0,0 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Abstractions": ""
},
"configurations": {
"net45": {
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0"
}
},
"k10": {}
}
}

View File

@ -13,18 +13,18 @@ namespace Microsoft.AspNet.Abstractions
public abstract void Dispose();
public abstract object GetInterface(Type type);
public abstract object GetFeature(Type type);
public abstract void SetInterface(Type type, object instance);
public abstract void SetFeature(Type type, object instance);
public virtual T GetInterface<T>()
public virtual T GetFeature<T>()
{
return (T)GetInterface(typeof(T));
return (T)GetFeature(typeof(T));
}
public virtual void SetInterface<T>(T instance)
public virtual void SetFeature<T>(T instance)
{
SetInterface(typeof(T), instance);
SetFeature(typeof(T), instance);
}
}
}

View File

@ -58,12 +58,6 @@ namespace Microsoft.AspNet.Abstractions
/// <returns>The query value collection parsed from owin.RequestQueryString.</returns>
public abstract IReadableStringCollection Query { get; }
/// <summary>
/// Gets the uniform resource identifier (URI) associated with the request.
/// </summary>
/// <returns>The uniform resource identifier (URI) associated with the request.</returns>
public abstract Uri Uri { get; }
/// <summary>
/// Gets or set the owin.RequestProtocol.
/// </summary>

View File

@ -2,14 +2,15 @@ using System;
namespace Microsoft.AspNet.Abstractions
{
public interface IBuilder
public interface IBuilder
{
IBuilder Use(object middleware, params object[] args);
IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware);
IBuilder Run(RequestDelegate handler);
IBuilder New();
RequestDelegate Build();
object GetItem(Type type);
object GetItem(Type type);
void SetItem(Type type, object feature);
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.PipelineCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.PipelineCore.Owin;
namespace Owin
{
using AppFunc = Func<IDictionary<string, object>, Task>;
public static class AppBuilderSupportExtensions
{
public static IAppBuilder UseBuilder(this IAppBuilder appBuilder, Action<IBuilder> configuration)
{
IBuilder builder = new Builder();
configuration(builder);
Func<AppFunc,AppFunc> middleware1 = next1 => {
Func<RequestDelegate,RequestDelegate> middleware2 = next2 => {
return httpContext => {
return next1(httpContext.GetFeature<ICanHasOwinEnvironment>().Environment);
};
};
builder.Use(middleware2);
var app = builder.Build();
return env =>
{
return app.Invoke(
new DefaultHttpContext(
new FeatureCollection(
new FeatureObject(
new OwinHttpEnvironment(env)))));
};
};
return appBuilder.Use(middleware1);
}
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Microsoft.AspNet.PipelineCore.Owin
{
public interface ICanHasOwinEnvironment
{
IDictionary<string, object> Environment { get; set; }
}
}

View File

@ -9,12 +9,16 @@ using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.Interfaces;
namespace Microsoft.AspNet.PipelineCore.Owin
{
public class OwinHttpEnvironment :
IHttpRequestInformation, IHttpResponseInformation, IHttpConnection, IHttpSendFile, IHttpTransportLayerSecurity
IHttpRequestInformation,
IHttpResponseInformation,
IHttpConnection,
IHttpSendFile,
IHttpTransportLayerSecurity,
ICanHasOwinEnvironment
{
public IDictionary<string, object> Environment { get; set; }
@ -44,11 +48,6 @@ namespace Microsoft.AspNet.PipelineCore.Owin
set { Prop("owin.RequestProtocol", value); }
}
Uri IHttpRequestInformation.Uri
{
get { throw new NotImplementedException(); }
}
string IHttpRequestInformation.Scheme
{
get { return Prop<string>("owin.RequestScheme"); }

View File

@ -0,0 +1,16 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.FeatureModel": "0.1-alpha-*",
"Microsoft.AspNet.PipelineCore": "0.1-alpha-*",
"Microsoft.AspNet.HttpFeature" : ""
},
"configurations": {
"net45": {
"dependencies": {
"Owin": "1.0"
}
}
}
}

View File

@ -6,19 +6,19 @@ using Microsoft.AspNet.FeatureModel.Implementation;
namespace Microsoft.AspNet.FeatureModel
{
public class InterfaceDictionary : IInterfaceDictionary
public class FeatureCollection : IFeatureCollection
{
private readonly IInterfaceDictionary _defaults;
private readonly IFeatureCollection _defaults;
private readonly IDictionary<Type, object> _featureByFeatureType = new Dictionary<Type, object>();
private readonly IDictionary<string, Type> _featureTypeByName = new Dictionary<string, Type>();
private readonly object _containerSync = new Object();
private int _containerRevision;
public InterfaceDictionary()
public FeatureCollection()
{
}
public InterfaceDictionary(IInterfaceDictionary defaults)
public FeatureCollection(IFeatureCollection defaults)
{
_defaults = defaults;
}
@ -174,7 +174,8 @@ namespace Microsoft.AspNet.FeatureModel
public bool TryGetValue(Type key, out object value)
{
throw new NotImplementedException();
value = GetInterface(key);
return value != null;
}
public object this[Type key]

View File

@ -1,16 +1,17 @@
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using Microsoft.AspNet.FeatureModel.Implementation;
namespace Microsoft.AspNet.FeatureModel
{
public class InterfaceObject : IInterfaceDictionary
public class FeatureObject : IFeatureCollection
{
private readonly object _instance;
public InterfaceObject(object instance)
public FeatureObject(object instance)
{
_instance = instance;
}
@ -31,7 +32,7 @@ namespace Microsoft.AspNet.FeatureModel
{
return _instance;
}
foreach (var interfaceType in _instance.GetType().GetInterfaces())
{
if (interfaceType.FullName == type.FullName)
@ -55,7 +56,16 @@ namespace Microsoft.AspNet.FeatureModel
public IEnumerator<KeyValuePair<Type, object>> GetEnumerator()
{
throw new NotImplementedException();
return GetTypeInterfaces()
.Select(interfaceType => new KeyValuePair<Type, object>(interfaceType, _instance))
.GetEnumerator();
}
private IEnumerable<Type> GetTypeInterfaces()
{
return _instance.GetType()
.GetTypeInfo()
.ImplementedInterfaces;
}
IEnumerator IEnumerable.GetEnumerator()
@ -80,7 +90,23 @@ namespace Microsoft.AspNet.FeatureModel
public void CopyTo(KeyValuePair<Type, object>[] array, int arrayIndex)
{
throw new NotImplementedException();
var enumerator = GetTypeInterfaces().GetEnumerator();
for (var index = 0; index != arrayIndex; ++index)
{
if (!enumerator.MoveNext())
{
throw new IndexOutOfRangeException();
}
}
for (var index = 0; index != array.Length; ++index)
{
if (!enumerator.MoveNext())
{
throw new IndexOutOfRangeException();
}
array[index] = new KeyValuePair<Type, object>(enumerator.Current, _instance);
}
}
public bool Remove(KeyValuePair<Type, object> item)
@ -90,17 +116,17 @@ namespace Microsoft.AspNet.FeatureModel
public int Count
{
get { throw new NotImplementedException(); }
get { return GetTypeInterfaces().Count(); }
}
public bool IsReadOnly
{
get { throw new NotImplementedException(); }
get { return true; }
}
public bool ContainsKey(Type key)
{
throw new NotImplementedException();
return key.GetTypeInfo().IsAssignableFrom(_instance.GetType().GetTypeInfo());
}
public void Add(Type key, object value)
@ -115,23 +141,33 @@ namespace Microsoft.AspNet.FeatureModel
public bool TryGetValue(Type key, out object value)
{
throw new NotImplementedException();
value = GetInterface(key);
return value != null;
}
public object this[Type key]
{
get { throw new NotImplementedException(); }
get { return GetInterface(key); }
set { throw new NotImplementedException(); }
}
public ICollection<Type> Keys
{
get { throw new NotImplementedException(); }
get { return GetTypeInterfaces().ToArray(); }
}
public ICollection<object> Values
{
get { throw new NotImplementedException(); }
get
{
var length = GetTypeInterfaces().Count();
var array = new object[length];
for (var index = 0; index != length; ++index)
{
array[index] = _instance;
}
return array;
}
}
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Microsoft.AspNet.FeatureModel
{
public interface IInterfaceDictionary : IDictionary<Type, object>, IDisposable
public interface IFeatureCollection : IDictionary<Type, object>, IDisposable
{
int Revision { get; }
}

View File

@ -1,8 +0,0 @@
using Microsoft.AspNet.FeatureModel;
namespace Microsoft.AspNet.HttpEnvironment
{
public abstract class HttpEnvironment : InterfaceDictionary, IHttpEnvironment
{
}
}

View File

@ -1,8 +0,0 @@
using Microsoft.AspNet.FeatureModel;
namespace Microsoft.AspNet.HttpEnvironment
{
public interface IHttpEnvironment : IInterfaceDictionary
{
}
}

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 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.
[assembly: AssemblyTitle("Microsoft.AspNet.Environments")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.AspNet.Environments")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1b326e9f-7c7a-42cd-9861-cdbef8353aed")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyFileVersion("0.1.0")]

View File

@ -1,9 +0,0 @@
{
"dependencies": {
"Microsoft.AspNet.FeatureModel" : ""
},
"configurations": {
"net45": { },
"k10" : { }
}
}

View File

@ -14,6 +14,11 @@ namespace Microsoft.AspNet.HttpFeature
string QueryString { get; set; }
IDictionary<string, string[]> Headers { get; set; }
Stream Body { get; set; }
Uri Uri { get; }
// FURI: Uri Uri { get; }
}
public interface ICanHasSession
{
}
}

View File

@ -12,4 +12,4 @@ namespace Microsoft.AspNet.HttpFeature
#endif
Task LoadAsync();
}
}
}

View File

@ -9,17 +9,17 @@ namespace Microsoft.AspNet.PipelineCore
{
public class Builder : IBuilder
{
private readonly IInterfaceDictionary _interfaces;
private readonly IFeatureCollection _interfaces;
private readonly IDictionary<string, object> _properties;
private readonly IList<Entry> _components = new List<Entry>();
private readonly IList<Func<RequestDelegate, RequestDelegate>> _components = new List<Func<RequestDelegate, RequestDelegate>>();
public Builder()
{
_interfaces = new InterfaceDictionary();
_interfaces = new FeatureCollection();
_properties = new Dictionary<string, object>();
}
public Builder(IInterfaceDictionary interfaces, IDictionary<string, object> properties)
public Builder(IFeatureCollection interfaces, IDictionary<string, object> properties)
{
_interfaces = interfaces;
_properties = properties;
@ -52,22 +52,15 @@ namespace Microsoft.AspNet.PipelineCore
_properties[key] = value;
}
public IBuilder Use(object middleware, params object[] args)
public IBuilder Use(Func<RequestDelegate, RequestDelegate> middleware)
{
_components.Add(new Entry(middleware, args));
_components.Add(middleware);
return this;
}
class Entry
public IBuilder Run(RequestDelegate handler)
{
private readonly object _middleware;
private readonly object[] _args;
public Entry(object middleware, object[] args)
{
_middleware = middleware;
_args = args;
}
return Use(next => handler);
}
public IBuilder New()
@ -81,20 +74,10 @@ namespace Microsoft.AspNet.PipelineCore
foreach (var component in _components.Reverse())
{
app = Activate(component, app);
app = component(app);
}
return app;
}
private RequestDelegate Activate(Entry component, RequestDelegate app)
{
return app;
}
public Func<TContext, Task> Adapt<TContext>(object app)
{
return null;
}
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace Microsoft.AspNet.PipelineCore
{
public class DefaultCanHasItems : ICanHasItems
{
public DefaultCanHasItems()
{
Items = new Dictionary<object, object>();
}
public IDictionary<object, object> Items { get; private set; }
}
}

View File

@ -0,0 +1,37 @@
using System.Collections.Generic;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.PipelineCore.Collections;
using Microsoft.AspNet.PipelineCore.Infrastructure;
namespace Microsoft.AspNet.PipelineCore
{
public class DefaultCanHasQuery : ICanHasQuery
{
private readonly IFeatureCollection _features;
private FeatureReference<IHttpRequestInformation> _request = new FeatureReference<IHttpRequestInformation>();
private string _queryString;
private IReadableStringCollection _query;
public DefaultCanHasQuery(IFeatureCollection features)
{
_features = features;
}
public IReadableStringCollection Query
{
get
{
var queryString = _request.Fetch(_features).QueryString;
if (_query == null || _queryString != queryString)
{
_queryString = queryString;
// TODO
_query = new ReadableStringCollection(new Dictionary<string, string[]>());
}
return _query;
}
}
}
}

View File

@ -0,0 +1,45 @@
using System;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.PipelineCore.Infrastructure;
namespace Microsoft.AspNet.PipelineCore
{
public class DefaultCanHasRequestCookies : ICanHasRequestCookies
{
private readonly IFeatureCollection _features;
private FeatureReference<IHttpRequestInformation> _request = new FeatureReference<IHttpRequestInformation>();
private string _cookiesHeader;
private RequestCookiesCollection _cookiesCollection;
private static readonly string[] ZeroHeaders = new string[0];
public DefaultCanHasRequestCookies(IFeatureCollection features)
{
_features = features;
}
public IReadableStringCollection Cookies
{
get
{
var headers = _request.Fetch(_features).Headers;
string cookiesHeader = ParsingHelpers.GetHeader(headers, "Cookies") ?? "";
if (_cookiesCollection == null)
{
_cookiesCollection = new RequestCookiesCollection();
_cookiesCollection.Reparse(cookiesHeader);
_cookiesHeader = cookiesHeader;
}
else if (!string.Equals(_cookiesHeader, cookiesHeader, StringComparison.Ordinal))
{
_cookiesCollection.Reparse(cookiesHeader);
_cookiesHeader = cookiesHeader;
}
return _cookiesCollection;
}
}
}
}

View File

@ -1,43 +1,59 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.PipelineCore.Infrastructure;
namespace Microsoft.AspNet.PipelineCore
{
public class DefaultHttpContext : HttpContext
{
private readonly IInterfaceDictionary _environment;
private readonly HttpRequest _request;
private readonly HttpResponse _response;
public DefaultHttpContext(IInterfaceDictionary environment)
private FeatureReference<ICanHasItems> _canHasItems;
private IFeatureCollection _features;
public DefaultHttpContext(IFeatureCollection features)
{
_environment = environment;
_request = new DefaultHttpRequest(this);
_response = new DefaultHttpResponse(this);
_features = features;
_request = new DefaultHttpRequest(this, features);
_response = new DefaultHttpResponse(this, features);
_canHasItems = new FeatureReference<ICanHasItems>();
}
ICanHasItems CanHasItems
{
get { return _canHasItems.Fetch(_features) ?? _canHasItems.Update(_features, new DefaultCanHasItems()); }
}
public override HttpRequest Request { get { return _request; } }
public override HttpResponse Response { get { return _response; } }
public int Revision { get { return _environment.Revision; } }
public override IDictionary<object, object> Items
{
get { return CanHasItems.Items; }
}
public int Revision { get { return _features.Revision; } }
public override void Dispose()
{
// REVIEW: is this necessary? is the environment "owned" by the context?
_environment.Dispose();
_features.Dispose();
}
public override object GetInterface(Type type)
public override object GetFeature(Type type)
{
object value;
return _environment.TryGetValue(type, out value) ? value : null;
return _features.TryGetValue(type, out value) ? value : null;
}
public override void SetInterface(Type type, object instance)
public override void SetFeature(Type type, object instance)
{
_environment[type] = instance;
_features[type] = instance;
}
}
}

View File

@ -1,98 +1,91 @@
using System;
using System.IO;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.Interfaces;
using Microsoft.AspNet.PipelineCore.Infrastructure;
namespace Microsoft.AspNet.PipelineCore
{
public class DefaultHttpRequest : HttpRequest
{
private readonly DefaultHttpContext _context;
private int _revision;
private IHttpRequestInformation _request;
private IHttpConnection _connection;
private readonly IFeatureCollection _features;
public DefaultHttpRequest(DefaultHttpContext context)
private FeatureReference<IHttpRequestInformation> _request = new FeatureReference<IHttpRequestInformation>();
private FeatureReference<IHttpConnection> _connection = new FeatureReference<IHttpConnection>();
private FeatureReference<IHttpTransportLayerSecurity> _transportLayerSecurity = new FeatureReference<IHttpTransportLayerSecurity>();
private FeatureReference<ICanHasQuery> _canHasQuery = new FeatureReference<ICanHasQuery>();
private FeatureReference<ICanHasRequestCookies> _canHasCookies = new FeatureReference<ICanHasRequestCookies>();
public DefaultHttpRequest(DefaultHttpContext context, IFeatureCollection features)
{
_context = context;
_features = features;
}
private IHttpRequestInformation IHttpRequest
private IHttpRequestInformation HttpRequestInformation
{
get { return EnsureCurrent(_request) ?? (_request = _context.GetInterface<IHttpRequestInformation>()); }
get { return _request.Fetch(_features); }
}
private IHttpConnection IHttpConnection
private IHttpConnection HttpConnection
{
get { return EnsureCurrent(_connection) ?? (_connection = _context.GetInterface<IHttpConnection>()); }
get { return _connection.Fetch(_features); }
}
private T EnsureCurrent<T>(T feature) where T : class
private IHttpTransportLayerSecurity HttpTransportLayerSecurity
{
if (_revision == _context.Revision) return feature;
get { return _transportLayerSecurity.Fetch(_features); }
}
private ICanHasQuery CanHasQuery
{
get { return _canHasQuery.Fetch(_features) ?? _canHasQuery.Update(_features, new DefaultCanHasQuery(_features)); }
}
private ICanHasRequestCookies CanHasRequestCookies
{
get { return _canHasCookies.Fetch(_features) ?? _canHasCookies.Update(_features, new DefaultCanHasRequestCookies(_features)); }
}
_request = null;
_connection = null;
_revision = _context.Revision;
return null;
}
public override HttpContext HttpContext { get { return _context; } }
public override Uri Uri
{
get { return IHttpRequest.Uri; }
}
//public override Uri Uri { get { _request} }
public override PathString PathBase
{
get { return new PathString(IHttpRequest.PathBase); }
set { IHttpRequest.PathBase = value.Value; }
get { return new PathString(HttpRequestInformation.PathBase); }
set { HttpRequestInformation.PathBase = value.Value; }
}
public override PathString Path
{
get { return new PathString(IHttpRequest.Path); }
set { IHttpRequest.Path = value.Value; }
get { return new PathString(HttpRequestInformation.Path); }
set { HttpRequestInformation.Path = value.Value; }
}
public override QueryString QueryString
{
get { return new QueryString(IHttpRequest.QueryString); }
set { IHttpRequest.QueryString = value.Value; }
get { return new QueryString(HttpRequestInformation.QueryString); }
set { HttpRequestInformation.QueryString = value.Value; }
}
public override Stream Body
{
get { return IHttpRequest.Body; }
set { IHttpRequest.Body = value; }
get { return HttpRequestInformation.Body; }
set { HttpRequestInformation.Body = value; }
}
public override string Method
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
get { return HttpRequestInformation.Method; }
set { HttpRequestInformation.Method = value; }
}
public override string Scheme
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
get { return HttpRequestInformation.Scheme; }
set { HttpRequestInformation.Scheme = value; }
}
public override bool IsSecure
@ -114,19 +107,13 @@ namespace Microsoft.AspNet.PipelineCore
public override IReadableStringCollection Query
{
get { throw new NotImplementedException(); }
get { return CanHasQuery.Query; }
}
public override string Protocol
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
get { return HttpRequestInformation.Protocol; }
set { HttpRequestInformation.Protocol = value; }
}
public override IHeaderDictionary Headers
@ -136,7 +123,7 @@ namespace Microsoft.AspNet.PipelineCore
public override IReadableStringCollection Cookies
{
get { throw new NotImplementedException(); }
get { return CanHasRequestCookies.Cookies; }
}
public override System.Threading.CancellationToken CallCanceled

View File

@ -2,56 +2,53 @@
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.HttpFeature.Security;
using Microsoft.AspNet.PipelineCore.Infrastructure;
namespace Microsoft.AspNet.PipelineCore
{
public class DefaultHttpResponse : HttpResponse
{
private readonly DefaultHttpContext _context;
private IHttpResponseInformation _response;
private int _revision;
private readonly IFeatureCollection _features;
private FeatureReference<IHttpResponseInformation> _response = FeatureReference<IHttpResponseInformation>.Default;
public DefaultHttpResponse(DefaultHttpContext context)
public DefaultHttpResponse(DefaultHttpContext context, IFeatureCollection features)
{
_context = context;
_features = features;
}
private IHttpResponseInformation IHttpResponse
private IHttpResponseInformation HttpResponseInformation
{
get { return EnsureCurrent(_response) ?? (_response = _context.GetInterface<IHttpResponseInformation>()); }
}
private T EnsureCurrent<T>(T feature) where T : class
{
if (_revision == _context.Revision) return feature;
_response = null;
_revision = _context.Revision;
return null;
get { return _response.Fetch(_features); }
}
public override HttpContext HttpContext { get { return _context; } }
public override int StatusCode
{
get { return IHttpResponse.StatusCode; }
set { IHttpResponse.StatusCode = value; }
get { return HttpResponseInformation.StatusCode; }
set { HttpResponseInformation.StatusCode = value; }
}
public override Stream Body { get { return _response.Body; } set { _response.Body = value; } }
public override Stream Body
{
get { return HttpResponseInformation.Body; }
set { HttpResponseInformation.Body = value; }
}
public override string ContentType
{
get
{
var contentTypeValues = IHttpResponse.Headers["Content-Type"];
var contentTypeValues = HttpResponseInformation.Headers["Content-Type"];
return contentTypeValues.Length == 0 ? null : contentTypeValues[0];
}
set
{
IHttpResponse.Headers["Content-Type"] = new[] { value };
HttpResponseInformation.Headers["Content-Type"] = new[] { value };
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Microsoft.AspNet.PipelineCore
{
public interface ICanHasItems
{
IDictionary<object, object> Items { get; }
}
}

View File

@ -0,0 +1,9 @@
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.PipelineCore
{
public interface ICanHasQuery
{
IReadableStringCollection Query { get; }
}
}

View File

@ -0,0 +1,9 @@
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.PipelineCore
{
public interface ICanHasRequestCookies
{
IReadableStringCollection Cookies { get; }
}
}

View File

@ -0,0 +1,41 @@
using Microsoft.AspNet.FeatureModel;
namespace Microsoft.AspNet.PipelineCore.Infrastructure
{
internal struct FeatureReference<T>
{
private T _feature;
private int _revision;
private FeatureReference(T feature, int revision)
{
_feature = feature;
_revision = revision;
}
public static readonly FeatureReference<T> Default = new FeatureReference<T>(default(T), -1);
public T Fetch(IFeatureCollection features)
{
if (_revision == features.Revision) return _feature;
object value;
if (features.TryGetValue(typeof(T), out value))
{
_feature = (T)value;
}
else
{
_feature = default(T);
}
_revision = features.Revision;
return _feature;
}
public T Update(IFeatureCollection features, T feature)
{
features[typeof(T)] = _feature = feature;
_revision = features.Revision;
return feature;
}
}
}

View File

@ -545,6 +545,11 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
return cookies;
}
internal static void ParseCookies(string cookiesHeader, IDictionary<string, string> cookiesCollection)
{
ParseDelimited(cookiesHeader, SemicolonAndComma, AddCookieCallback, cookiesCollection);
}
internal static void ParseDelimited(string text, char[] delimiters, Action<string, string, object> callback, object state)
{
int textLength = text.Length;
@ -851,19 +856,19 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
internal static partial class ParsingHelpers
{
internal static string GetHost(HttpRequest request)
{
IHeaderDictionary headers = request.Headers;
//internal static string GetHost(HttpRequest request)
//{
// IHeaderDictionary headers = request.Headers;
string host = GetHeader(headers, "Host");
if (!string.IsNullOrWhiteSpace(host))
{
return host;
}
// string host = GetHeader(headers, "Host");
// if (!string.IsNullOrWhiteSpace(host))
// {
// return host;
// }
string localIpAddress = request.LocalIpAddress ?? "localhost";
var localPort = request.Get<string>(OwinConstants.CommonKeys.LocalPort);
return string.IsNullOrWhiteSpace(localPort) ? localIpAddress : (localIpAddress + ":" + localPort);
}
// string localIpAddress = request.LocalIpAddress ?? "localhost";
// var localPort = request.Get<string>(OwinConstants.CommonKeys.LocalPort);
// return string.IsNullOrWhiteSpace(localPort) ? localIpAddress : (localIpAddress + ":" + localPort);
//}
}
}

View File

@ -41,18 +41,24 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Builder.cs" />
<Compile Include="DefaultCanHasItems.cs" />
<Compile Include="DefaultCanHasQuery.cs" />
<Compile Include="DefaultCanHasRequestCookies.cs" />
<Compile Include="DefaultHttpContext.cs" />
<Compile Include="DefaultHttpRequest.cs" />
<Compile Include="DefaultHttpResponse.cs" />
<Compile Include="ICanHasItems.cs" />
<Compile Include="ICanHasQuery.cs" />
<Compile Include="ICanHasRequestCookies.cs" />
<Compile Include="RequestCookiesCollection.cs" />
<Compile Include="Collections\FormCollection.cs" />
<Compile Include="Collections\HeaderDictionary.cs" />
<Compile Include="Collections\ReadableStringCollection.cs" />
<Compile Include="Collections\RequestCookieCollection.cs" />
<Compile Include="Collections\ResponseCookieCollection.cs" />
<Compile Include="Infrastructure\Constants.cs" />
<Compile Include="Infrastructure\FeatureReference.cs" />
<Compile Include="Infrastructure\ParsingHelpers.cs" />
<Compile Include="Owin\OwinConstants.cs" />
<Compile Include="Owin\OwinHttpEnvironment.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Content Include="project.json"/>
</ItemGroup>

View File

@ -0,0 +1,65 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.PipelineCore.Infrastructure;
namespace Microsoft.AspNet.PipelineCore
{
public class RequestCookiesCollection : IReadableStringCollection
{
private readonly IDictionary<string, string> _dictionary;
public RequestCookiesCollection()
{
_dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
public IEnumerator<KeyValuePair<string, string[]>> GetEnumerator()
{
foreach (var pair in _dictionary)
{
yield return new KeyValuePair<string, string[]>(pair.Key, new[] { pair.Value });
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public string this[string key]
{
get { return Get(key); }
}
public string Get(string key)
{
string value;
return _dictionary.TryGetValue(key, out value) ? value : null;
}
public IList<string> GetValues(string key)
{
string value;
return _dictionary.TryGetValue(key, out value) ? new[] { value } : null;
}
private static readonly char[] SemicolonAndComma = { ';', ',' };
public void Reparse(string cookiesHeader)
{
_dictionary.Clear();
ParsingHelpers.ParseDelimited(cookiesHeader, SemicolonAndComma, AddCookieCallback, _dictionary);
}
private static readonly Action<string, string, object> AddCookieCallback = (name, value, state) =>
{
var dictionary = (IDictionary<string, string>)state;
if (!dictionary.ContainsKey(name))
{
dictionary.Add(name, value);
}
};
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Abstractions;
using Owin;
using Xunit;
namespace Microsoft.AspNet.AppBuilderSupport.Tests
{
public class AppBuilderSupportTests
{
[Fact]
public async Task BuildCanGoInsideAppBuilder()
{
var server = Microsoft.Owin.Testing.TestServer.Create(
app => app.UseBuilder(HelloWorld));
var result = await server.CreateRequest("/hello").GetAsync();
var body = await result.Content.ReadAsStringAsync();
Assert.Equal(result.StatusCode, HttpStatusCode.Accepted);
Assert.Equal(body, "Hello world!");
}
private void HelloWorld(IBuilder builder)
{
builder.Use(next => async context =>
{
await next(context);
});
builder.Run(async context =>
{
context.Response.StatusCode = 202;
await context.Response.WriteAsync("Hello world!");
});
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.PipelineCore.Owin;
using Xunit;
namespace Microsoft.AspNet.AppBuilderSupport.Tests
{
public class OwinHttpEnvironmentTests
{
private T Get<T>(IFeatureCollection features)
{
object value;
return features.TryGetValue(typeof(T), out value) ? (T)value : default(T);
}
[Fact]
public void OwinHttpEnvironmentCanBeCreated()
{
var env = new Dictionary<string, object>
{
{"owin.RequestMethod", "POST"}
};
var features = new FeatureObject( new OwinHttpEnvironment(env));
Assert.Equal(Get<IHttpRequestInformation>(features).Method, "POST");
}
[Fact]
public void ImplementedInterfacesAreEnumerated()
{
var env = new Dictionary<string, object>
{
{"owin.RequestMethod", "POST"}
};
var features = new FeatureObject(new OwinHttpEnvironment(env));
var entries = features.ToArray();
var keys = features.Keys.ToArray();
var values = features.Values.ToArray();
Assert.Contains(typeof(IHttpRequestInformation), keys);
Assert.Contains(typeof(IHttpResponseInformation), keys);
}
}
}

View File

@ -0,0 +1,23 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.AppBuilderSupport": "",
"Microsoft.AspNet.HttpFeature": "",
"Microsoft.AspNet.Abstractions": "",
"Microsoft.AspNet.FeatureModel": ""
},
"configurations": {
"net45": {
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0",
"Microsoft.Owin.Hosting": "2.1.0",
"Microsoft.Owin.Testing": "2.1.0",
"Shouldly": "1.1.1.1",
"xunit": "1.9.2",
"Microsoft.Net.Http": "2.2.13",
"System.Net.Http": ""
}
}
}
}

View File

@ -0,0 +1,7 @@
namespace Microsoft.AspNet.FeatureModel.Tests
{
public interface IThing
{
string Hello();
}
}

View File

@ -4,25 +4,12 @@ using Xunit;
namespace Microsoft.AspNet.FeatureModel.Tests
{
public interface IThing
{
string Hello();
}
public class Thing : IThing
{
public string Hello()
{
return "World";
}
}
public class InterfaceDictionaryTests
{
[Fact]
public void AddedInterfaceIsReturned()
{
var interfaces = new InterfaceDictionary();
var interfaces = new FeatureCollection();
var thing = new Thing();
interfaces.Add(typeof(IThing), thing);
@ -37,7 +24,7 @@ namespace Microsoft.AspNet.FeatureModel.Tests
[Fact]
public void IndexerAlsoAddsItems()
{
var interfaces = new InterfaceDictionary();
var interfaces = new FeatureCollection();
var thing = new Thing();
interfaces[typeof(IThing)] = thing;
@ -52,7 +39,7 @@ namespace Microsoft.AspNet.FeatureModel.Tests
[Fact]
public void SecondCallToAddThrowsException()
{
var interfaces = new InterfaceDictionary();
var interfaces = new FeatureCollection();
var thing = new Thing();
interfaces.Add(typeof(IThing), thing);

View File

@ -1,66 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8C671AE3-1188-499F-A2A2-3A0B117B33CE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AspNet.FeatureModel.Tests</RootNamespace>
<AssemblyName>Microsoft.AspNet.FeatureModel.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Shouldly">
<HintPath>..\..\packages\Shouldly.1.1.1.1\lib\35\Shouldly.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="xunit">
<HintPath>..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNet.FeatureModel\Microsoft.AspNet.FeatureModel.net45.csproj">
<Project>{95aee59d-bf51-47cb-a957-c03d909cc148}</Project>
<Name>Microsoft.AspNet.FeatureModel.net45</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,10 @@
namespace Microsoft.AspNet.FeatureModel.Tests
{
public class Thing : IThing
{
public string Hello()
{
return "World";
}
}
}

View File

@ -0,0 +1,17 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.AppBuilderSupport": "",
"Microsoft.AspNet.HttpFeature": "",
"Microsoft.AspNet.Abstractions": "",
"Microsoft.AspNet.FeatureModel": ""
},
"configurations": {
"net45": {
"dependencies": {
"Shouldly": "1.1.1.1",
"xunit": "1.9.2"
}
}
}
}

View File

@ -0,0 +1,23 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.AppBuilderSupport": "",
"Microsoft.AspNet.HttpFeature": "",
"Microsoft.AspNet.Abstractions": "",
"Microsoft.AspNet.FeatureModel": ""
},
"configurations": {
"net45": {
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0",
"Microsoft.Owin.Hosting": "2.1.0",
"Microsoft.Owin.Testing": "2.1.0",
"Moq": "4.2.1312.1622",
"xunit": "1.9.2",
"Microsoft.Net.Http": "2.2.13",
"System.Net.Http": ""
}
}
}
}