Skip to content

Commit 2fffa7c

Browse files
Add sample project
1 parent 7e807e3 commit 2fffa7c

File tree

6 files changed

+145
-1
lines changed

6 files changed

+145
-1
lines changed

Atc.Azure.Messaging.sln

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Azure.Messaging", "src\Atc.Azure.Messaging\Atc.Azure.Messaging.csproj", "{2F7702F2-A407-41FB-8C88-7C066237BC75}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Atc.Azure.Messaging.Tests", "test\Atc.Azure.Messaging.Tests\Atc.Azure.Messaging.Tests.csproj", "{0C49EE44-DAE3-4A7C-9D2D-D1190CAC85F0}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Atc.Azure.Messaging.Tests", "test\Atc.Azure.Messaging.Tests\Atc.Azure.Messaging.Tests.csproj", "{0C49EE44-DAE3-4A7C-9D2D-D1190CAC85F0}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{80664A26-621B-4C22-B341-44EB3CA66724}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApi", "sample\SampleApi\SampleApi.csproj", "{FEFE9828-0DA9-4C88-8D45-416D889012B6}"
913
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,10 +25,17 @@ Global
2125
{0C49EE44-DAE3-4A7C-9D2D-D1190CAC85F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
2226
{0C49EE44-DAE3-4A7C-9D2D-D1190CAC85F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
2327
{0C49EE44-DAE3-4A7C-9D2D-D1190CAC85F0}.Release|Any CPU.Build.0 = Release|Any CPU
28+
{FEFE9828-0DA9-4C88-8D45-416D889012B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{FEFE9828-0DA9-4C88-8D45-416D889012B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{FEFE9828-0DA9-4C88-8D45-416D889012B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{FEFE9828-0DA9-4C88-8D45-416D889012B6}.Release|Any CPU.Build.0 = Release|Any CPU
2432
EndGlobalSection
2533
GlobalSection(SolutionProperties) = preSolution
2634
HideSolutionNode = FALSE
2735
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{FEFE9828-0DA9-4C88-8D45-416D889012B6} = {80664A26-621B-4C22-B341-44EB3CA66724}
38+
EndGlobalSection
2839
GlobalSection(ExtensibilityGlobals) = postSolution
2940
SolutionGuid = {1EC093F7-1E03-4088-BA72-0DEB39AFEE82}
3041
EndGlobalSection

sample/SampleApi/Program.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Atc.Azure.Messaging.EventHub;
2+
3+
var builder = WebApplication.CreateBuilder(args);
4+
builder.Services.AddEndpointsApiExplorer();
5+
builder.Services.AddSwaggerGen();
6+
builder.Services.AddSingleton<SendDataHandler>();
7+
8+
// Register Atc.Azure.Messaging dependencies
9+
builder.Services.ConfigureMessagingServices(builder.Configuration);
10+
11+
var app = builder.Build();
12+
app.UseHttpsRedirection();
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.MapPost(
20+
"/data",
21+
(Request request, SendDataHandler handler) => handler.Post(request));
22+
23+
app.Run();
24+
25+
#pragma warning disable MA0048 // File name must match type name
26+
#pragma warning disable SA1649 // File name should match first type name
27+
#pragma warning disable MA0047 // Declare types in namespaces
28+
#pragma warning disable S3903 // Types should be defined in named namespaces
29+
30+
internal class SendDataHandler
31+
{
32+
private readonly IEventHubPublisher publisher;
33+
34+
public SendDataHandler(IEventHubPublisherFactory factory)
35+
{
36+
publisher = factory.Create("ocpi");
37+
}
38+
39+
public async Task<Response> Post(Request request)
40+
{
41+
await publisher
42+
.PublishAsync(
43+
request,
44+
new Dictionary<string, string>(StringComparer.Ordinal)
45+
{
46+
{ "MessageType", "example" },
47+
});
48+
49+
return new Response(
50+
Guid.NewGuid().ToString("N"),
51+
request.A,
52+
request.B,
53+
request.C);
54+
}
55+
}
56+
57+
internal record Request(string A, string B, string C);
58+
59+
internal record Response(string Id, string A, string B, string C);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:20787",
8+
"sslPort": 44330
9+
}
10+
},
11+
"profiles": {
12+
"SampleApi": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "https://localhost:7091;http://localhost:5091",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
24+
"launchBrowser": true,
25+
"launchUrl": "swagger",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

sample/SampleApi/SampleApi.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\Atc.Azure.Messaging\Atc.Azure.Messaging.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

sample/SampleApi/appsettings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*",
9+
"EventHubOptions": {
10+
"ConnectionString": "Endpoint=sb://[your eventhub namespace].servicebus.windows.net/;SharedAccessKeyName=[eventhub name];SharedAccessKey=[sas key]"
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*",
9+
"NamingOptions": {
10+
"CompanyAbbreviation": "cl",
11+
"SystemAbbreviation": "cpms",
12+
"ServiceAbbreviation": "ocpi"
13+
}
14+
}

0 commit comments

Comments
 (0)