Skip to content

Commit dddeb62

Browse files
author
N. Taylor Mullen
committed
Convert to CLI.
1 parent c2a4b30 commit dddeb62

File tree

12 files changed

+118
-96
lines changed

12 files changed

+118
-96
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@
4848
*.fsproj text=auto
4949
*.dbproj text=auto
5050
*.sln text=auto eol=crlf
51+
*.sh eol=lf

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ version.h
3535

3636
# Profiler result files, just in case they are left lying around :)
3737
/.vs/
38+
.testPublish/
39+
.build/

build.cmd

+2-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,2 @@
1-
@ECHO off
2-
SETLOCAL
3-
4-
SET REPO_FOLDER=%~dp0
5-
CD %REPO_FOLDER%
6-
7-
SET BUILD_FOLDER=.build
8-
SET KOREBUILD_FOLDER=%BUILD_FOLDER%\KoreBuild-dotnet
9-
SET KOREBUILD_VERSION=
10-
11-
SET NUGET_PATH=%BUILD_FOLDER%\NuGet.exe
12-
SET NUGET_VERSION=latest
13-
SET CACHED_NUGET=%LocalAppData%\NuGet\nuget.%NUGET_VERSION%.exe
14-
15-
IF NOT EXIST %BUILD_FOLDER% (
16-
md %BUILD_FOLDER%
17-
)
18-
19-
IF NOT EXIST %NUGET_PATH% (
20-
IF NOT EXIST %CACHED_NUGET% (
21-
echo Downloading latest version of NuGet.exe...
22-
IF NOT EXIST %LocalAppData%\NuGet (
23-
md %LocalAppData%\NuGet
24-
)
25-
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/%NUGET_VERSION%/nuget.exe' -OutFile '%CACHED_NUGET%'"
26-
)
27-
28-
copy %CACHED_NUGET% %NUGET_PATH% > nul
29-
)
30-
31-
IF NOT EXIST %KOREBUILD_FOLDER% (
32-
SET KOREBUILD_DOWNLOAD_ARGS=
33-
IF NOT "%KOREBUILD_VERSION%"=="" (
34-
SET KOREBUILD_DOWNLOAD_ARGS=-version %KOREBUILD_VERSION%
35-
)
36-
37-
%BUILD_FOLDER%\nuget.exe install KoreBuild-dotnet -ExcludeVersion -o %BUILD_FOLDER% -nocache -pre %KOREBUILD_DOWNLOAD_ARGS%
38-
)
39-
40-
"%KOREBUILD_FOLDER%\build\KoreBuild.cmd" %*
1+
@ECHO OFF
2+
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"

build.ps1

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cd $PSScriptRoot
2+
3+
$repoFolder = $PSScriptRoot
4+
$env:REPO_FOLDER = $repoFolder
5+
6+
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip"
7+
if ($env:KOREBUILD_ZIP)
8+
{
9+
$koreBuildZip=$env:KOREBUILD_ZIP
10+
}
11+
12+
$buildFolder = ".build"
13+
$buildFile="$buildFolder\KoreBuild.ps1"
14+
15+
if (!(Test-Path $buildFolder)) {
16+
Write-Host "Downloading KoreBuild from $koreBuildZip"
17+
18+
$tempFolder=$env:TEMP + "\KoreBuild-" + [guid]::NewGuid()
19+
New-Item -Path "$tempFolder" -Type directory | Out-Null
20+
21+
$localZipFile="$tempFolder\korebuild.zip"
22+
23+
Invoke-WebRequest $koreBuildZip -OutFile $localZipFile
24+
Add-Type -AssemblyName System.IO.Compression.FileSystem
25+
[System.IO.Compression.ZipFile]::ExtractToDirectory($localZipFile, $tempFolder)
26+
27+
New-Item -Path "$buildFolder" -Type directory | Out-Null
28+
copy-item "$tempFolder\**\build\*" $buildFolder -Recurse
29+
30+
# Cleanup
31+
if (Test-Path $tempFolder) {
32+
Remove-Item -Recurse -Force $tempFolder
33+
}
34+
}
35+
36+
&"$buildFile" $args

experimental/BasicAsyncHttpServer/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BasicAsyncHttpServer
77
{
88
public class Program
99
{
10-
public void Main(string[] args)
10+
public static void Main(string[] args)
1111
{
1212
}
1313
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"version": "1.0.0-*",
3-
"dependencies": {
3+
"compilationOptions": {
4+
"emitEntryPoint": true
45
},
5-
6-
"commands": {
7-
"BasicAsyncHttpServer": "BasicAsyncHttpServer"
6+
"dependencies": {
87
},
9-
108
"frameworks": {
11-
"dnx451": { }
9+
"net451": { }
1210
}
1311
}
+5-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
{
22
"version": "1.0.0-*",
3-
"description": "",
4-
"authors": [ "" ],
5-
"tags": [ "" ],
6-
"projectUrl": "",
7-
"licenseUrl": "",
8-
9-
"dependencies": {
3+
"compilationOptions": {
4+
"emitEntryPoint": true
105
},
11-
12-
"commands": {
13-
"BasicHttpServer" : "BasicHttpServer"
6+
"dependencies": {
147
},
15-
16-
"frameworks" : {
17-
"dnx451": { }
8+
"frameworks": {
9+
"net451": { }
1810
}
1911
}
+3-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
{
22
"version": "1.0.0-*",
3-
4-
"dependencies": {
5-
},
63
"compilationOptions": {
4+
"emitEntryPoint": true,
75
"allowUnsafe": true
86
},
9-
"commands": {
10-
"NativeHttpServer": "NativeHttpServer"
7+
"dependencies": {
118
},
12-
139
"frameworks": {
14-
"dnx451": { }
10+
"net451": { }
1511
}
1612
}
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,75 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Threading.Tasks;
55
using Benchmarks.Data;
66
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.DependencyInjection;
78

89
namespace Benchmarks.Controllers
910
{
1011
[Route("mvc")]
1112
public class FortunesController : Controller
1213
{
13-
private readonly RawDb _rawDb;
14-
private readonly DapperDb _dapperDb;
15-
private readonly EfDb _efDb;
14+
private RawDb _rawDb;
15+
private DapperDb _dapperDb;
16+
private EfDb _efDb;
1617

17-
public FortunesController(RawDb rawDb, DapperDb dapperDb, EfDb efDb)
18+
private RawDb RawDb
1819
{
19-
_rawDb = rawDb;
20-
_dapperDb = dapperDb;
21-
_efDb = efDb;
20+
get
21+
{
22+
if (_rawDb == null)
23+
{
24+
_rawDb = HttpContext.RequestServices.GetRequiredService<RawDb>();
25+
}
26+
27+
return _rawDb;
28+
}
29+
}
30+
31+
private DapperDb DapperDb
32+
{
33+
get
34+
{
35+
if (_dapperDb == null)
36+
{
37+
_dapperDb = HttpContext.RequestServices.GetRequiredService<DapperDb>();
38+
}
39+
40+
return _dapperDb;
41+
}
42+
}
43+
44+
private EfDb EfDb
45+
{
46+
get
47+
{
48+
if (_efDb == null)
49+
{
50+
_efDb = HttpContext.RequestServices.GetRequiredService<EfDb>();
51+
}
52+
53+
return _efDb;
54+
}
2255
}
2356

2457
[HttpGet("fortunes/raw")]
2558
public async Task<IActionResult> Raw()
2659
{
27-
return View("Fortunes", await _rawDb.LoadFortunesRows());
60+
return View("Fortunes", await RawDb.LoadFortunesRows());
2861
}
2962

3063
[HttpGet("fortunes/dapper")]
3164
public async Task<IActionResult> Dapper()
3265
{
33-
return View("Fortunes", await _dapperDb.LoadFortunesRows());
66+
return View("Fortunes", await DapperDb.LoadFortunesRows());
3467
}
3568

3669
[HttpGet("fortunes/ef")]
3770
public async Task<IActionResult> Ef()
3871
{
39-
return View("Fortunes", await _efDb.LoadFortunesRows());
72+
return View("Fortunes", await EfDb.LoadFortunesRows());
4073
}
4174
}
4275
}

src/Benchmarks/Program.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.IO;
@@ -15,11 +15,11 @@ public class Program
1515
{
1616
public static string[] Args;
1717
public static string Server;
18-
18+
1919
public static void Main(string[] args)
2020
{
2121
Args = args;
22-
22+
2323
Console.WriteLine();
2424
Console.WriteLine("ASP.NET Core Benchmarks");
2525
Console.WriteLine("-----------------------");

src/Benchmarks/Startup.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Data.Common;
@@ -34,7 +34,7 @@ public Startup(IApplicationEnvironment appEnv, IHostingEnvironment hostingEnv, S
3434
}
3535

3636
public IConfigurationRoot Configuration { get; set; }
37-
37+
3838
public Scenarios Scenarios { get; }
3939

4040
public void ConfigureServices(IServiceCollection services)
@@ -52,7 +52,7 @@ public void ConfigureServices(IServiceCollection services)
5252
.AddDbContext<ApplicationDbContext>();
5353

5454
if (Scenarios.Any("Raw") || Scenarios.Any("Dapper"))
55-
{
55+
{
5656
// TODO: Add support for plugging in different DbProviderFactory implementations via configuration
5757
services.AddSingleton<DbProviderFactory>(SqlClientFactory.Instance);
5858
}
@@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
8181
{
8282
var mvcBuilder = services.AddMvcCore()
8383
.AddControllersAsServices(typeof(Startup).GetTypeInfo().Assembly);
84-
84+
8585
if (Scenarios.MvcApis)
8686
{
8787
mvcBuilder.AddJsonFormatters();
@@ -96,7 +96,7 @@ public void ConfigureServices(IServiceCollection services)
9696
}
9797
}
9898

99-
public void Configure(IApplicationBuilder app, ApplicationDbSeeder dbSeeder)
99+
public void Configure(IApplicationBuilder app, ApplicationDbSeeder dbSeeder, ApplicationDbContext dbContext)
100100
{
101101
app.UseErrorHandler();
102102

@@ -160,6 +160,8 @@ public void Configure(IApplicationBuilder app, ApplicationDbSeeder dbSeeder)
160160

161161
if (Scenarios.Any("Db"))
162162
{
163+
dbContext.Database.EnsureCreated();
164+
163165
if (!dbSeeder.Seed())
164166
{
165167
Environment.Exit(1);

src/Benchmarks/project.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"webroot": "wwwroot",
33
"version": "1.0.0-*",
44
"compilationOptions": {
5-
"emitEntryPoint": true
5+
"emitEntryPoint": true,
6+
"preserveCompilationContext": true
67
},
78
"dependencies": {
89
"Dapper": "1.50.0-*",
@@ -14,19 +15,18 @@
1415
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
1516
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0-*"
1617
},
17-
"commands": {
18-
"Benchmarks": "Benchmarks",
19-
"ef": "Microsoft.EntityFrameworkCore.Commands"
20-
},
2118
"frameworks": {
22-
"dnxcore50": {
23-
"imports": "portable-net451+win8",
19+
"netstandardapp1.5": {
20+
"imports": [ "portable-net451+win8", "dnxcore50" ],
2421
"dependencies": {
2522
"NETStandard.Library": "1.0.0-*",
2623
"System.Runtime.Serialization.Primitives": "4.1.0-*"
2724
}
2825
},
29-
"net451": {}
26+
"net451": { }
27+
},
28+
"tools": {
29+
"dotnet-ef": "1.0.0-*"
3030
},
3131
"content": [ "appsettings.json" ],
3232
"publishExclude": [

0 commit comments

Comments
 (0)