Skip to content

Commit 649efa4

Browse files
committed
Upgraded BelgradeProductCatalog to .csproj
1 parent ef33b71 commit 649efa4

8 files changed

Lines changed: 108 additions & 132 deletions

File tree

samples/demos/belgrade-product-catalog-demo/Controllers/CompanyController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public CompanyController(IQueryPipe sqlQueryService)
2222
[HttpGet]
2323
public async Task Get()
2424
{
25-
await sqlQuery.Stream("select CompanyID as [value], Name as [text] from Company FOR JSON PATH", Response.Body);
25+
await sqlQuery.Sql("select CompanyID as [value], Name as [text] from Company FOR JSON PATH").Stream(Response.Body);
2626
}
2727

2828
[HttpGet("login")]

samples/demos/belgrade-product-catalog-demo/Controllers/ProductController.cs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ await sqlQuery
3737
this.Response.StatusCode = 500;
3838
throw ex;
3939
})
40-
.Stream(@"
40+
.Sql(@"
4141
select ProductID, Name, Color, Price, Quantity,
4242
JSON_VALUE(Data, '$.MadeIn') as MadeIn, JSON_QUERY(Tags) as Tags
4343
from Product
44-
FOR JSON PATH, ROOT('data')", Response.Body, EMPTY_PRODUCTS_ARRAY);
44+
FOR JSON PATH, ROOT('data')").Stream(Response.Body);
4545
}
4646

4747
// GET api/Product/compressed
@@ -50,91 +50,92 @@ public async Task GetCompressed()
5050
{
5151
Response.Headers.Add("Content-Type", "application/json;charset=utf-16");
5252
Response.Headers.Add("Content-Encoding", "gzip");
53-
await sqlQuery.Stream(@"
53+
await sqlQuery.Sql(@"
5454
select COMPRESS(
5555
(select ProductID, Name, Color, Price, Quantity,
5656
JSON_VALUE(Data, '$.MadeIn') as MadeIn, JSON_QUERY(Tags) as Tags
5757
from Product
5858
FOR JSON PATH, ROOT('data') )
59-
)", Response.Body, EMPTY_PRODUCTS_ARRAY_GZIPPED);
59+
)").Stream(Response.Body, EMPTY_PRODUCTS_ARRAY_GZIPPED);
6060
}
6161

6262
// GET api/Product/5
6363
[HttpGet("{id}")]
6464
public async Task Get(int id)
6565
{
66-
var cmd = new SqlCommand(
66+
await sqlQuery.Sql(
6767
@"select ProductID, Product.Name, Color, Price, Quantity,
6868
Company.Name as Company, Company.Address, Company.Email, Company.Phone
6969
from Product
7070
join Company on Product.CompanyID = Company.CompanyID
7171
where ProductID = @id
72-
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
73-
74-
cmd.Parameters.AddWithValue("id", id);
75-
await sqlQuery.Stream(cmd, Response.Body, "{}");
72+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER")
73+
.Param("id", id)
74+
.Stream(Response.Body, "{}");
7675
}
7776

7877
// POST api/Product
7978
[HttpPost]
8079
public async Task Post()
8180
{
8281
string product = new StreamReader(Request.Body).ReadToEnd();
83-
var cmd = new SqlCommand("EXEC InsertProductFromJson @ProductJson");
84-
cmd.Parameters.AddWithValue("ProductJson", product);
85-
await sqlCmd.ExecuteNonQuery(cmd);
82+
await sqlCmd
83+
.Sql("EXEC InsertProductFromJson @ProductJson")
84+
.Param("ProductJson", product)
85+
.Exec();
8686
}
8787

8888
// PUT api/Product/5
8989
[HttpPut("{id}")]
9090
public async Task Put(int id)
9191
{
9292
string product = new StreamReader(Request.Body).ReadToEnd();
93-
var cmd = new SqlCommand("EXEC UpdateProductFromJson @ProductID, @ProductJson");
94-
cmd.Parameters.AddWithValue("ProductID", id);
95-
cmd.Parameters.AddWithValue("ProductJson", product);
96-
await sqlCmd.ExecuteNonQuery(cmd);
93+
await sqlCmd
94+
.Sql("EXEC UpdateProductFromJson @ProductID, @ProductJson")
95+
.Param("ProductID", id)
96+
.Param("ProductJson", product)
97+
.Exec();
9798
}
9899

99100
// DELETE api/Product/5
100101
[HttpDelete("{id}")]
101102
public async Task Delete(int id)
102103
{
103-
var cmd = new SqlCommand(@"delete Product where ProductID = @id");
104-
cmd.Parameters.AddWithValue("id", id);
105-
await sqlCmd.ExecuteNonQuery(cmd);
104+
await sqlCmd.Sql(@"delete Product where ProductID = @id")
105+
.Param("id", id)
106+
.Exec();
106107
}
107108

108109
[HttpGet("temporal")]
109110
[Produces("application/json")]
110111
public async Task Get(DateTime? date)
111112
{
112113
if (date == null)
113-
await this.sqlQuery.Stream("EXEC GetProducts", this.Response.Body, EMPTY_PRODUCTS_ARRAY);
114+
await this.sqlQuery
115+
.Sql("EXEC GetProducts")
116+
.Stream(this.Response.Body, EMPTY_PRODUCTS_ARRAY);
114117
else
115-
{
116-
var cmd = new SqlCommand("EXEC GetProductsAsOf @date");
117-
cmd.Parameters.AddWithValue("@date", date);
118-
await this.sqlQuery.Stream(cmd, this.Response.Body, EMPTY_PRODUCTS_ARRAY);
119-
}
118+
await this.sqlQuery.Sql("EXEC GetProductsAsOf @date")
119+
.Param("date", date)
120+
.Stream(this.Response.Body, EMPTY_PRODUCTS_ARRAY);
120121
}
121122

122123
[HttpGet("restore")]
123124
[Produces("application/json")]
124125
public void RestoreVersion(int ProductId, DateTime DateModified)
125126
{
126-
var cmd = new SqlCommand("EXEC RestoreProduct @productid, @date");
127-
cmd.Parameters.AddWithValue("@productid", ProductId);
128-
cmd.Parameters.AddWithValue("@date", DateModified);
129127
this.sqlCmd
128+
.Sql("EXEC RestoreProduct @productid, @date")
129+
.Param("productid", ProductId)
130+
.Param("date", DateModified)
130131
.OnError(
131132
ex =>
132133
{
133134
logger.LogError("Error while trying to restore product with id {ProductID} from time {DateModified}.\n{Error}\n{StackTrace}", ProductId, DateModified, ex.Message, ex.StackTrace);
134135
this.Response.StatusCode = 500;
135136
throw ex;
136137
})
137-
.ExecuteNonQuery(cmd);
138+
.Exec();
138139
}
139140

140141

@@ -143,12 +144,13 @@ public void RestoreVersion(int ProductId, DateTime DateModified)
143144
public async Task Report1()
144145
{
145146
await sqlQuery
146-
.Stream(@"
147+
.Sql(@"
147148
select color as x, sum(quantity) as y
148149
from product
149150
where color is not null
150151
group by color
151-
for json path", Response.Body, EMPTY_PRODUCTS_ARRAY);
152+
for json path")
153+
.Stream(Response.Body, EMPTY_PRODUCTS_ARRAY);
152154
}
153155

154156

@@ -157,7 +159,7 @@ group by color
157159
public async Task Report2()
158160
{
159161
await sqlQuery
160-
.Stream(@"
162+
.Sql(@"
161163
select name as [key], [values].x, [values].y
162164
from company
163165
join (select companyid, color as x, sum(quantity) as y
@@ -166,7 +168,8 @@ where color is not null
166168
group by companyid, color
167169
) as [values] on company.companyid = [values].companyid
168170
order by company.companyid
169-
for json auto", Response.Body, EMPTY_PRODUCTS_ARRAY);
171+
for json auto")
172+
.Stream(Response.Body, EMPTY_PRODUCTS_ARRAY);
170173
}
171174
}
172175
}

samples/demos/belgrade-product-catalog-demo/ProductCatalog.xproj

Lines changed: 0 additions & 19 deletions
This file was deleted.

samples/demos/belgrade-product-catalog-demo/Startup.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Logging;
1111
using ProductCatalog.Models;
12-
using Serilog;
13-
#if NET46
12+
using Serilog;
13+
using Serilog.Sinks;
1414
using Serilog.Sinks.MSSqlServer;
15-
#endif
1615
using System;
1716
using System.Data.SqlClient;
1817
using System.Linq;
@@ -29,22 +28,24 @@ public Startup(IHostingEnvironment env)
2928
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
3029
.AddEnvironmentVariables();
3130
Configuration = builder.Build();
32-
#if NETCOREAPP1_0
31+
#if NETCOREAPP2_0
3332
Log.Logger = new LoggerConfiguration()
3433
.WriteTo.RollingFile(new Serilog.Formatting.Json.JsonFormatter(), System.IO.Path.Combine(env.ContentRootPath, "logs\\log-{Date}.ndjson"))
3534
.CreateLogger();
3635
#endif
3736
#if NET46
3837
var columnOptions = new ColumnOptions();
3938
// Don't include the Properties XML column.
39+
columnOptions.Store.Remove(StandardColumn.Id);
4040
columnOptions.Store.Remove(StandardColumn.Properties);
4141
columnOptions.Store.Remove(StandardColumn.MessageTemplate);
4242
columnOptions.Store.Remove(StandardColumn.Exception);
43+
columnOptions.TimeStamp.ColumnName = "EventTime";
4344
// Do include the log event data as JSON.
4445
columnOptions.Store.Add(StandardColumn.LogEvent);
4546

4647
Log.Logger = new LoggerConfiguration()
47-
.WriteTo.MSSqlServer(Configuration["ConnectionStrings:BelgradeDemo"], "dbo.Logs", columnOptions: columnOptions)
48+
.WriteTo.MSSqlServer(Configuration["ConnectionStrings:BelgradeDemo"], "Logs", columnOptions: columnOptions, autoCreateSqlTable: false)
4849
.CreateLogger();
4950
#endif
5051
}

samples/demos/belgrade-product-catalog-demo/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
}
99
},
1010
"ConnectionStrings": {
11-
"BelgradeDemo": "Server=.\\SQLEXPRESS;Database=ProductCatalog;Integrated Security=true"
11+
"BelgradeDemo": "Server=.\\SQLEXPRESS;Database=ProductCatalog;Integrated Security=true;Application Name=Belgrade"
1212
}
1313
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<PreserveCompilationContext>true</PreserveCompilationContext>
5+
<AssemblyName>belgrade-product-catalog-demo</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
<PackageId>belgrade-product-catalog-demo</PackageId>
8+
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
9+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
10+
<TargetFrameworkProfile />
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<None Update="wwwroot\**\*;Views\**\*">
15+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
16+
</None>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="Belgrade.Sql.Client" Version="1.1.4" />
21+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" />
22+
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
23+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
24+
<PackageReference Include="Microsoft.AspNetCore.Session" Version="1.0.2" />
25+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2" />
26+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.0.3" />
27+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.2" />
28+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.2" />
29+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
30+
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" />
31+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" />
32+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" />
33+
<PackageReference Include="Serilog" Version="2.5.0" />
34+
<PackageReference Include="Serilog.Extensions.Logging" Version="1.3.1" />
35+
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
36+
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
37+
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
38+
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="5.1.3-dev-00224" />
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<None Update="sql-scripts\bcp.sql.sql">
43+
<DesignTime>True</DesignTime>
44+
<AutoGen>True</AutoGen>
45+
<DependentUpon>bcp.sql.tt</DependentUpon>
46+
</None>
47+
<None Update="sql-scripts\bcp.sql.tt">
48+
<Generator>TextTemplatingFileGenerator</Generator>
49+
<LastGenOutput>bcp.sql.sql</LastGenOutput>
50+
</None>
51+
</ItemGroup>
52+
53+
<ItemGroup>
54+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
55+
</ItemGroup>
56+
57+
</Project>

samples/demos/belgrade-product-catalog-demo/project.json

Lines changed: 0 additions & 63 deletions
This file was deleted.

samples/demos/belgrade-product-catalog-demo/sql-scripts/1 setup.sql

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,10 @@ END
115115
GO
116116
DROP TABLE IF EXISTS Logs;
117117
GO
118-
CREATE TABLE Logs (
119-
Id int IDENTITY PRIMARY KEY,
120-
Message nvarchar(max) NULL,
121-
MessageTemplate nvarchar(max) NULL,
122-
Level nvarchar(128) NULL,
123-
TimeStamp datetimeoffset(7) NOT NULL,
124-
Exception nvarchar(max) NULL,
125-
Properties xml NULL,
126-
LogEvent nvarchar(max) NULL
127-
);
118+
119+
CREATE TABLE Logs(
120+
[Message] NVARCHAR(4000) NOT NULL,
121+
[Level] VARCHAR(16) NOT NULL,
122+
[EventTime] DATETIME2 (7) NOT NULL,
123+
[LogEvent] NVARCHAR(max) NULL
124+
)

0 commit comments

Comments
 (0)