Skip to content

Commit aa80422

Browse files
committed
In tests and samples added support of ASP.NET Core 3.1
1 parent 506e937 commit aa80422

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2462
-18
lines changed

JavaScriptEngineSwitcher.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JavaScriptEngineSwitcher.Sa
9797
EndProject
9898
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JavaScriptEngineSwitcher.Sample.AspNetCore21.Mvc21", "samples\JavaScriptEngineSwitcher.Sample.AspNetCore21.Mvc21\JavaScriptEngineSwitcher.Sample.AspNetCore21.Mvc21.csproj", "{0342791E-6390-4F97-9163-5CE02E4CFF07}"
9999
EndProject
100+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31", "samples\JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31\JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.csproj", "{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}"
101+
EndProject
100102
Global
101103
GlobalSection(SolutionConfigurationPlatforms) = preSolution
102104
Debug|Any CPU = Debug|Any CPU
@@ -199,6 +201,10 @@ Global
199201
{0342791E-6390-4F97-9163-5CE02E4CFF07}.Debug|Any CPU.Build.0 = Debug|Any CPU
200202
{0342791E-6390-4F97-9163-5CE02E4CFF07}.Release|Any CPU.ActiveCfg = Release|Any CPU
201203
{0342791E-6390-4F97-9163-5CE02E4CFF07}.Release|Any CPU.Build.0 = Release|Any CPU
204+
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
205+
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
206+
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
207+
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Release|Any CPU.Build.0 = Release|Any CPU
202208
EndGlobalSection
203209
GlobalSection(SolutionProperties) = preSolution
204210
HideSolutionNode = FALSE
@@ -230,6 +236,7 @@ Global
230236
{C790AD7F-55C6-4106-8D8C-8F901B7FF245} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
231237
{5CA92021-B75A-40AF-B5AA-500BAF76B4D6} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
232238
{0342791E-6390-4F97-9163-5CE02E4CFF07} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
239+
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
233240
EndGlobalSection
234241
GlobalSection(ExtensibilityGlobals) = postSolution
235242
SolutionGuid = {8184BE59-ACBC-4CD1-9419-D59A0FAC6131}

build/common.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<DefineConstants>$(DefineConstants);NETFULL</DefineConstants>
1010
</PropertyGroup>
1111

12-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' Or '$(TargetFramework)' == 'netstandard1.6' Or '$(TargetFramework)' == 'netstandard2.0' ">
12+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' Or '$(TargetFramework)' == 'netstandard1.6' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1' ">
1313
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
1414
</PropertyGroup>
1515

16-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' Or '$(TargetFramework)' == 'netcoreapp2.0' Or '$(TargetFramework)' == 'netcoreapp2.1' ">
16+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' Or '$(TargetFramework)' == 'netcoreapp2.0' Or '$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netcoreapp3.1' ">
1717
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
1818
</PropertyGroup>
1919
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "2.2.402"
3+
"version": "3.1.100"
44
}
55
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"registry": "https://registry.bower.io",
3+
"directory": "wwwroot/lib"
4+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Diagnostics;
2+
using System.Threading.Tasks;
3+
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Html;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Configuration;
8+
9+
using JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.Models;
10+
using JavaScriptEngineSwitcher.Sample.Logic.Models;
11+
using JavaScriptEngineSwitcher.Sample.Logic.Services;
12+
13+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.Controllers
14+
{
15+
public class HomeController : Controller
16+
{
17+
private readonly FileContentService _fileContentService;
18+
private readonly JsEvaluationService _jsEvaluationService;
19+
20+
21+
public HomeController(
22+
IConfigurationRoot configuration,
23+
IWebHostEnvironment hostingEnvironment,
24+
JsEvaluationService jsEvaluationService)
25+
{
26+
string textContentDirectoryPath = configuration
27+
.GetSection("jsengineswitcher")
28+
.GetSection("Samples")["TextContentDirectoryPath"]
29+
;
30+
31+
_fileContentService = new FileContentService(textContentDirectoryPath, hostingEnvironment);
32+
_jsEvaluationService = jsEvaluationService;
33+
}
34+
35+
36+
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
37+
public IActionResult Index()
38+
{
39+
ViewBag.Body = new HtmlString(_fileContentService.GetFileContent("index.html"));
40+
41+
return View();
42+
}
43+
44+
[HttpGet]
45+
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
46+
public IActionResult Demo()
47+
{
48+
var model = _jsEvaluationService.GetInitializationData();
49+
50+
return View(model);
51+
}
52+
53+
[HttpPost]
54+
public async Task<IActionResult> Demo(JsEvaluationViewModel editedModel)
55+
{
56+
var model = _jsEvaluationService.GetInitializationData();
57+
await TryUpdateModelAsync(model, string.Empty, m => m.EngineName, m=> m.Expression);
58+
59+
if (ModelState.IsValid)
60+
{
61+
model = _jsEvaluationService.Evaluate(model);
62+
63+
ModelState.Clear();
64+
}
65+
66+
return View(model);
67+
}
68+
69+
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
70+
public IActionResult Contact()
71+
{
72+
ViewBag.Body = new HtmlString(_fileContentService.GetFileContent("contact.html"));
73+
74+
return View();
75+
}
76+
77+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
78+
public IActionResult Error()
79+
{
80+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
81+
}
82+
}
83+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Text.RegularExpressions;
2+
3+
using Microsoft.AspNetCore.Html;
4+
using Microsoft.AspNetCore.Mvc.Rendering;
5+
6+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.Infrastructure.Helpers
7+
{
8+
public static class CommonExtensions
9+
{
10+
public static HtmlString EncodedReplace(this IHtmlHelper htmlHelper, string input,
11+
string pattern, string replacement)
12+
{
13+
return new HtmlString(Regex.Replace(htmlHelper.Encode(input), pattern, replacement));
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
3+
using Microsoft.AspNetCore.Razor.TagHelpers;
4+
5+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.Infrastructure.TagHelpers
6+
{
7+
[HtmlTargetElement("conditional-comment")]
8+
public class ConditionalCommentTagHelper : TagHelper
9+
{
10+
[HtmlAttributeName("type")]
11+
public ConditionalCommentType CommentType { get; set; }
12+
13+
[HtmlAttributeName("expression")]
14+
public string Expression { get; set; }
15+
16+
17+
public override void Process(TagHelperContext context, TagHelperOutput output)
18+
{
19+
output.TagName = null;
20+
21+
ConditionalCommentType type = CommentType;
22+
23+
string ifCommentStartPart;
24+
string ifCommentEndPart;
25+
26+
switch (type)
27+
{
28+
case ConditionalCommentType.Hidden:
29+
ifCommentStartPart = "<!--[if ";
30+
ifCommentEndPart = "]>";
31+
32+
break;
33+
case ConditionalCommentType.RevealedValidating:
34+
ifCommentStartPart = "<!--[if ";
35+
ifCommentEndPart = "]><!-->";
36+
37+
break;
38+
case ConditionalCommentType.RevealedValidatingSimplified:
39+
ifCommentStartPart = "<!--[if ";
40+
ifCommentEndPart = "]>-->";
41+
42+
break;
43+
case ConditionalCommentType.Revealed:
44+
ifCommentStartPart = "<![if ";
45+
ifCommentEndPart = "]>";
46+
47+
break;
48+
default:
49+
throw new NotSupportedException();
50+
}
51+
52+
TagHelperContent preContent = output.PreContent;
53+
preContent.AppendHtml(ifCommentStartPart);
54+
preContent.AppendHtml(Expression);
55+
preContent.AppendHtml(ifCommentEndPart);
56+
57+
string endIfComment;
58+
59+
switch (type)
60+
{
61+
case ConditionalCommentType.Hidden:
62+
endIfComment = "<![endif]-->";
63+
break;
64+
case ConditionalCommentType.RevealedValidating:
65+
case ConditionalCommentType.RevealedValidatingSimplified:
66+
endIfComment = "<!--<![endif]-->";
67+
break;
68+
case ConditionalCommentType.Revealed:
69+
endIfComment = "<![endif]>";
70+
break;
71+
default:
72+
throw new NotSupportedException();
73+
}
74+
75+
output.PostContent.AppendHtml(endIfComment);
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.Infrastructure.TagHelpers
2+
{
3+
public enum ConditionalCommentType
4+
{
5+
Hidden,
6+
Revealed,
7+
RevealedValidating,
8+
RevealedValidatingSimplified
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<Product>JS Engine Switcher: Sample ASP.NET Core 3.1 MVC 3.1 Site</Product>
5+
<VersionPrefix>3.2.4</VersionPrefix>
6+
<TargetFramework>netcoreapp3.1</TargetFramework>
7+
<OutputType>Exe</OutputType>
8+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
9+
<PreserveCompilationContext>true</PreserveCompilationContext>
10+
<IsPackable>false</IsPackable>
11+
</PropertyGroup>
12+
13+
<Import Project="../../build/common.props" />
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.0" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.0" />
18+
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
19+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
20+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
21+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" PrivateAssets="All" />
22+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" Version="3.2.3" />
23+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="3.2.3" />
24+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-arm" Version="3.2.3" />
25+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.2.3" />
26+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" Version="3.2.3" />
27+
28+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.csproj" />
29+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Extensions.MsDependencyInjection/JavaScriptEngineSwitcher.Extensions.MsDependencyInjection.csproj" />
30+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Jint/JavaScriptEngineSwitcher.Jint.csproj" />
31+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Jurassic/JavaScriptEngineSwitcher.Jurassic.csproj" />
32+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Msie/JavaScriptEngineSwitcher.Msie.csproj" />
33+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.NiL/JavaScriptEngineSwitcher.NiL.csproj" />
34+
<ProjectReference Include="../JavaScriptEngineSwitcher.Sample.Logic/JavaScriptEngineSwitcher.Sample.Logic.csproj" />
35+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Vroom/JavaScriptEngineSwitcher.Vroom.csproj" />
36+
</ItemGroup>
37+
38+
<ItemGroup>
39+
<None Update="wwwroot/**/*;Views/**/*">
40+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
41+
</None>
42+
</ItemGroup>
43+
44+
<Target Name="GulpBuild" AfterTargets="AfterBuild">
45+
<Exec Command="gulp" />
46+
</Target>
47+
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
48+
<Exec Command="npm install" />
49+
<Exec Command="gulp" />
50+
</Target>
51+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}

0 commit comments

Comments
 (0)