Skip to content

Commit fe16cee

Browse files
committed
Adding Automatic tuning demo
1 parent 9ec0359 commit fe16cee

19 files changed

Lines changed: 634 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.xproj.user
2+
.vs/*
3+
.vscode/*
4+
bin/*
5+
obj/*
6+
*.sln
7+
*.log
8+
Properties/PublishProfiles/*
9+
*.development.json
10+
*.lock.json
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Belgrade.SqlClient;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace FlgpWwiDemo.Controllers
7+
{
8+
[Route("api/[controller]")]
9+
public class DemoController : Controller
10+
{
11+
IQueryMapper queryMapper = null;
12+
13+
public DemoController(IQueryMapper queryMapper)
14+
{
15+
this.queryMapper = queryMapper;
16+
}
17+
18+
// GET api/demo
19+
[HttpGet]
20+
[Produces("application/json")]
21+
public async Task<string> Get()
22+
{
23+
decimal result = 0;
24+
string status = "OK";
25+
long start = DateTimeOffset.Now.ToUnixTimeMilliseconds();
26+
long end = 0;
27+
await this.queryMapper
28+
.OnError(ex=> status = ex.Message)
29+
.ExecuteReader("EXEC dbo.report 7", reader => {
30+
result = reader.GetDecimal(0);
31+
end = DateTimeOffset.Now.ToUnixTimeMilliseconds();
32+
});
33+
return "{\"x\":\"" + DateTime.Now.ToUniversalTime().ToString() + "\",\"y\":" + (end-start) + ",\"start\":" + start + ",\"end\":" + end + ",\"result\":" + result +",\"status\":\"" + status + "\"}";
34+
}
35+
36+
37+
// GET api/demo/init
38+
[HttpGet("init")]
39+
public async Task Init()
40+
{
41+
await this.queryMapper.ExecuteReader("EXEC dbo.[initialize]", _ => { });
42+
}
43+
44+
// GET api/demo/regression
45+
[HttpGet("regression")]
46+
public async Task Regression()
47+
{
48+
await this.queryMapper.ExecuteReader("EXEC dbo.regression", _ => { });
49+
}
50+
51+
// GET api/demo/on
52+
[HttpGet("on")]
53+
public async Task On()
54+
{
55+
await this.queryMapper.ExecuteReader("EXEC dbo.auto_tuning_on", _ => { });
56+
}
57+
58+
59+
// GET api/demo/off
60+
[HttpGet("off")]
61+
public async Task Off()
62+
{
63+
await this.queryMapper.ExecuteReader("EXEC dbo.auto_tuning_off", _ => { });
64+
}
65+
}
66+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>ca0088d0-bcb5-4485-89ab-860e23bcf9b7</ProjectGuid>
10+
<RootNamespace>FlgpWwiDemo</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
19+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Builder;
8+
9+
namespace FlgpWwiDemo
10+
{
11+
public class Program
12+
{
13+
public static void Main(string[] args)
14+
{
15+
var host = new WebHostBuilder()
16+
.UseKestrel()
17+
.UseContentRoot(Directory.GetCurrentDirectory())
18+
.UseIISIntegration()
19+
.UseStartup<Startup>()
20+
.Build();
21+
22+
host.Run();
23+
}
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:57485/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"launchUrl": "index.html",
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
}
18+
},
19+
"FlgpWwiDemo": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"launchUrl": "http://localhost:5000/index.html",
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT": "Development"
25+
}
26+
}
27+
}
28+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.SqlClient;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Belgrade.SqlClient;
7+
using Belgrade.SqlClient.SqlDb;
8+
using Microsoft.AspNetCore.Builder;
9+
using Microsoft.AspNetCore.Hosting;
10+
using Microsoft.Extensions.Configuration;
11+
using Microsoft.Extensions.DependencyInjection;
12+
using Microsoft.Extensions.Logging;
13+
14+
namespace FlgpWwiDemo
15+
{
16+
public class Startup
17+
{
18+
public Startup(IHostingEnvironment env)
19+
{
20+
var builder = new ConfigurationBuilder()
21+
.SetBasePath(env.ContentRootPath)
22+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
23+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
24+
.AddEnvironmentVariables();
25+
Configuration = builder.Build();
26+
}
27+
28+
public IConfigurationRoot Configuration { get; }
29+
30+
// This method gets called by the runtime. Use this method to add services to the container.
31+
public void ConfigureServices(IServiceCollection services)
32+
{
33+
string ConnString = Configuration["ConnectionStrings:Wwi"];
34+
35+
// Adding data access services/components.
36+
services.AddTransient<IQueryMapper>(
37+
sp => new QueryMapper(new SqlConnection(ConnString))
38+
);
39+
// Add framework services.
40+
services.AddMvc();
41+
}
42+
43+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
44+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
45+
{
46+
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
47+
loggerFactory.AddDebug();
48+
49+
app.UseStaticFiles();
50+
app.UseMvc();
51+
}
52+
}
53+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Logging": {
3+
"IncludeScopes": false,
4+
"LogLevel": {
5+
"Default": "Debug",
6+
"System": "Information",
7+
"Microsoft": "Information"
8+
}
9+
},
10+
"ConnectionStrings": {
11+
"Wwi": "Server=.;Database=WideWorldImporters;Integrated Security=true"
12+
}
13+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"dependencies": {
3+
"Microsoft.NETCore.App": {
4+
"version": "1.0.1",
5+
"type": "platform"
6+
},
7+
"Microsoft.AspNetCore.Mvc": "1.0.1",
8+
"Microsoft.AspNetCore.Routing": "1.0.1",
9+
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
10+
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
11+
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
12+
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
13+
"Microsoft.Extensions.Configuration.Json": "1.0.0",
14+
"Microsoft.Extensions.Logging": "1.0.0",
15+
"Microsoft.Extensions.Logging.Console": "1.0.0",
16+
"Microsoft.Extensions.Logging.Debug": "1.0.0",
17+
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
18+
"System.Data.SqlClient": "4.3.0",
19+
"Belgrade.Sql.Client": "0.7.0",
20+
"Microsoft.AspNetCore.StaticFiles": "1.1.0"
21+
},
22+
23+
"tools": {
24+
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
25+
},
26+
27+
"frameworks": {
28+
"netcoreapp1.0": {
29+
"imports": [
30+
"dotnet5.6",
31+
"portable-net45+win8"
32+
]
33+
}
34+
},
35+
36+
"buildOptions": {
37+
"emitEntryPoint": true,
38+
"preserveCompilationContext": true
39+
},
40+
41+
"runtimeOptions": {
42+
"configProperties": {
43+
"System.GC.Server": true
44+
}
45+
},
46+
47+
"publishOptions": {
48+
"include": [
49+
"wwwroot",
50+
"**/*.cshtml",
51+
"appsettings.json",
52+
"web.config"
53+
]
54+
},
55+
56+
"scripts": {
57+
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
58+
}
59+
}

0 commit comments

Comments
 (0)