Use Json.Net for MVC ValueProviderFactory
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
<TargetFrameworkProfile />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<TargetFrameworkProfile />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
-1
@@ -12,7 +12,6 @@
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<AssemblyVersion>2.0.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<TargetFrameworkProfile />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<TargetFrameworkProfile />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -104,6 +103,7 @@
|
||||
<Compile Include="DataModelExtension\DocumentTemplateExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\JobSubTypeExtensions.cs" />
|
||||
<Compile Include="DataModelExtension\JobTypeExtensions.cs" />
|
||||
<Compile Include="MvcExtensions\JsonNet\JsonDotNetValueProviderFactory.cs" />
|
||||
<Compile Include="MvcExtensions\JsonNet\JsonNetResult.cs" />
|
||||
<Compile Include="MvcExtensions\PartialCompiled\PartialCompiledHtmlExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Extensions
|
||||
{
|
||||
public class JsonDotNetValueProviderFactory : ValueProviderFactory
|
||||
{
|
||||
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
|
||||
{
|
||||
if (controllerContext == null)
|
||||
throw new ArgumentNullException(nameof(controllerContext));
|
||||
|
||||
if (!controllerContext.HttpContext.Request.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
if (controllerContext.HttpContext.Request.InputStream.Length == 0)
|
||||
return null;
|
||||
|
||||
var jsonSerializer = new JsonSerializer();
|
||||
jsonSerializer.Converters.Add(new ExpandoObjectConverter());
|
||||
|
||||
using (var streamReader = new StreamReader(controllerContext.HttpContext.Request.InputStream, Encoding.UTF8, true, 0x400, true))
|
||||
{
|
||||
using (var jsonReader = new JsonTextReader(streamReader))
|
||||
{
|
||||
var bodyObject = jsonSerializer.Deserialize<ExpandoObject>(jsonReader);
|
||||
return new DictionaryValueProvider<object>(bodyObject, CultureInfo.CurrentCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Web;
|
||||
using Disco.Web.Extensions;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web
|
||||
@@ -7,7 +8,15 @@ namespace Disco.Web
|
||||
{
|
||||
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
|
||||
{
|
||||
//filters.Add(new HandleErrorAttribute());
|
||||
// Remove Default Json Value Provider Factory (JavaScriptSerializer)
|
||||
var defaultJsonValueProvider = ValueProviderFactories.Factories.OfType<JsonValueProviderFactory>().FirstOrDefault();
|
||||
if (defaultJsonValueProvider != null)
|
||||
{
|
||||
ValueProviderFactories.Factories.Remove(defaultJsonValueProvider);
|
||||
}
|
||||
|
||||
// Add Custom Json Value Provider Factory (Json.Net)
|
||||
ValueProviderFactories.Factories.Add(new JsonDotNetValueProviderFactory());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
<AssemblyVersion>2.2.16272.1003</AssemblyVersion>
|
||||
<UseGlobalApplicationHostFile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
|
||||
@@ -24,19 +24,9 @@ namespace Disco.Web
|
||||
|
||||
protected void Application_Start()
|
||||
{
|
||||
var timer = new Stopwatch();
|
||||
long timer_last;
|
||||
timer.Start();
|
||||
|
||||
|
||||
Debug.WriteLine("Application Startup Profiling Started");
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
if (AppConfig.InitializeDatabase())
|
||||
{
|
||||
// Database Initialized
|
||||
Debug.WriteLine("Initialized Database: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
using (DiscoDataContext database = new DiscoDataContext())
|
||||
{
|
||||
@@ -64,33 +54,15 @@ namespace Disco.Web
|
||||
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
|
||||
Debug.WriteLine("Registered Areas: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
WebApiConfig.Register(GlobalConfiguration.Configuration);
|
||||
|
||||
Debug.WriteLine("Registered API: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
|
||||
Debug.WriteLine("Registered Global Filters: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
|
||||
Debug.WriteLine("Registered Routes: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
BundleConfig.RegisterBundles();
|
||||
|
||||
Debug.WriteLine("Registered Bundles: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
|
||||
AppConfig.InitalizeNormalEnvironment(database);
|
||||
|
||||
Debug.WriteLine("Initialized Environment: +{0}ms", timer.ElapsedMilliseconds - timer_last);
|
||||
timer_last = timer.ElapsedMilliseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -107,6 +79,7 @@ namespace Disco.Web
|
||||
// Database Not Initialized
|
||||
// Install
|
||||
InitialConfig = true;
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
RouteConfig.RegisterInstallRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles();
|
||||
}
|
||||
|
||||
@@ -129,10 +129,4 @@ Global
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(AutomaticVersions) = postSolution
|
||||
PrimaryVersionType = AssemblyVersionAttribute
|
||||
UpdateAssemblyVersion = False
|
||||
UpdateAssemblyFileVersion = False
|
||||
UpdateAssemblyInfoVersion = False
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user