Skip to content

Commit 78bda56

Browse files
committed
Added a sample project for ASP.NET Core 5.0
1 parent 6d1ee94 commit 78bda56

Some content is hidden

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

48 files changed

+2473
-16
lines changed

JavaScriptEngineSwitcher.sln

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JavaScriptEngineSwitcher.Sa
107107
EndProject
108108
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}"
109109
EndProject
110+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptEngineSwitcher.Sample.AspNetCore5.Mvc5", "samples\JavaScriptEngineSwitcher.Sample.AspNetCore5.Mvc5\JavaScriptEngineSwitcher.Sample.AspNetCore5.Mvc5.csproj", "{189376C9-49DA-4A12-9C78-CE39E8EC7731}"
111+
EndProject
110112
Global
111113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
112114
Debug|Any CPU = Debug|Any CPU
@@ -137,6 +139,14 @@ Global
137139
{4FB64080-817F-468A-B92C-F63B46E6D85F}.Debug|Any CPU.Build.0 = Debug|Any CPU
138140
{4FB64080-817F-468A-B92C-F63B46E6D85F}.Release|Any CPU.ActiveCfg = Release|Any CPU
139141
{4FB64080-817F-468A-B92C-F63B46E6D85F}.Release|Any CPU.Build.0 = Release|Any CPU
142+
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
143+
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Debug|Any CPU.Build.0 = Debug|Any CPU
144+
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Release|Any CPU.ActiveCfg = Release|Any CPU
145+
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Release|Any CPU.Build.0 = Release|Any CPU
146+
{4B727E90-AE52-41DD-B704-28A00196052C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
147+
{4B727E90-AE52-41DD-B704-28A00196052C}.Debug|Any CPU.Build.0 = Debug|Any CPU
148+
{4B727E90-AE52-41DD-B704-28A00196052C}.Release|Any CPU.ActiveCfg = Release|Any CPU
149+
{4B727E90-AE52-41DD-B704-28A00196052C}.Release|Any CPU.Build.0 = Release|Any CPU
140150
{D31B5A77-8018-4D76-B372-325564385B2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
141151
{D31B5A77-8018-4D76-B372-325564385B2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
142152
{D31B5A77-8018-4D76-B372-325564385B2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -221,14 +231,10 @@ Global
221231
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
222232
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
223233
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4}.Release|Any CPU.Build.0 = Release|Any CPU
224-
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
225-
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Debug|Any CPU.Build.0 = Debug|Any CPU
226-
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Release|Any CPU.ActiveCfg = Release|Any CPU
227-
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889}.Release|Any CPU.Build.0 = Release|Any CPU
228-
{4B727E90-AE52-41DD-B704-28A00196052C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
229-
{4B727E90-AE52-41DD-B704-28A00196052C}.Debug|Any CPU.Build.0 = Debug|Any CPU
230-
{4B727E90-AE52-41DD-B704-28A00196052C}.Release|Any CPU.ActiveCfg = Release|Any CPU
231-
{4B727E90-AE52-41DD-B704-28A00196052C}.Release|Any CPU.Build.0 = Release|Any CPU
234+
{189376C9-49DA-4A12-9C78-CE39E8EC7731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
235+
{189376C9-49DA-4A12-9C78-CE39E8EC7731}.Debug|Any CPU.Build.0 = Debug|Any CPU
236+
{189376C9-49DA-4A12-9C78-CE39E8EC7731}.Release|Any CPU.ActiveCfg = Release|Any CPU
237+
{189376C9-49DA-4A12-9C78-CE39E8EC7731}.Release|Any CPU.Build.0 = Release|Any CPU
232238
EndGlobalSection
233239
GlobalSection(SolutionProperties) = preSolution
234240
HideSolutionNode = FALSE
@@ -242,6 +248,8 @@ Global
242248
{C24E1F3C-5680-463A-8703-B9F40BCDAC77} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
243249
{1739A011-164B-4227-B540-01BAD61F17C5} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
244250
{4FB64080-817F-468A-B92C-F63B46E6D85F} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
251+
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
252+
{4B727E90-AE52-41DD-B704-28A00196052C} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
245253
{D31B5A77-8018-4D76-B372-325564385B2D} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
246254
{22D73C6E-5F35-497B-A93B-F9EAAAE4DDAA} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
247255
{2EFFFC6B-E642-477F-B537-4241EBD93410} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
@@ -263,8 +271,7 @@ Global
263271
{5CA92021-B75A-40AF-B5AA-500BAF76B4D6} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
264272
{0342791E-6390-4F97-9163-5CE02E4CFF07} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
265273
{D0127B5A-E66B-4DA2-8C57-A8BA2A0163F4} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
266-
{D4B2AB12-57DE-43AA-9A1E-E4A5DEB59889} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
267-
{4B727E90-AE52-41DD-B704-28A00196052C} = {0C281F46-F1D2-4A1C-8560-375EDA65D680}
274+
{189376C9-49DA-4A12-9C78-CE39E8EC7731} = {E5989CB5-AACE-4D35-A8EE-26942F140DA3}
268275
EndGlobalSection
269276
GlobalSection(ExtensibilityGlobals) = postSolution
270277
SolutionGuid = {8184BE59-ACBC-4CD1-9419-D59A0FAC6131}
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.AspNetCore5.Mvc5.Models;
10+
using JavaScriptEngineSwitcher.Sample.Logic.Models;
11+
using JavaScriptEngineSwitcher.Sample.Logic.Services;
12+
13+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore5.Mvc5.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.AspNetCore5.Mvc5.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.AspNetCore5.Mvc5.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.AspNetCore5.Mvc5.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,68 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<Product>JS Engine Switcher: Sample ASP.NET Core 5.0 MVC 5 Site</Product>
5+
<VersionPrefix>3.9.0</VersionPrefix>
6+
<TargetFramework>net5.0</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="5.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
21+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" PrivateAssets="All" />
22+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" Version="3.8.5" />
23+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="3.8.5" />
24+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-arm" Version="3.8.5" />
25+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-arm64" Version="3.8.5" />
26+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.8.5" />
27+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" Version="3.8.5" />
28+
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.0.0" />
29+
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x86" Version="7.0.0" />
30+
<PackageReference Include="Microsoft.ClearScript.V8.Native.linux-x64" Version="7.0.0" />
31+
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-x64" Version="7.0.0" />
32+
33+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.csproj" />
34+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Extensions.MsDependencyInjection/JavaScriptEngineSwitcher.Extensions.MsDependencyInjection.csproj" />
35+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Jint/JavaScriptEngineSwitcher.Jint.csproj" />
36+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Jurassic/JavaScriptEngineSwitcher.Jurassic.csproj" />
37+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Msie/JavaScriptEngineSwitcher.Msie.csproj" />
38+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.NiL/JavaScriptEngineSwitcher.NiL.csproj" />
39+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Node/JavaScriptEngineSwitcher.Node.csproj" />
40+
<ProjectReference Include="../JavaScriptEngineSwitcher.Sample.Logic/JavaScriptEngineSwitcher.Sample.Logic.csproj" />
41+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.csproj" />
42+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Vroom/JavaScriptEngineSwitcher.Vroom.csproj" />
43+
</ItemGroup>
44+
45+
<ItemGroup>
46+
<None Update="wwwroot/**/*;Views/**/*">
47+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
48+
</None>
49+
</ItemGroup>
50+
51+
<Target Name="NodePackageInstallation" BeforeTargets="BeforeBuild;BeforeClean">
52+
<Exec Command="npm install" ConsoleToMsBuild="true" />
53+
</Target>
54+
<Target Name="BowerPackagesInstallation" AfterTargets="AfterBuild">
55+
<Exec Command="bower install" ConsoleToMsBuild="true" />
56+
</Target>
57+
<Target Name="GulpClean" AfterTargets="AfterClean">
58+
<Exec Command="gulp cleanBuildedAssets" ConsoleToMsBuild="true" />
59+
</Target>
60+
<Target Name="GulpBuild" AfterTargets="BowerPackagesInstallation">
61+
<Exec Command="gulp buildAssets" ConsoleToMsBuild="true" />
62+
</Target>
63+
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
64+
<Exec Command="npm install" />
65+
<Exec Command="bower install" />
66+
<Exec Command="gulp" />
67+
</Target>
68+
</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.AspNetCore5.Mvc5.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore5.Mvc5
6+
{
7+
public class Program
8+
{
9+
public static void Main(string[] args)
10+
{
11+
CreateHostBuilder(args).Build().Run();
12+
}
13+
14+
public static IHostBuilder CreateHostBuilder(string[] args) =>
15+
Host.CreateDefaultBuilder(args)
16+
.ConfigureWebHostDefaults(webBuilder =>
17+
{
18+
webBuilder.UseStartup<Startup>();
19+
})
20+
.ConfigureLogging((hostingContext, logging) =>
21+
{
22+
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
23+
logging.AddConsole();
24+
logging.AddDebug();
25+
})
26+
;
27+
}
28+
}

0 commit comments

Comments
 (0)