Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "ASP.NET Core Sample Launch",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/samples/CloudNative.CloudEvents.AspNetCoreSample/CloudNative.CloudEvents.AspNetCoreSample.csproj"
},
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
Expand All @@ -24,5 +30,5 @@
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
]
}
254 changes: 0 additions & 254 deletions CloudEvents.sln

This file was deleted.

52 changes: 52 additions & 0 deletions CloudEvents.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<Solution>
<Configurations>
<Platform Name="Any CPU" />
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Folder Name="/conformance/" />
<Folder Name="/conformance/format/">
<File Path="conformance/format/README.md" />
</Folder>
<Folder Name="/conformance/format/json/">
<File Path="conformance/format/json/invalid-batches.json" />
<File Path="conformance/format/json/invalid-events.json" />
<File Path="conformance/format/json/README.md" />
<File Path="conformance/format/json/valid-batches.json" />
<File Path="conformance/format/json/valid-events.json" />
</Folder>
<Folder Name="/conformance/format/protobuf/">
<File Path="conformance/format/protobuf/conformance_tests.proto" />
<File Path="conformance/format/protobuf/invalid-batches.json" />
<File Path="conformance/format/protobuf/invalid-events.json" />
<File Path="conformance/format/protobuf/README.md" />
<File Path="conformance/format/protobuf/valid-batches.json" />
<File Path="conformance/format/protobuf/valid-events.json" />
</Folder>
<Folder Name="/conformance/format/xml/">
<File Path="conformance/format/xml/invalid-batches.xml" />
<File Path="conformance/format/xml/invalid-events.xml" />
<File Path="conformance/format/xml/README.md" />
<File Path="conformance/format/xml/valid-batches.xml" />
<File Path="conformance/format/xml/valid-events.xml" />
</Folder>
<Folder Name="/Solution Items/">
<File Path=".gitignore" />
<File Path="appveyor.yml" />
<File Path="LICENSE" />
<File Path="README.md" />
</Folder>
<Project Path="samples/CloudNative.CloudEvents.AspNetCoreSample/CloudNative.CloudEvents.AspNetCoreSample.csproj" />
<Project Path="samples/HttpSend/HttpSend.csproj" />
<Project Path="src/CloudNative.CloudEvents.Amqp/CloudNative.CloudEvents.Amqp.csproj" />
<Project Path="src/CloudNative.CloudEvents.AspNetCore/CloudNative.CloudEvents.AspNetCore.csproj" />
<Project Path="src/CloudNative.CloudEvents.Avro/CloudNative.CloudEvents.Avro.csproj" />
<Project Path="src/CloudNative.CloudEvents.Kafka/CloudNative.CloudEvents.Kafka.csproj" />
<Project Path="src/CloudNative.CloudEvents.Mqtt/CloudNative.CloudEvents.Mqtt.csproj" />
<Project Path="src/CloudNative.CloudEvents.NewtonsoftJson/CloudNative.CloudEvents.NewtonsoftJson.csproj" />
<Project Path="src/CloudNative.CloudEvents.Protobuf/CloudNative.CloudEvents.Protobuf.csproj" />
<Project Path="src/CloudNative.CloudEvents.SystemTextJson/CloudNative.CloudEvents.SystemTextJson.csproj" />
<Project Path="src/CloudNative.CloudEvents/CloudNative.CloudEvents.csproj" />
<Project Path="test/CloudNative.CloudEvents.IntegrationTests/CloudNative.CloudEvents.IntegrationTests.csproj" />
<Project Path="test/CloudNative.CloudEvents.UnitTests/CloudNative.CloudEvents.UnitTests.csproj" />
</Solution>
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<PackageVersion Include="Apache.Avro" Version="1.11.3" />
<PackageVersion Include="Confluent.Kafka" Version="1.9.3" />
<PackageVersion Include="Google.Protobuf" Version="3.27.3" />
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="5.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.1.34" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.32" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.25" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand All @@ -17,8 +17,8 @@
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Text.Encodings.Web" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.console" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.console" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.400",
"version": "10.0.102",
"allowPrerelease": false,
"rollForward": "latestMinor"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using CloudNative.CloudEvents.AspNetCore;
using CloudNative.CloudEvents.Core;
using CloudNative.CloudEvents.SystemTextJson;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using System.Threading.Tasks;

namespace CloudNative.CloudEvents.AspNetCoreSample.Bindings;

public class CloudEventBinding : IBindableFromHttpContext<CloudEventBinding>
{
public CloudEvent Value { get; init; }

public ProblemHttpResult Error { get; init; }

public static async ValueTask<CloudEventBinding> BindAsync(HttpContext context, ParameterInfo parameter)
{
Validation.CheckNotNull(context, nameof(context));
Validation.CheckNotNull(parameter, nameof(parameter));

var request = context.Request;

// Even though we're not allowing non-JSON content in this binding,
// types such as "text/xml" could still be parsed with the current JsonEventFormatter,
// but it's just not making it strongly typed, or anything structured (XmlNode).
// Depending on your use-case, it may or may not be desirable to allow that.
if (request.ContentLength != 0 && !request.HasJsonContentType())
{
return new CloudEventBinding
{
Error = TypedResults.Problem(
statusCode: StatusCodes.Status415UnsupportedMediaType,
title: "Unsupported media type",
detail: "Request content type is not JSON and not fully supported in this binding. " +
"Please note: the CloudEvents specification does allow for any data content, " +
"as long as it adheres to the provided datacontenttype."
)
};
}

var formatter = context.RequestServices.GetRequiredService<JsonEventFormatter>();

var cloudEvent = await request.ToCloudEventAsync(formatter);

return new CloudEventBinding
{
Value = cloudEvent
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Cloud Native Foundation.
// Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information.

using CloudNative.CloudEvents.AspNetCore;
using CloudNative.CloudEvents.AspNetCoreSample.Bindings;
using CloudNative.CloudEvents.SystemTextJson;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CloudNative.CloudEvents.AspNetCoreSample.Operations
{
public class CloudEventOperations
{
public static async Task<Results<ProblemHttpResult, JsonHttpResult<object>>> ReceiveCloudEvent(CloudEventBinding cloudEventBinding)
{
if (cloudEventBinding.Error is not null)
{
return cloudEventBinding.Error;
}

var cloudEvent = cloudEventBinding.Value;

var cloudEventAttributes = new Dictionary<string, string>();
foreach (var (attribute, attributeValue) in cloudEvent.GetPopulatedAttributes())
{
cloudEventAttributes[attribute.Name] = attribute.Format(attributeValue);
}

return TypedResults.Json<object>(new
{
note = "wow, such event, much disassembling, very skill",
cloudEvent.SpecVersion.VersionId,
cloudEventAttributes,
cloudEvent.Data
});
}

/// <summary>
/// Generates a CloudEvent.
/// </summary>
public static async Task GenerateCloudEvent(HttpResponse response, JsonEventFormatter formatter, ContentMode contentMode = ContentMode.Structured)
{
var evt = new CloudEvent
{
Type = "CloudNative.CloudEvents.AspNetCoreSample",
Source = new Uri("https://github.com/cloudevents/sdk-csharp"),
Time = DateTimeOffset.Now,
DataContentType = "application/json",
Id = Guid.NewGuid().ToString(),
Data = new
{
Language = "C#",
EnvironmentVersion = Environment.Version.ToString()
}
};

response.StatusCode = StatusCodes.Status200OK;
await evt.CopyToHttpResponseAsync(response, contentMode, formatter);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net10.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CloudNative.CloudEvents.AspNetCore\CloudNative.CloudEvents.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\CloudNative.CloudEvents\CloudNative.CloudEvents.csproj" />
<ProjectReference Include="..\..\src\CloudNative.CloudEvents.NewtonsoftJson\CloudNative.CloudEvents.NewtonsoftJson.csproj" />
<ProjectReference Include="..\..\src\CloudNative.CloudEvents.SystemTextJson\CloudNative.CloudEvents.SystemTextJson.csproj" />
</ItemGroup>

</Project>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,56 @@
@HostAddress = https://localhost:5001

### Send via Structured mode

POST {{HostAddress}}/api/events/receive
Content-Type: application/cloudevents+json; charset=utf-8

{
"specversion": "1.0",
"type": "com.example.myevent",
"source": "urn:example-com:mysource:abc",
"id": "{{$guid}}",
"data": {
"message": "Hello world!"
}
}

### Send via Binary mode

POST {{HostAddress}}/api/events/receive
Content-Type: application/json
CE-SpecVersion: 1.0
CE-Type: "com.example.myevent"
CE-Source: "urn:example-com:mysource:abc"
CE-Id: "c457b7c5-c038-4be9-98b9-938cb64a4fbf"
CE-Id: "{{$guid}}"

{
"message": "Hello world!"
}

###
### Send content-less via Binary mode

POST {{HostAddress}}/api/events/receive
CE-SpecVersion: 1.0
CE-Type: "com.example.myevent"
CE-Source: "urn:example-com:mysource:abc"
CE-Id: "{{$guid}}"

### Send unsupported media type (XML) via Binary mode

POST {{HostAddress}}/api/events/receive
Content-Type: text/xml
CE-SpecVersion: 1.0
CE-Type: "com.example.myevent"
CE-Source: "urn:example-com:mysource:abc"
CE-Id: "{{$guid}}"

<message>Hello world!</message>

### Generate via Structured mode

GET {{HostAddress}}/api/events/generate

### Generate via Binary mode

GET {{HostAddress}}/api/events/generate?contentMode=Binary
Loading