Removed unneeded dependencies and updated owin bits.
This commit is contained in:
parent
7adb658a38
commit
477cf79e58
|
|
@ -7,8 +7,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Mvc", "src
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcSample", "samples\MvcSample\MvcSample.csproj", "{069EA0A1-BB68-41D1-A973-3429EC09264C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.CoreServices", "src\Microsoft.AspNet.CoreServices\Microsoft.AspNet.CoreServices.csproj", "{EC38534C-A2D1-413F-97D1-55EEF5D2FB71}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Mvc.Razor", "src\Microsoft.AspNet.Mvc.Razor\Microsoft.AspNet.Mvc.Razor.csproj", "{224A14D0-ECA7-441C-AE89-B6E66A57EF9B}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DAAE4C74-D06F-4874-A166-33305D2643CE}"
|
||||
|
|
@ -31,10 +29,6 @@ Global
|
|||
{069EA0A1-BB68-41D1-A973-3429EC09264C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{069EA0A1-BB68-41D1-A973-3429EC09264C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{069EA0A1-BB68-41D1-A973-3429EC09264C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EC38534C-A2D1-413F-97D1-55EEF5D2FB71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EC38534C-A2D1-413F-97D1-55EEF5D2FB71}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EC38534C-A2D1-413F-97D1-55EEF5D2FB71}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EC38534C-A2D1-413F-97D1-55EEF5D2FB71}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{224A14D0-ECA7-441C-AE89-B6E66A57EF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{224A14D0-ECA7-441C-AE89-B6E66A57EF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{224A14D0-ECA7-441C-AE89-B6E66A57EF9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
@ -48,7 +42,6 @@ Global
|
|||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{EC38534C-A2D1-413F-97D1-55EEF5D2FB71} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{224A14D0-ECA7-441C-AE89-B6E66A57EF9B} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{2A0C26F1-0240-4AE1-AE00-4691C291B122} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{AB4CDC03-176C-460F-8955-4202F6D53FED} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
|
|
|
|||
|
|
@ -39,16 +39,21 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\net45\Microsoft.AspNet.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Diagnostics">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Diagnostics.2.0.2\lib\net40\Microsoft.Owin.Diagnostics.dll</HintPath>
|
||||
<Reference Include="Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Diagnostics.2.1.0\lib\net40\Microsoft.Owin.Diagnostics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.FileSystems, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.FileSystems.2.1.0-rc1\lib\net40\Microsoft.Owin.FileSystems.dll</HintPath>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.FileSystems.2.1.0\lib\net40\Microsoft.Owin.FileSystems.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
|
|
@ -60,10 +65,6 @@
|
|||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.0.0\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config" />
|
||||
|
|
@ -76,10 +77,6 @@
|
|||
<Compile Include="Startup.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNet.CoreServices\Microsoft.AspNet.CoreServices.csproj">
|
||||
<Project>{ec38534c-a2d1-413f-97d1-55eef5d2fb71}</Project>
|
||||
<Name>Microsoft.AspNet.CoreServices</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Microsoft.AspNet.Mvc.Razor\Microsoft.AspNet.Mvc.Razor.csproj">
|
||||
<Project>{224a14d0-eca7-441c-ae89-b6e66a57ef9b}</Project>
|
||||
<Name>Microsoft.AspNet.Mvc.Razor</Name>
|
||||
|
|
@ -91,7 +88,6 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="web.config" />
|
||||
<Content Include="project.json" />
|
||||
<Content Include="Views\Home\MyView.cshtml" />
|
||||
<Content Include="Views\Shared\_Layout.cshtml" />
|
||||
<None Include="web.Debug.config">
|
||||
|
|
@ -112,18 +108,18 @@
|
|||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<UseIIS>False</UseIIS>
|
||||
<UseIIS>True</UseIIS>
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>48140</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:48140/</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>True</UseCustomServer>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
<servers defaultServer="OwinHost">
|
||||
<server name="OwinHost" exePath="{solutiondir}\packages\OwinHost.2.0.2\tools\OwinHost.exe" cmdArgs="-u {url}" url="http://localhost:12345/" workingDir="{projectdir}" />
|
||||
<servers defaultServer="">
|
||||
<server name="OwinHost" exePath="{solutiondir}\packages\OwinHost.2.1.0\tools\OwinHost.exe" cmdArgs="-u {url}" url="http://localhost:12345/" workingDir="{projectdir}" />
|
||||
</servers>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
|
|
@ -18,9 +17,10 @@ namespace MvcSample
|
|||
{
|
||||
app.UseErrorPage();
|
||||
|
||||
string appRoot = Environment.GetEnvironmentVariable("WEB_ROOT") ??
|
||||
AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
var serviceProvider = MvcServices.Create();
|
||||
|
||||
string appRoot = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
|
||||
|
||||
var fileSystem = new PhysicalFileSystem(appRoot);
|
||||
serviceProvider.AddInstance<IFileSystem>(new VirtualFileSystem(fileSystem));
|
||||
serviceProvider.AddInstance<ICompilationService>(new RazorCompilationService(new CscBasedCompilationService()));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.Diagnostics" version="2.0.2" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.FileSystems" version="2.1.0-rc1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.DependencyInjection" version="0.1-alpha-t140123020341" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.Diagnostics" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.FileSystems" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
<package id="OwinHost" version="2.0.2" targetFramework="net45" />
|
||||
<package id="OwinHost" version="2.1.0" targetFramework="net45" />
|
||||
</packages>
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Owin": "1.0",
|
||||
"Microsoft.Owin.Diagnostics": "2.0.2",
|
||||
"Microsoft.Owin": "2.0.2",
|
||||
"Microsoft.AspNet.Mvc": "",
|
||||
},
|
||||
"configurations": {
|
||||
"net45": {
|
||||
"dependencies": {
|
||||
"System.Net.Http" : ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"sources": ["src"],
|
||||
"packages": ["packages"]
|
||||
}
|
||||
|
|
@ -30,7 +30,8 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Owin">
|
||||
<Reference Include="Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin">
|
||||
|
|
@ -56,10 +57,6 @@
|
|||
<Compile Include="TypeHelpers.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNet.CoreServices\Microsoft.AspNet.CoreServices.csproj">
|
||||
<Project>{ec38534c-a2d1-413f-97d1-55eef5d2fb71}</Project>
|
||||
<Name>Microsoft.AspNet.CoreServices</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Microsoft.AspNet.Mvc\Microsoft.AspNet.Mvc.csproj">
|
||||
<Project>{2a0c26f1-0240-4ae1-ae00-4691c291b122}</Project>
|
||||
<Name>Microsoft.AspNet.Mvc</Name>
|
||||
|
|
|
|||
|
|
@ -30,12 +30,17 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\net45\Microsoft.AspNet.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.FileSystems">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.FileSystems.2.1.0-rc1\lib\net40\Microsoft.Owin.FileSystems.dll</HintPath>
|
||||
<Reference Include="Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.FileSystems, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.FileSystems.2.1.0\lib\net40\Microsoft.Owin.FileSystems.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
|
|
@ -43,15 +48,11 @@
|
|||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.Razor.3.1.0\lib\net45\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Compilation\CompilationFailedException.cs" />
|
||||
|
|
@ -81,10 +82,6 @@
|
|||
<Project>{ab4cdc03-176c-460f-8955-4202f6d53fed}</Project>
|
||||
<Name>Microsoft.AspNet.Mvc.Html</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Microsoft.AspNet.CoreServices\Microsoft.AspNet.CoreServices.csproj">
|
||||
<Project>{ec38534c-a2d1-413f-97d1-55eef5d2fb71}</Project>
|
||||
<Name>Microsoft.AspNet.CoreServices</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Microsoft.AspNet.Mvc\Microsoft.AspNet.Mvc.csproj">
|
||||
<Project>{2a0c26f1-0240-4ae1-ae00-4691c291b122}</Project>
|
||||
<Name>Microsoft.AspNet.Mvc</Name>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ using System.IO;
|
|||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
using Microsoft.Owin;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.FileSystems" version="2.1.0-rc1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.DependencyInjection" version="0.1-alpha-t140123020341" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.1.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin.FileSystems" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
</packages>
|
||||
|
|
@ -2,17 +2,12 @@
|
|||
"dependencies": {
|
||||
"Owin": "1.0",
|
||||
"Newtonsoft.Json": "4.5.11",
|
||||
"Microsoft.Owin": "2.0.2",
|
||||
"Microsoft.Owin.FileSystems": "2.0.2",
|
||||
"Microsoft.AspNet.WebApi.Client": "5.0.0",
|
||||
"Microsoft.Owin": "2.1.0",
|
||||
"Microsoft.Owin.FileSystems": "2.1.0",
|
||||
"Microsoft.AspNet.Mvc.Razor" : ""
|
||||
},
|
||||
"configurations": {
|
||||
"net45": {
|
||||
"dependencies": {
|
||||
"System.Net.Http" : ""
|
||||
}
|
||||
},
|
||||
"k10" : { }
|
||||
"net45": { },
|
||||
"k10" : { }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,4 @@
|
|||
using Microsoft.AspNet.CoreServices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -12,61 +6,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
public IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue, RequestContext requestContext)
|
||||
{
|
||||
// optimize common path
|
||||
IActionResult actionResult = actionReturnValue as IActionResult;
|
||||
|
||||
if (actionResult != null)
|
||||
return new ContentResult
|
||||
{
|
||||
return actionResult;
|
||||
}
|
||||
|
||||
bool isDeclaredTypeActionResult = typeof(IActionResult).IsAssignableFrom(declaredReturnType);
|
||||
bool isDeclaredTypeResponseMessage = typeof(HttpResponseMessage).IsAssignableFrom(declaredReturnType);
|
||||
|
||||
if ((isDeclaredTypeActionResult || isDeclaredTypeResponseMessage) && actionReturnValue == null)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot return null from an action method declaring IActionResult or HttpResponseMessage");
|
||||
}
|
||||
|
||||
if (declaredReturnType == null)
|
||||
{
|
||||
throw new InvalidOperationException("Declared type must be passed");
|
||||
}
|
||||
|
||||
if (declaredReturnType.IsGenericParameter)
|
||||
{
|
||||
// This can happen if somebody declares an action method as:
|
||||
// public T Get<T>() { }
|
||||
throw new InvalidOperationException("HttpActionDescriptor_NoConverterForGenericParamterTypeExists");
|
||||
}
|
||||
|
||||
if (declaredReturnType.IsAssignableFrom(typeof(void)))
|
||||
{
|
||||
return new NoContentResult();
|
||||
}
|
||||
|
||||
var responseMessage = actionReturnValue as HttpResponseMessage;
|
||||
if (responseMessage != null)
|
||||
{
|
||||
return new HttpResponseMessageActionResult(responseMessage);
|
||||
}
|
||||
|
||||
if (actionReturnValue is string)
|
||||
{
|
||||
return new ContentResult
|
||||
{
|
||||
ContentType = "text/plain",
|
||||
Content = (string)actionReturnValue,
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: this needs to get injected
|
||||
IOwinContentNegotiator contentNegotiator = new DefaultContentNegotiator();
|
||||
|
||||
// TODO: inject the formatters
|
||||
IEnumerable<MediaTypeFormatter> formatters = requestContext.Formatters;
|
||||
|
||||
return new NegotiatedContentResult(HttpStatusCode.OK, declaredReturnType, actionReturnValue, contentNegotiator, requestContext.HttpContext, formatters);
|
||||
ContentType = "text/plain",
|
||||
Content = Convert.ToString(actionReturnValue),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,104 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Microsoft.Owin;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Properties;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
/// <summary>Represents an action result that performs content negotiation.</summary>
|
||||
/// <typeparam name="T">The type of content in the entity body.</typeparam>
|
||||
internal class NegotiatedContentResult : IActionResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NegotiatedContentResult{T}"/> class with the values provided.
|
||||
/// </summary>
|
||||
/// <param name="statusCode">The HTTP status code for the response message.</param>
|
||||
/// <param name="content">The content value to negotiate and format in the entity body.</param>
|
||||
/// <param name="contentNegotiator">The content negotiator to handle content negotiation.</param>
|
||||
/// <param name="request">The request message which led to this result.</param>
|
||||
/// <param name="formatters">The formatters to use to negotiate and format the content.</param>
|
||||
public NegotiatedContentResult(HttpStatusCode statusCode,
|
||||
Type declaredType,
|
||||
object content,
|
||||
IOwinContentNegotiator contentNegotiator,
|
||||
IOwinContext owinContext,
|
||||
IEnumerable<MediaTypeFormatter> formatters)
|
||||
{
|
||||
Contract.Assert(content != null);
|
||||
Contract.Assert(declaredType != null);
|
||||
Contract.Assert(owinContext != null);
|
||||
Contract.Assert(formatters != null);
|
||||
|
||||
StatusCode = statusCode;
|
||||
DeclaredType = declaredType;
|
||||
Content = content;
|
||||
CurrentOwinContext = owinContext;
|
||||
Formatters = formatters;
|
||||
ContentNegotiator = contentNegotiator;
|
||||
}
|
||||
|
||||
/// <summary>Gets the HTTP status code for the response message.</summary>
|
||||
public HttpStatusCode StatusCode { get; private set; }
|
||||
|
||||
public Type DeclaredType { get; private set; }
|
||||
|
||||
/// <summary>Gets the content value to negotiate and format in the entity body.</summary>
|
||||
public object Content { get; private set; }
|
||||
|
||||
/// <summary>Gets the content negotiator to handle content negotiation.</summary>
|
||||
public IOwinContentNegotiator ContentNegotiator { get; private set; }
|
||||
|
||||
/// <summary>Gets the request message which led to this result.</summary>
|
||||
public IOwinContext CurrentOwinContext { get; private set; }
|
||||
|
||||
/// <summary>Gets the formatters to use to negotiate and format the content.</summary>
|
||||
public IEnumerable<MediaTypeFormatter> Formatters { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual Task ExecuteResultAsync(RequestContext context)
|
||||
{
|
||||
// Run content negotiation.
|
||||
ContentNegotiationResult result = ContentNegotiator.Negotiate(DeclaredType, CurrentOwinContext, Formatters);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
// A null result from content negotiation indicates that the response should be a 406.
|
||||
CurrentOwinContext.Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
||||
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
IOwinResponse response = CurrentOwinContext.Response;
|
||||
response.StatusCode = (int)StatusCode;
|
||||
Contract.Assert(result.Formatter != null);
|
||||
|
||||
var objectContent = new ObjectContent(DeclaredType, Content, result.Formatter, result.MediaType);
|
||||
|
||||
// Copy non-content headers
|
||||
IDictionary<string, string[]> responseHeaders = response.Headers;
|
||||
foreach (KeyValuePair<string, string[]> header in response.Headers)
|
||||
{
|
||||
responseHeaders[header.Key] = header.Value.AsArray();
|
||||
}
|
||||
|
||||
// Copy content headers
|
||||
foreach (KeyValuePair<string, IEnumerable<string>> contentHeader in objectContent.Headers)
|
||||
{
|
||||
responseHeaders[contentHeader.Key] = contentHeader.Value.AsArray();
|
||||
}
|
||||
|
||||
return objectContent.CopyToAsync(response.Body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a value as well as an associated <see cref="MediaTypeFormatter"/> that will be
|
||||
/// used to serialize the value when writing this content.
|
||||
/// </summary>
|
||||
public class ObjectContent : HttpContent
|
||||
{
|
||||
private object _value;
|
||||
private readonly MediaTypeFormatter _formatter;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObjectContent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of object this instance will contain.</param>
|
||||
/// <param name="value">The value of the object this instance will contain.</param>
|
||||
/// <param name="formatter">The formatter to use when serializing the value.</param>
|
||||
public ObjectContent(Type type, object value, MediaTypeFormatter formatter)
|
||||
: this(type, value, formatter, (MediaTypeHeaderValue)null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObjectContent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of object this instance will contain.</param>
|
||||
/// <param name="value">The value of the object this instance will contain.</param>
|
||||
/// <param name="formatter">The formatter to use when serializing the value.</param>
|
||||
/// <param name="mediaType">The authoritative value of the content's Content-Type header. Can be <c>null</c> in which case the
|
||||
/// <paramref name="formatter">formatter's</paramref> default content type will be used.</param>
|
||||
public ObjectContent(Type type, object value, MediaTypeFormatter formatter, string mediaType)
|
||||
: this(type, value, formatter, BuildHeaderValue(mediaType))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObjectContent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of object this instance will contain.</param>
|
||||
/// <param name="value">The value of the object this instance will contain.</param>
|
||||
/// <param name="formatter">The formatter to use when serializing the value.</param>
|
||||
/// <param name="mediaType">The authoritative value of the content's Content-Type header. Can be <c>null</c> in which case the
|
||||
/// <paramref name="formatter">formatter's</paramref> default content type will be used.</param>
|
||||
public ObjectContent(Type type, object value, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("type");
|
||||
}
|
||||
if (formatter == null)
|
||||
{
|
||||
throw new ArgumentNullException("formatter");
|
||||
}
|
||||
|
||||
if (!formatter.CanWriteType(type))
|
||||
{
|
||||
throw new ArgumentNullException(formatter.GetType().FullName + " cannot write " + type.Name);
|
||||
}
|
||||
|
||||
_formatter = formatter;
|
||||
ObjectType = type;
|
||||
|
||||
VerifyAndSetObject(value);
|
||||
_formatter.SetDefaultContentHeaders(type, Headers, mediaType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of object managed by this <see cref="ObjectContent"/> instance.
|
||||
/// </summary>
|
||||
public Type ObjectType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="MediaTypeFormatter">formatter</see> associated with this content instance.
|
||||
/// </summary>
|
||||
public MediaTypeFormatter Formatter
|
||||
{
|
||||
get { return _formatter; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the current <see cref="ObjectContent"/>.
|
||||
/// </summary>
|
||||
public object Value
|
||||
{
|
||||
get { return _value; }
|
||||
set { _value = value; }
|
||||
}
|
||||
|
||||
internal static MediaTypeHeaderValue BuildHeaderValue(string mediaType)
|
||||
{
|
||||
return mediaType != null ? new MediaTypeHeaderValue(mediaType) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously serializes the object's content to the given <paramref name="stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="stream">The <see cref="Stream"/> to which to write.</param>
|
||||
/// <param name="context">The associated <see cref="TransportContext"/>.</param>
|
||||
/// <returns>A <see cref="Task"/> instance that is asynchronously serializing the object's content.</returns>
|
||||
protected override Task SerializeToStreamAsync(Stream stream, System.Net.TransportContext context)
|
||||
{
|
||||
return _formatter.WriteToStreamAsync(ObjectType, Value, stream, this, context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the length of the stream if possible.
|
||||
/// </summary>
|
||||
/// <param name="length">The computed length of the stream.</param>
|
||||
/// <returns><c>true</c> if the length has been computed; otherwise <c>false</c>.</returns>
|
||||
protected override bool TryComputeLength(out long length)
|
||||
{
|
||||
length = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool IsTypeNullable(Type type)
|
||||
{
|
||||
return !type.IsValueType() ||
|
||||
(type.IsGenericType() &&
|
||||
type.GetGenericTypeDefinition() == typeof(Nullable<>));
|
||||
}
|
||||
|
||||
private void VerifyAndSetObject(object value)
|
||||
{
|
||||
Contract.Assert(ObjectType != null, "Type cannot be null");
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
// Null may not be assigned to value types (unless Nullable<T>)
|
||||
if (!IsTypeNullable(ObjectType))
|
||||
{
|
||||
throw new InvalidOperationException("CannotUseNullValueType " + typeof(ObjectContent).Name + " " + ObjectType.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-null objects must be a type assignable to Type
|
||||
Type objectType = value.GetType();
|
||||
if (!ObjectType.IsAssignableFrom(objectType))
|
||||
{
|
||||
throw new ArgumentException("value Resources.ObjectAndTypeDisagree, objectType.Name, ObjectType.Name");
|
||||
}
|
||||
}
|
||||
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
using Microsoft.Owin;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
|
|
|
|||
|
|
@ -1,599 +0,0 @@
|
|||
//// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.Owin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that selects a <see cref="MediaTypeFormatter"/> for an <see cref="HttpRequestMessage"/>
|
||||
/// or <see cref="HttpResponseMessage"/>.
|
||||
/// </summary>
|
||||
public class DefaultContentNegotiator : IOwinContentNegotiator
|
||||
{
|
||||
// public DefaultContentNegotiator()
|
||||
// : this(false)
|
||||
// {
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Initializes a new instance of the <see cref="DefaultContentNegotiator"/> with
|
||||
// /// the given setting for <paramref name="excludeMatchOnTypeOnly"/>.
|
||||
// /// </summary>
|
||||
// /// <param name="excludeMatchOnTypeOnly">
|
||||
// /// If ExcludeMatchOnTypeOnly is true then we don't match on type only which means
|
||||
// /// that we return null if we can't match on anything in the request. This is useful
|
||||
// /// for generating 406 (Not Acceptable) status codes.
|
||||
// /// </param>
|
||||
// public DefaultContentNegotiator(bool excludeMatchOnTypeOnly)
|
||||
// {
|
||||
// ExcludeMatchOnTypeOnly = excludeMatchOnTypeOnly;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// If ExcludeMatchOnTypeOnly is true then we don't match on type only which means
|
||||
// /// that we return null if we can't match on anything in the request. This is useful
|
||||
// /// for generating 406 (Not Acceptable) status codes.
|
||||
// /// </summary>
|
||||
// public bool ExcludeMatchOnTypeOnly { get; private set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// Performs content negotiating by selecting the most appropriate <see cref="MediaTypeFormatter"/> out of the passed in
|
||||
// /// <paramref name="formatters"/> for the given <paramref name="request"/> that can serialize an object of the given
|
||||
// /// <paramref name="type"/>.
|
||||
// /// </summary>
|
||||
// /// <param name="type">The type to be serialized.</param>
|
||||
// /// <param name="request">The request.</param>
|
||||
// /// <param name="formatters">The set of <see cref="MediaTypeFormatter"/> objects from which to choose.</param>
|
||||
// /// <returns>The result of the negotiation containing the most appropriate <see cref="MediaTypeFormatter"/> instance,
|
||||
// /// or <c>null</c> if there is no appropriate formatter.</returns>
|
||||
// public virtual ContentNegotiationResult Negotiate(Type type, IOwinContext context, IEnumerable<MediaTypeFormatter> formatters)
|
||||
// {
|
||||
// // Performance-sensitive
|
||||
// if (type == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("type");
|
||||
// }
|
||||
// if (context == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("context");
|
||||
// }
|
||||
// if (formatters == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("formatters");
|
||||
// }
|
||||
|
||||
// var request = context.Request;
|
||||
|
||||
// // Go through each formatter to compute how well it matches.
|
||||
// Collection<MediaTypeFormatterMatch> matches = ComputeFormatterMatches(type, request, formatters);
|
||||
|
||||
// // Select best formatter match among the matches
|
||||
// MediaTypeFormatterMatch bestFormatterMatch = SelectResponseMediaTypeFormatter(matches);
|
||||
|
||||
// // We found a best formatter
|
||||
// if (bestFormatterMatch != null)
|
||||
// {
|
||||
// // Find the best character encoding for the selected formatter
|
||||
// Encoding bestEncodingMatch = SelectResponseCharacterEncoding(request, bestFormatterMatch.Formatter);
|
||||
// if (bestEncodingMatch != null)
|
||||
// {
|
||||
// bestFormatterMatch.MediaType.CharSet = bestEncodingMatch.WebName;
|
||||
// }
|
||||
|
||||
// MediaTypeHeaderValue bestMediaType = bestFormatterMatch.MediaType;
|
||||
// MediaTypeFormatter bestFormatter = bestFormatterMatch.Formatter; // this is OData only scenario at the moment: .GetPerRequestFormatterInstance(type, request, bestMediaType);
|
||||
// return new ContentNegotiationResult(bestFormatter, bestMediaType);
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Determine how well each formatter matches by associating a <see cref="MediaTypeFormatterMatchRanking"/> value
|
||||
// /// with the formatter. Then associate the quality of the match based on q-factors and other parameters. The result of this
|
||||
// /// method is a collection of the matches found categorized and assigned a quality value.
|
||||
// /// </summary>
|
||||
// /// <param name="type">The type to be serialized.</param>
|
||||
// /// <param name="request">The request.</param>
|
||||
// /// <param name="formatters">The set of <see cref="MediaTypeFormatter"/> objects from which to choose.</param>
|
||||
// /// <returns>A collection containing all the matches.</returns>
|
||||
// protected virtual Collection<MediaTypeFormatterMatch> ComputeFormatterMatches(Type type, IOwinRequest request, IEnumerable<MediaTypeFormatter> formatters)
|
||||
// {
|
||||
// // Performance-sensitive
|
||||
// if (type == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("type");
|
||||
// }
|
||||
// if (request == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("request");
|
||||
// }
|
||||
// if (formatters == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("formatters");
|
||||
// }
|
||||
|
||||
// IEnumerable<MediaTypeWithQualityHeaderValue> sortedAcceptValues = null;
|
||||
|
||||
// // Go through each formatter to find how well it matches.
|
||||
// List<MediaTypeFormatterMatch> matches = new List<MediaTypeFormatterMatch>();
|
||||
// MediaTypeFormatter[] writingFormatters = GetWritingFormatters(formatters);
|
||||
// for (int i = 0; i < writingFormatters.Length; i++)
|
||||
// {
|
||||
// MediaTypeFormatter formatter = writingFormatters[i];
|
||||
// MediaTypeFormatterMatch match = null;
|
||||
|
||||
// // Check first that formatter can write the actual type
|
||||
// if (!formatter.CanWriteType(type))
|
||||
// {
|
||||
// // Formatter can't even write the type so no match at all
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Match against media type mapping.
|
||||
// if ((match = MatchMediaTypeMapping(request, formatter)) != null)
|
||||
// {
|
||||
// matches.Add(match);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Match against the accept header values.
|
||||
// if (sortedAcceptValues == null)
|
||||
// {
|
||||
// // Sort the Accept header values in descending order based on q-factor
|
||||
// sortedAcceptValues = SortMediaTypeWithQualityHeaderValuesByQFactor(request.Headers.Accept);
|
||||
// }
|
||||
// if ((match = MatchAcceptHeader(sortedAcceptValues, formatter)) != null)
|
||||
// {
|
||||
// matches.Add(match);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Match against request's media type if any
|
||||
// if ((match = MatchRequestMediaType(request, formatter)) != null)
|
||||
// {
|
||||
// matches.Add(match);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// // Check whether we should match on type or stop the matching process.
|
||||
// // The latter is used to generate 406 (Not Acceptable) status codes.
|
||||
// bool shouldMatchOnType = ShouldMatchOnType(sortedAcceptValues);
|
||||
|
||||
// // Match against the type of object we are writing out
|
||||
// if (shouldMatchOnType && (match = MatchType(type, formatter)) != null)
|
||||
// {
|
||||
// matches.Add(match);
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return matches;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Select the best match among the candidate matches found.
|
||||
// /// </summary>
|
||||
// /// <param name="matches">The collection of matches.</param>
|
||||
// /// <returns>The <see cref="MediaTypeFormatterMatch"/> determined to be the best match.</returns>
|
||||
// protected virtual MediaTypeFormatterMatch SelectResponseMediaTypeFormatter(ICollection<MediaTypeFormatterMatch> matches)
|
||||
// {
|
||||
// // Performance-sensitive
|
||||
// if (matches == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("matches");
|
||||
// }
|
||||
|
||||
// List<MediaTypeFormatterMatch> matchList = matches.AsList();
|
||||
|
||||
// MediaTypeFormatterMatch bestMatchOnType = null;
|
||||
// MediaTypeFormatterMatch bestMatchOnAcceptHeaderLiteral = null;
|
||||
// MediaTypeFormatterMatch bestMatchOnAcceptHeaderSubtypeMediaRange = null;
|
||||
// MediaTypeFormatterMatch bestMatchOnAcceptHeaderAllMediaRange = null;
|
||||
// MediaTypeFormatterMatch bestMatchOnMediaTypeMapping = null;
|
||||
// MediaTypeFormatterMatch bestMatchOnRequestMediaType = null;
|
||||
|
||||
// // Go through each formatter to find the best match in each category.
|
||||
// for (int i = 0; i < matchList.Count; i++)
|
||||
// {
|
||||
// MediaTypeFormatterMatch match = matchList[i];
|
||||
// switch (match.Ranking)
|
||||
// {
|
||||
// case MediaTypeFormatterMatchRanking.MatchOnCanWriteType:
|
||||
// // First match by type trumps all other type matches
|
||||
// if (bestMatchOnType == null)
|
||||
// {
|
||||
// bestMatchOnType = match;
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case MediaTypeFormatterMatchRanking.MatchOnRequestWithMediaTypeMapping:
|
||||
// // Matches on accept headers using mappings must choose the highest quality match
|
||||
// bestMatchOnMediaTypeMapping = UpdateBestMatch(bestMatchOnMediaTypeMapping, match);
|
||||
// break;
|
||||
|
||||
// case MediaTypeFormatterMatchRanking.MatchOnRequestAcceptHeaderLiteral:
|
||||
// // Matches on accept headers must choose the highest quality match.
|
||||
// // A match of 0.0 means we won't use it at all.
|
||||
// bestMatchOnAcceptHeaderLiteral = UpdateBestMatch(bestMatchOnAcceptHeaderLiteral, match);
|
||||
// break;
|
||||
|
||||
// case MediaTypeFormatterMatchRanking.MatchOnRequestAcceptHeaderSubtypeMediaRange:
|
||||
// // Matches on accept headers must choose the highest quality match.
|
||||
// // A match of 0.0 means we won't use it at all.
|
||||
// bestMatchOnAcceptHeaderSubtypeMediaRange = UpdateBestMatch(bestMatchOnAcceptHeaderSubtypeMediaRange, match);
|
||||
// break;
|
||||
|
||||
// case MediaTypeFormatterMatchRanking.MatchOnRequestAcceptHeaderAllMediaRange:
|
||||
// // Matches on accept headers must choose the highest quality match.
|
||||
// // A match of 0.0 means we won't use it at all.
|
||||
// bestMatchOnAcceptHeaderAllMediaRange = UpdateBestMatch(bestMatchOnAcceptHeaderAllMediaRange, match);
|
||||
// break;
|
||||
|
||||
// case MediaTypeFormatterMatchRanking.MatchOnRequestMediaType:
|
||||
// // First match on request content type trumps other request content matches
|
||||
// if (bestMatchOnRequestMediaType == null)
|
||||
// {
|
||||
// bestMatchOnRequestMediaType = match;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // If we received matches based on both supported media types and from media type mappings,
|
||||
// // we want to give precedence to the media type mappings, but only if their quality is >= that of the supported media type.
|
||||
// // We do this because media type mappings are the user's extensibility point and must take precedence over normal
|
||||
// // supported media types in the case of a tie. The 99% case is where both have quality 1.0.
|
||||
// if (bestMatchOnMediaTypeMapping != null)
|
||||
// {
|
||||
// MediaTypeFormatterMatch mappingOverride = bestMatchOnMediaTypeMapping;
|
||||
// mappingOverride = UpdateBestMatch(mappingOverride, bestMatchOnAcceptHeaderLiteral);
|
||||
// mappingOverride = UpdateBestMatch(mappingOverride, bestMatchOnAcceptHeaderSubtypeMediaRange);
|
||||
// mappingOverride = UpdateBestMatch(mappingOverride, bestMatchOnAcceptHeaderAllMediaRange);
|
||||
// if (mappingOverride != bestMatchOnMediaTypeMapping)
|
||||
// {
|
||||
// bestMatchOnMediaTypeMapping = null;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // now select the formatter and media type
|
||||
// // A MediaTypeMapping is highest precedence -- it is an extensibility point
|
||||
// // allowing the user to override normal accept header matching
|
||||
// MediaTypeFormatterMatch bestMatch = null;
|
||||
// if (bestMatchOnMediaTypeMapping != null)
|
||||
// {
|
||||
// bestMatch = bestMatchOnMediaTypeMapping;
|
||||
// }
|
||||
// else if (bestMatchOnAcceptHeaderLiteral != null ||
|
||||
// bestMatchOnAcceptHeaderSubtypeMediaRange != null ||
|
||||
// bestMatchOnAcceptHeaderAllMediaRange != null)
|
||||
// {
|
||||
// bestMatch = UpdateBestMatch(bestMatch, bestMatchOnAcceptHeaderLiteral);
|
||||
// bestMatch = UpdateBestMatch(bestMatch, bestMatchOnAcceptHeaderSubtypeMediaRange);
|
||||
// bestMatch = UpdateBestMatch(bestMatch, bestMatchOnAcceptHeaderAllMediaRange);
|
||||
// }
|
||||
// else if (bestMatchOnRequestMediaType != null)
|
||||
// {
|
||||
// bestMatch = bestMatchOnRequestMediaType;
|
||||
// }
|
||||
// else if (bestMatchOnType != null)
|
||||
// {
|
||||
// bestMatch = bestMatchOnType;
|
||||
// }
|
||||
|
||||
// return bestMatch;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Determine the best character encoding for writing the response. First we look
|
||||
// /// for accept-charset headers and if not found then we try to match
|
||||
// /// any charset encoding in the request (in case of PUT, POST, etc.)
|
||||
// /// If no encoding is found then we use the default for the formatter.
|
||||
// /// </summary>
|
||||
// /// <returns>The <see cref="Encoding"/> determined to be the best match.</returns>
|
||||
// protected virtual Encoding SelectResponseCharacterEncoding(IOwinRequest request, MediaTypeFormatter formatter)
|
||||
// {
|
||||
// if (request == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("request");
|
||||
// }
|
||||
// if (formatter == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("formatter");
|
||||
// }
|
||||
|
||||
// // If there are any SupportedEncodings then we pick an encoding
|
||||
// List<Encoding> supportedEncodings = formatter.SupportedEncodingsInternal;
|
||||
// if (supportedEncodings.Count > 0)
|
||||
// {
|
||||
// // Sort Accept-Charset header values
|
||||
// IEnumerable<StringWithQualityHeaderValue> sortedAcceptCharsetValues = SortStringWithQualityHeaderValuesByQFactor(request.Headers.AcceptCharset);
|
||||
|
||||
// // Check for match based on accept-charset headers
|
||||
// foreach (StringWithQualityHeaderValue acceptCharset in sortedAcceptCharsetValues)
|
||||
// {
|
||||
// for (int i = 0; i < supportedEncodings.Count; i++)
|
||||
// {
|
||||
// Encoding encoding = supportedEncodings[i];
|
||||
// if (encoding != null && acceptCharset.Quality != FormattingUtilities.NoMatch &&
|
||||
// (acceptCharset.Value.Equals(encoding.WebName, StringComparison.OrdinalIgnoreCase) ||
|
||||
// acceptCharset.Value.Equals("*", StringComparison.OrdinalIgnoreCase)))
|
||||
// {
|
||||
// return encoding;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Check for match based on any request entity body
|
||||
|
||||
// // TODO: Transform to use request content headers directly
|
||||
// // was - request.Content != null ? request.Content.Headers : null
|
||||
// return formatter.SelectCharacterEncoding(null);
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Match a request against the <see cref="MediaTypeMapping"/>s registered with the formatter.
|
||||
// /// </summary>
|
||||
// /// <param name="request">The request to match.</param>
|
||||
// /// <param name="formatter">The formatter to match against.</param>
|
||||
// /// <returns>A <see cref="MediaTypeFormatterMatch"/> indicating the quality of the match or null is no match.</returns>
|
||||
// protected virtual MediaTypeFormatterMatch MatchMediaTypeMapping(IOwinRequest request, MediaTypeFormatter formatter)
|
||||
// {
|
||||
// if (request == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("request");
|
||||
// }
|
||||
// if (formatter == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("formatter");
|
||||
// }
|
||||
|
||||
// List<MediaTypeMapping> mediaTypeMappings = formatter.MediaTypeMappingsInternal;
|
||||
// for (int i = 0; i < mediaTypeMappings.Count; i++)
|
||||
// {
|
||||
// MediaTypeMapping mapping = mediaTypeMappings[i];
|
||||
// double quality;
|
||||
// if (mapping != null && ((quality = mapping.TryMatchMediaType(request)) > FormattingUtilities.NoMatch))
|
||||
// {
|
||||
// return new MediaTypeFormatterMatch(formatter, mapping.MediaType, quality, MediaTypeFormatterMatchRanking.MatchOnRequestWithMediaTypeMapping);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Match the request accept header field values against the formatter's registered supported media types.
|
||||
// /// </summary>
|
||||
// /// <param name="sortedAcceptValues">The sorted accept header values to match.</param>
|
||||
// /// <param name="formatter">The formatter to match against.</param>
|
||||
// /// <returns>A <see cref="MediaTypeFormatterMatch"/> indicating the quality of the match or null is no match.</returns>
|
||||
// protected virtual MediaTypeFormatterMatch MatchAcceptHeader(IEnumerable<MediaTypeWithQualityHeaderValue> sortedAcceptValues, MediaTypeFormatter formatter)
|
||||
// {
|
||||
// if (sortedAcceptValues == null)
|
||||
// {
|
||||
// throw Error.ArgumentNull("sortedAcceptValues");
|
||||
// }
|
||||
// if (formatter == null)
|
||||
// {
|
||||
// throw Error.ArgumentNull("formatter");
|
||||
// }
|
||||
|
||||
// foreach (MediaTypeWithQualityHeaderValue acceptMediaTypeValue in sortedAcceptValues)
|
||||
// {
|
||||
// List<MediaTypeHeaderValue> supportedMediaTypes = formatter.SupportedMediaTypesInternal;
|
||||
// for (int i = 0; i < supportedMediaTypes.Count; i++)
|
||||
// {
|
||||
// MediaTypeHeaderValue supportedMediaType = supportedMediaTypes[i];
|
||||
// MediaTypeHeaderValueRange range;
|
||||
// if (supportedMediaType != null && acceptMediaTypeValue.Quality != FormattingUtilities.NoMatch &&
|
||||
// supportedMediaType.IsSubsetOf(acceptMediaTypeValue, out range))
|
||||
// {
|
||||
// MediaTypeFormatterMatchRanking ranking;
|
||||
// switch (range)
|
||||
// {
|
||||
// case MediaTypeHeaderValueRange.AllMediaRange:
|
||||
// ranking = MediaTypeFormatterMatchRanking.MatchOnRequestAcceptHeaderAllMediaRange;
|
||||
// break;
|
||||
|
||||
// case MediaTypeHeaderValueRange.SubtypeMediaRange:
|
||||
// ranking = MediaTypeFormatterMatchRanking.MatchOnRequestAcceptHeaderSubtypeMediaRange;
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// ranking = MediaTypeFormatterMatchRanking.MatchOnRequestAcceptHeaderLiteral;
|
||||
// break;
|
||||
// }
|
||||
|
||||
// return new MediaTypeFormatterMatch(formatter, supportedMediaType, acceptMediaTypeValue.Quality, ranking);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Match any request media type (in case there is a request entity body) against the formatter's registered
|
||||
// /// media types.
|
||||
// /// </summary>
|
||||
// /// <param name="request">The request to match.</param>
|
||||
// /// <param name="formatter">The formatter to match against.</param>
|
||||
// /// <returns>A <see cref="MediaTypeFormatterMatch"/> indicating the quality of the match or null is no match.</returns>
|
||||
// protected virtual MediaTypeFormatterMatch MatchRequestMediaType(IOwinRequest request, MediaTypeFormatter formatter)
|
||||
// {
|
||||
// if (request == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("request");
|
||||
// }
|
||||
// if (formatter == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("formatter");
|
||||
// }
|
||||
|
||||
// if (request.Content != null)
|
||||
// {
|
||||
// MediaTypeHeaderValue requestMediaType = request.Content.Headers.ContentType;
|
||||
// if (requestMediaType != null)
|
||||
// {
|
||||
// List<MediaTypeHeaderValue> supportedMediaTypes = formatter.SupportedMediaTypesInternal;
|
||||
// for (int i = 0; i < supportedMediaTypes.Count; i++)
|
||||
// {
|
||||
// MediaTypeHeaderValue supportedMediaType = supportedMediaTypes[i];
|
||||
// if (supportedMediaType != null && supportedMediaType.IsSubsetOf(requestMediaType))
|
||||
// {
|
||||
// return new MediaTypeFormatterMatch(formatter, supportedMediaType, FormattingUtilities.Match, MediaTypeFormatterMatchRanking.MatchOnRequestMediaType);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Determine whether to match on type or not. This is used to determine whether to
|
||||
// /// generate a 406 response or use the default media type formatter in case there
|
||||
// /// is no match against anything in the request. If ExcludeMatchOnTypeOnly is true
|
||||
// /// then we don't match on type unless there are no accept headers.
|
||||
// /// </summary>
|
||||
// /// <param name="sortedAcceptValues">The sorted accept header values to match.</param>
|
||||
// /// <returns>True if not ExcludeMatchOnTypeOnly and accept headers with a q-factor bigger than 0.0 are present.</returns>
|
||||
// protected virtual bool ShouldMatchOnType(IEnumerable<MediaTypeWithQualityHeaderValue> sortedAcceptValues)
|
||||
// {
|
||||
// if (sortedAcceptValues == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("sortedAcceptValues");
|
||||
// }
|
||||
|
||||
// return !(ExcludeMatchOnTypeOnly && sortedAcceptValues.Any());
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Pick the first supported media type and indicate we've matched only on type
|
||||
// /// </summary>
|
||||
// /// <param name="type">The type to be serialized.</param>
|
||||
// /// <param name="formatter">The formatter we are matching against.</param>
|
||||
// /// <returns>A <see cref="MediaTypeFormatterMatch"/> indicating the quality of the match or null is no match.</returns>
|
||||
// protected virtual MediaTypeFormatterMatch MatchType(Type type, MediaTypeFormatter formatter)
|
||||
// {
|
||||
// // Performance-sensitive
|
||||
// if (type == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("type");
|
||||
// }
|
||||
// if (formatter == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("formatter");
|
||||
// }
|
||||
|
||||
// // We already know that we do match on type -- otherwise we wouldn't even be called --
|
||||
// // so this is just a matter of determining how we match.
|
||||
// MediaTypeHeaderValue mediaType = null;
|
||||
// List<MediaTypeHeaderValue> supportedMediaTypes = formatter.SupportedMediaTypesInternal;
|
||||
// if (supportedMediaTypes.Count > 0)
|
||||
// {
|
||||
// mediaType = supportedMediaTypes[0];
|
||||
// }
|
||||
// return new MediaTypeFormatterMatch(formatter, mediaType, FormattingUtilities.Match, MediaTypeFormatterMatchRanking.MatchOnCanWriteType);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Sort Accept header values and related header field values with similar syntax rules
|
||||
// /// (if more than 1) in descending order based on q-factor.
|
||||
// /// </summary>
|
||||
// /// <param name="headerValues">The header values to sort.</param>
|
||||
// /// <returns>The sorted header values.</returns>
|
||||
// protected virtual IEnumerable<MediaTypeWithQualityHeaderValue> SortMediaTypeWithQualityHeaderValuesByQFactor(ICollection<MediaTypeWithQualityHeaderValue> headerValues)
|
||||
// {
|
||||
// if (headerValues == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("headerValues");
|
||||
// }
|
||||
|
||||
// if (headerValues.Count > 1)
|
||||
// {
|
||||
// // Use OrderBy() instead of Array.Sort() as it performs fewer comparisons. In this case the comparisons
|
||||
// // are quite expensive so OrderBy() performs better.
|
||||
// return headerValues.OrderByDescending(m => m, MediaTypeWithQualityHeaderValueComparer.QualityComparer).ToArray();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return headerValues;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Sort Accept-Charset, Accept-Encoding, Accept-Language and related header field values with similar syntax rules
|
||||
// /// (if more than 1) in descending order based on q-factor.
|
||||
// /// </summary>
|
||||
// /// <param name="headerValues">The header values to sort.</param>
|
||||
// /// <returns>The sorted header values.</returns>
|
||||
// protected virtual IEnumerable<StringWithQualityHeaderValue> SortStringWithQualityHeaderValuesByQFactor(ICollection<StringWithQualityHeaderValue> headerValues)
|
||||
// {
|
||||
// if (headerValues == null)
|
||||
// {
|
||||
// throw new ArgumentNullException("headerValues");
|
||||
// }
|
||||
|
||||
// if (headerValues.Count > 1)
|
||||
// {
|
||||
// // Use OrderBy() instead of Array.Sort() as it performs fewer comparisons. In this case the comparisons
|
||||
// // are quite expensive so OrderBy() performs better.
|
||||
// return headerValues.OrderByDescending(m => m, StringWithQualityHeaderValueComparer.QualityComparer).ToArray();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return headerValues;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Evaluates whether a match is better than the current match and if so returns the replacement; otherwise returns the
|
||||
// /// current match.
|
||||
// /// </summary>
|
||||
// protected virtual MediaTypeFormatterMatch UpdateBestMatch(MediaTypeFormatterMatch current, MediaTypeFormatterMatch potentialReplacement)
|
||||
// {
|
||||
// if (potentialReplacement == null)
|
||||
// {
|
||||
// return current;
|
||||
// }
|
||||
|
||||
// if (current != null)
|
||||
// {
|
||||
// return (potentialReplacement.Quality > current.Quality) ? potentialReplacement : current;
|
||||
// }
|
||||
|
||||
// return potentialReplacement;
|
||||
// }
|
||||
|
||||
// private static MediaTypeFormatter[] GetWritingFormatters(IEnumerable<MediaTypeFormatter> formatters)
|
||||
// {
|
||||
// Contract.Assert(formatters != null);
|
||||
// MediaTypeFormatterCollection formatterCollection = formatters as MediaTypeFormatterCollection;
|
||||
// if (formatterCollection != null)
|
||||
// {
|
||||
// return formatterCollection.WritingFormatters;
|
||||
// }
|
||||
// return formatters.AsArray();
|
||||
// }
|
||||
|
||||
public ContentNegotiationResult Negotiate(Type type, IOwinContext context, IEnumerable<MediaTypeFormatter> formatters)
|
||||
{
|
||||
return new ContentNegotiationResult(formatters.First(), formatters.First().SupportedMediaTypes.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
using Microsoft.Owin;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
var type = a.GetType(controllerName) ??
|
||||
var type = a.GetType(controllerName) ??
|
||||
a.GetType(a.GetName().Name + "." + controllerName) ??
|
||||
a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
// Supports JQuery schema on FormURL.
|
||||
public class JQueryMvcFormUrlEncodedFormatter : FormUrlEncodedMediaTypeFormatter
|
||||
{
|
||||
public override bool CanReadType(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("type");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException("type");
|
||||
}
|
||||
|
||||
if (readStream == null)
|
||||
{
|
||||
throw new ArgumentNullException("readStream");
|
||||
}
|
||||
|
||||
// For simple types, defer to base class
|
||||
if (base.CanReadType(type))
|
||||
{
|
||||
return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);
|
||||
}
|
||||
|
||||
return ReadFromStreamAsyncCore(type, readStream, content, formatterLogger);
|
||||
}
|
||||
|
||||
private async Task<object> ReadFromStreamAsyncCore(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
|
||||
{
|
||||
object obj = await base.ReadFromStreamAsync(typeof(FormDataCollection), readStream, content, formatterLogger);
|
||||
FormDataCollection fd = (FormDataCollection)obj;
|
||||
|
||||
try
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//return fd.ReadAs(type, String.Empty, RequiredMemberSelector, formatterLogger);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (formatterLogger == null)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
formatterLogger.LogError(String.Empty, e);
|
||||
return GetDefaultValueForType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides various internal utility functions
|
||||
/// </summary>
|
||||
internal static class FormattingUtilities
|
||||
{
|
||||
// Supported date formats for input.
|
||||
private static readonly string[] dateFormats = new string[]
|
||||
{
|
||||
// "r", // RFC 1123, required output format but too strict for input
|
||||
"ddd, d MMM yyyy H:m:s 'GMT'", // RFC 1123 (r, except it allows both 1 and 01 for date and time)
|
||||
"ddd, d MMM yyyy H:m:s", // RFC 1123, no zone - assume GMT
|
||||
"d MMM yyyy H:m:s 'GMT'", // RFC 1123, no day-of-week
|
||||
"d MMM yyyy H:m:s", // RFC 1123, no day-of-week, no zone
|
||||
"ddd, d MMM yy H:m:s 'GMT'", // RFC 1123, short year
|
||||
"ddd, d MMM yy H:m:s", // RFC 1123, short year, no zone
|
||||
"d MMM yy H:m:s 'GMT'", // RFC 1123, no day-of-week, short year
|
||||
"d MMM yy H:m:s", // RFC 1123, no day-of-week, short year, no zone
|
||||
|
||||
"dddd, d'-'MMM'-'yy H:m:s 'GMT'", // RFC 850
|
||||
"dddd, d'-'MMM'-'yy H:m:s", // RFC 850 no zone
|
||||
"ddd MMM d H:m:s yyyy", // ANSI C's asctime() format
|
||||
|
||||
"ddd, d MMM yyyy H:m:s zzz", // RFC 5322
|
||||
"ddd, d MMM yyyy H:m:s", // RFC 5322 no zone
|
||||
"d MMM yyyy H:m:s zzz", // RFC 5322 no day-of-week
|
||||
"d MMM yyyy H:m:s", // RFC 5322 no day-of-week, no zone
|
||||
};
|
||||
|
||||
// Valid header token characters are within the range 0x20 < c < 0x7F excluding the following characters
|
||||
private const string NonTokenChars = "()<>@,;:\\\"/[]?={}";
|
||||
|
||||
/// <summary>
|
||||
/// Quality factor to indicate a perfect match.
|
||||
/// </summary>
|
||||
public const double Match = 1.0;
|
||||
|
||||
/// <summary>
|
||||
/// Quality factor to indicate no match.
|
||||
/// </summary>
|
||||
public const double NoMatch = 0.0;
|
||||
|
||||
/// <summary>
|
||||
/// The default max depth for our formatter is 256
|
||||
/// </summary>
|
||||
public const int DefaultMaxDepth = 256;
|
||||
|
||||
/// <summary>
|
||||
/// The default min depth for our formatter is 1
|
||||
/// </summary>
|
||||
public const int DefaultMinDepth = 1;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP X-Requested-With header field name
|
||||
/// </summary>
|
||||
public const string HttpRequestedWithHeader = @"x-requested-with";
|
||||
|
||||
/// <summary>
|
||||
/// HTTP X-Requested-With header field value
|
||||
/// </summary>
|
||||
public const string HttpRequestedWithHeaderValue = @"XMLHttpRequest";
|
||||
|
||||
/// <summary>
|
||||
/// HTTP Host header field name
|
||||
/// </summary>
|
||||
public const string HttpHostHeader = "Host";
|
||||
|
||||
/// <summary>
|
||||
/// HTTP Version token
|
||||
/// </summary>
|
||||
public const string HttpVersionToken = "HTTP";
|
||||
|
||||
///// <summary>
|
||||
///// A <see cref="Type"/> representing <see cref="HttpRequestMessage"/>.
|
||||
///// </summary>
|
||||
//public static readonly Type HttpRequestMessageType = typeof(HttpRequestMessage);
|
||||
|
||||
///// <summary>
|
||||
///// A <see cref="Type"/> representing <see cref="HttpResponseMessage"/>.
|
||||
///// </summary>
|
||||
//public static readonly Type HttpResponseMessageType = typeof(HttpResponseMessage);
|
||||
|
||||
///// <summary>
|
||||
///// A <see cref="Type"/> representing <see cref="HttpContent"/>.
|
||||
///// </summary>
|
||||
//public static readonly Type HttpContentType = typeof(HttpContent);
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Type"/> representing <see cref="DelegatingEnumerable{T}"/>.
|
||||
/// </summary>
|
||||
public static readonly Type DelegatingEnumerableGenericType = typeof(DelegatingEnumerable<>);
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Type"/> representing <see cref="IEnumerable{T}"/>.
|
||||
/// </summary>
|
||||
public static readonly Type EnumerableInterfaceGenericType = typeof(IEnumerable<>);
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Type"/> representing <see cref="IQueryable{T}"/>.
|
||||
/// </summary>
|
||||
public static readonly Type QueryableInterfaceGenericType = typeof(IQueryable<>);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether <paramref name="type"/> is a <see cref="JToken"/> type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type to test.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if <paramref name="type"/> is a <see cref="JToken"/> type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsJTokenType(Type type)
|
||||
{
|
||||
return typeof(JToken).IsAssignableFrom(type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty <see cref="HttpContentHeaders"/> instance. The only way is to get it from a dummy
|
||||
/// <see cref="HttpContent"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>The created instance.</returns>
|
||||
public static HttpContentHeaders CreateEmptyContentHeaders()
|
||||
{
|
||||
HttpContent tempContent = null;
|
||||
HttpContentHeaders contentHeaders = null;
|
||||
try
|
||||
{
|
||||
tempContent = new StringContent(String.Empty);
|
||||
contentHeaders = tempContent.Headers;
|
||||
contentHeaders.Clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// We can dispose the content without touching the headers
|
||||
if (tempContent != null)
|
||||
{
|
||||
tempContent.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
return contentHeaders;
|
||||
}
|
||||
|
||||
//#if NETFX_CORE // MaxDepth is a DOS mitigation. We don't support MaxDepth in portable libraries because it is strictly client side.
|
||||
|
||||
// /// <summary>
|
||||
// /// Create a default reader quotas with a default depth quota of 1K
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public static XmlDictionaryReaderQuotas CreateDefaultReaderQuotas()
|
||||
// {
|
||||
// return XmlDictionaryReaderQuotas.Max;
|
||||
//#else
|
||||
// return new XmlDictionaryReaderQuotas()
|
||||
// {
|
||||
// MaxArrayLength = Int32.MaxValue,
|
||||
// MaxBytesPerRead = Int32.MaxValue,
|
||||
// MaxDepth = DefaultMaxDepth,
|
||||
// MaxNameTableCharCount = Int32.MaxValue,
|
||||
// MaxStringContentLength = Int32.MaxValue
|
||||
// };
|
||||
//#endif
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Remove bounding quotes on a token if present
|
||||
/// </summary>
|
||||
/// <param name="token">Token to unquote.</param>
|
||||
/// <returns>Unquoted token.</returns>
|
||||
public static string UnquoteToken(string token)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
if (token.StartsWith("\"", StringComparison.Ordinal) && token.EndsWith("\"", StringComparison.Ordinal) && token.Length > 1)
|
||||
{
|
||||
return token.Substring(1, token.Length - 2);
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
public static bool ValidateHeaderToken(string token)
|
||||
{
|
||||
if (token == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (char c in token)
|
||||
{
|
||||
if (c < 0x21 || c > 0x7E || NonTokenChars.IndexOf(c) != -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string DateToString(DateTimeOffset dateTime)
|
||||
{
|
||||
// Format according to RFC1123; 'r' uses invariant info (DateTimeFormatInfo.InvariantInfo)
|
||||
return dateTime.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static bool TryParseDate(string input, out DateTimeOffset result)
|
||||
{
|
||||
return DateTimeOffset.TryParseExact(input, dateFormats, DateTimeFormatInfo.InvariantInfo,
|
||||
DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AssumeUniversal,
|
||||
out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses valid integer strings with no leading signs, whitespace or other <see cref="NumberStyles"/>
|
||||
/// </summary>
|
||||
/// <param name="value">The value to parse</param>
|
||||
/// <param name="result">The result</param>
|
||||
/// <returns>True if value was valid; false otherwise.</returns>
|
||||
public static bool TryParseInt32(string value, out int result)
|
||||
{
|
||||
return Int32.TryParse(value, NumberStyles.None, NumberFormatInfo.InvariantInfo, out result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class HttpResponseMessageActionResult : IActionResult
|
||||
{
|
||||
public HttpResponseMessage ResponseMessage { get; set; }
|
||||
|
||||
public HttpResponseMessageActionResult(HttpResponseMessage responseMessage)
|
||||
{
|
||||
ResponseMessage = responseMessage;
|
||||
}
|
||||
|
||||
public async Task ExecuteResultAsync(RequestContext context)
|
||||
{
|
||||
var response = context.HttpContext.Response;
|
||||
response.StatusCode = (int)ResponseMessage.StatusCode;
|
||||
|
||||
foreach (var responseHeader in ResponseMessage.Headers)
|
||||
{
|
||||
response.Headers.AppendValues(responseHeader.Key, responseHeader.Value.ToArray());
|
||||
}
|
||||
|
||||
var content = ResponseMessage.Content;
|
||||
if (content != null)
|
||||
{
|
||||
foreach (var responseHeader in content.Headers)
|
||||
{
|
||||
response.Headers.AppendValues(responseHeader.Key, responseHeader.Value.ToArray());
|
||||
}
|
||||
|
||||
await content.CopyToAsync(response.Body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
using Microsoft.Owin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Formatting;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public interface IOwinContentNegotiator
|
||||
{
|
||||
ContentNegotiationResult Negotiate(Type type, IOwinContext context, IEnumerable<MediaTypeFormatter> formatters);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,13 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Owin">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\net45\Microsoft.AspNet.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.1.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
|
|
@ -41,11 +46,6 @@
|
|||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.0.0\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ActionDescriptor.cs" />
|
||||
|
|
@ -54,22 +54,15 @@
|
|||
<Compile Include="ActionResultFactory.cs" />
|
||||
<Compile Include="ActionResultHelper.cs" />
|
||||
<Compile Include="ActionResults\NoContentResult.cs" />
|
||||
<Compile Include="ActionResults\NegotiatedContentResult.cs" />
|
||||
<Compile Include="ActionResults\ContentResult.cs" />
|
||||
<Compile Include="ActionResults\ObjectContent.cs" />
|
||||
<Compile Include="ControllerBasedActionDescriptor.cs" />
|
||||
<Compile Include="DefaultContentNegotiator.cs" />
|
||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||
<Compile Include="Formatters\JQeryMvcForUrlEncodedFormatter.cs" />
|
||||
<Compile Include="View\CompositeViewEngine.cs" />
|
||||
<Compile Include="View\IView.cs" />
|
||||
<Compile Include="View\IViewEngine.cs" />
|
||||
<Compile Include="FormattingUtilities.cs" />
|
||||
<Compile Include="Extensions\TypeExtensions.cs" />
|
||||
<Compile Include="IOwinContentNegotiator.cs" />
|
||||
<Compile Include="RequestContext.cs" />
|
||||
<Compile Include="EmptyResult.cs" />
|
||||
<Compile Include="HttpResponseMessageActionResult.cs" />
|
||||
<Compile Include="IActionDescriptorProvider.cs" />
|
||||
<Compile Include="IActionInvokerProvider.cs" />
|
||||
<Compile Include="IActionResult.cs" />
|
||||
|
|
@ -97,12 +90,6 @@
|
|||
<None Include="packages.config" />
|
||||
<Content Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.AspNet.CoreServices\Microsoft.AspNet.CoreServices.csproj">
|
||||
<Project>{ec38534c-a2d1-413f-97d1-55eef5d2fb71}</Project>
|
||||
<Name>Microsoft.AspNet.CoreServices</Name>
|
||||
</ProjectReference>
|
||||
</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.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.Owin;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -10,21 +10,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public MvcHandler()
|
||||
: this(null)
|
||||
{
|
||||
}
|
||||
|
||||
public MvcHandler(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider ?? MvcServices.Create();
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
//public ServiceProvider ServiceProvider
|
||||
//{
|
||||
// get { return (ServiceProvider)_serviceProvider; }
|
||||
//}
|
||||
|
||||
public Task ExecuteAsync(IOwinContext context, IRouteData routeData)
|
||||
{
|
||||
var requestContext = new RequestContext(context, routeData);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
using System.Net.Http.Formatting;
|
||||
using Microsoft.AspNet.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -19,7 +18,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
callback(typeof(IActionInvokerFactory), typeof(ActionInvokerFactory));
|
||||
callback(typeof(IActionResultHelper), typeof(ActionResultHelper));
|
||||
callback(typeof(IActionResultFactory), typeof(ActionResultFactory));
|
||||
callback(typeof(IContentNegotiator), typeof(DefaultContentNegotiator));
|
||||
|
||||
|
||||
// TODO: Should be many
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Mvc.Routing;
|
||||
using Microsoft.Owin;
|
||||
using System.Net.Http.Formatting;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
@ -21,23 +20,10 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
HttpContext = context;
|
||||
RouteData = routeData;
|
||||
|
||||
// todo: inject
|
||||
InjectFormatters();
|
||||
}
|
||||
|
||||
private void InjectFormatters()
|
||||
{
|
||||
Formatters = new MediaTypeFormatterCollection();
|
||||
Formatters.Add(new JsonMediaTypeFormatter());
|
||||
//Formatters.Add(new XmlMediaTypeFormatter());
|
||||
//Formatters.Add(new JQueryMvcFormUrlEncodedFormatter());
|
||||
}
|
||||
|
||||
public virtual IRouteData RouteData { get; set; }
|
||||
|
||||
public virtual IOwinContext HttpContext { get; set; }
|
||||
|
||||
public virtual MediaTypeFormatterCollection Formatters { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.CoreServices;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.DependencyInjection" version="0.1-alpha-t140123020341" targetFramework="net45" />
|
||||
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
|
||||
<package id="Owin" version="1.0" targetFramework="net45" />
|
||||
</packages>
|
||||
|
|
@ -2,16 +2,11 @@
|
|||
"dependencies": {
|
||||
"Owin": "1.0",
|
||||
"Newtonsoft.Json": "4.5.11",
|
||||
"Microsoft.Owin": "2.0.2",
|
||||
"Microsoft.AspNet.WebApi.Client": "5.0.0",
|
||||
"Microsoft.AspNet.CoreServices" : ""
|
||||
"Microsoft.Owin": "2.1.0",
|
||||
"Microsoft.AspNet.DependencyInjection" : "0.1-alpha-*"
|
||||
},
|
||||
"configurations": {
|
||||
"net45": {
|
||||
"dependencies": {
|
||||
"System.Net.Http" : ""
|
||||
}
|
||||
},
|
||||
"k10" : { }
|
||||
"net45": { },
|
||||
"k10" : { }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue