Skip to content

Commit e65cce0

Browse files
benaadamsNateBrady23
authored andcommitted
ASP.Net Core add platform dataupdates (#3802)
* ASP.NET Core, Plat, DataUpdates * Fix nancy-netcore
1 parent 12106ef commit e65cce0

17 files changed

+451
-245
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.
3+
4+
using System.Collections.Generic;
5+
using System.IO.Pipelines;
6+
using System.Text.Encodings.Web;
7+
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
9+
10+
namespace PlatformBenchmarks
11+
{
12+
public partial class BenchmarkApplication
13+
{
14+
private async Task Fortunes(PipeWriter pipeWriter)
15+
{
16+
OutputFortunes(pipeWriter, await Db.LoadFortunesRows());
17+
}
18+
19+
private void OutputFortunes(PipeWriter pipeWriter, List<Fortune> model)
20+
{
21+
var writer = GetWriter(pipeWriter);
22+
23+
// HTTP 1.1 OK
24+
writer.Write(_http11OK);
25+
26+
// Server headers
27+
writer.Write(_headerServer);
28+
29+
// Date header
30+
writer.Write(DateHeader.HeaderBytes);
31+
32+
// Content-Type header
33+
writer.Write(_headerContentTypeHtml);
34+
35+
// Content-Length header
36+
writer.Write(_headerContentLength);
37+
38+
var lengthWriter = writer;
39+
writer.Write(_contentLengthGap);
40+
41+
// End of headers
42+
writer.Write(_eoh);
43+
44+
var bodyStart = writer.Buffered;
45+
// Body
46+
writer.Write(_fortunesTableStart);
47+
foreach (var item in model)
48+
{
49+
writer.Write(_fortunesRowStart);
50+
writer.WriteNumeric((uint)item.Id);
51+
writer.Write(_fortunesColumn);
52+
writer.WriteUtf8String(HtmlEncoder.Encode(item.Message));
53+
writer.Write(_fortunesRowEnd);
54+
}
55+
writer.Write(_fortunesTableEnd);
56+
lengthWriter.WriteNumeric((uint)(writer.Buffered - bodyStart));
57+
58+
writer.Commit();
59+
}
60+
}
61+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.
3+
4+
using System.IO.Pipelines;
5+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
6+
using Utf8Json;
7+
8+
namespace PlatformBenchmarks
9+
{
10+
public partial class BenchmarkApplication
11+
{
12+
private static void Json(PipeWriter pipeWriter)
13+
{
14+
var writer = GetWriter(pipeWriter);
15+
16+
// HTTP 1.1 OK
17+
writer.Write(_http11OK);
18+
19+
// Server headers
20+
writer.Write(_headerServer);
21+
22+
// Date header
23+
writer.Write(DateHeader.HeaderBytes);
24+
25+
// Content-Type header
26+
writer.Write(_headerContentTypeJson);
27+
28+
// Content-Length header
29+
writer.Write(_headerContentLength);
30+
var jsonPayload = JsonSerializer.SerializeUnsafe(new JsonMessage { message = "Hello, World!" });
31+
writer.WriteNumeric((uint)jsonPayload.Count);
32+
33+
// End of headers
34+
writer.Write(_eoh);
35+
36+
// Body
37+
writer.Write(jsonPayload);
38+
writer.Commit();
39+
}
40+
}
41+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.
3+
4+
using System.IO.Pipelines;
5+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
6+
7+
namespace PlatformBenchmarks
8+
{
9+
public partial class BenchmarkApplication
10+
{
11+
private static void PlainText(PipeWriter pipeWriter)
12+
{
13+
var writer = GetWriter(pipeWriter);
14+
15+
// HTTP 1.1 OK
16+
writer.Write(_http11OK);
17+
18+
// Server headers
19+
writer.Write(_headerServer);
20+
21+
// Date header
22+
writer.Write(DateHeader.HeaderBytes);
23+
24+
// Content-Type header
25+
writer.Write(_headerContentTypeText);
26+
27+
// Content-Length header
28+
writer.Write(_headerContentLength);
29+
writer.WriteNumeric((uint)_plainTextBody.Length);
30+
31+
// End of headers
32+
writer.Write(_eoh);
33+
34+
// Body
35+
writer.Write(_plainTextBody);
36+
writer.Commit();
37+
}
38+
}
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.
3+
4+
using System.IO.Pipelines;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
7+
using Utf8Json;
8+
9+
namespace PlatformBenchmarks
10+
{
11+
public partial class BenchmarkApplication
12+
{
13+
private async Task SingleQuery(PipeWriter pipeWriter)
14+
{
15+
OutputSingleQuery(pipeWriter, await Db.LoadSingleQueryRow());
16+
}
17+
18+
private static void OutputSingleQuery(PipeWriter pipeWriter, World row)
19+
{
20+
var writer = GetWriter(pipeWriter);
21+
22+
// HTTP 1.1 OK
23+
writer.Write(_http11OK);
24+
25+
// Server headers
26+
writer.Write(_headerServer);
27+
28+
// Date header
29+
writer.Write(DateHeader.HeaderBytes);
30+
31+
// Content-Type header
32+
writer.Write(_headerContentTypeJson);
33+
34+
// Content-Length header
35+
writer.Write(_headerContentLength);
36+
var jsonPayload = JsonSerializer.SerializeUnsafe(row);
37+
writer.WriteNumeric((uint)jsonPayload.Count);
38+
39+
// End of headers
40+
writer.Write(_eoh);
41+
42+
// Body
43+
writer.Write(jsonPayload);
44+
writer.Commit();
45+
}
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.
3+
4+
using System.IO.Pipelines;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
7+
using Utf8Json;
8+
9+
namespace PlatformBenchmarks
10+
{
11+
public partial class BenchmarkApplication
12+
{
13+
private async Task Updates(PipeWriter pipeWriter, int count)
14+
{
15+
OutputUpdates(pipeWriter, await Db.LoadMultipleUpdatesRows(count));
16+
}
17+
18+
private static void OutputUpdates(PipeWriter pipeWriter, World[] rows)
19+
{
20+
var writer = GetWriter(pipeWriter);
21+
22+
// HTTP 1.1 OK
23+
writer.Write(_http11OK);
24+
25+
// Server headers
26+
writer.Write(_headerServer);
27+
28+
// Date header
29+
writer.Write(DateHeader.HeaderBytes);
30+
31+
// Content-Type header
32+
writer.Write(_headerContentTypeJson);
33+
34+
// Content-Length header
35+
writer.Write(_headerContentLength);
36+
var jsonPayload = JsonSerializer.SerializeUnsafe(rows);
37+
writer.WriteNumeric((uint)jsonPayload.Count);
38+
39+
// End of headers
40+
writer.Write(_eoh);
41+
42+
// Body
43+
writer.Write(jsonPayload);
44+
writer.Commit();
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)