Skip to content

Commit

Permalink
Merge pull request #14 from ejball/events
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball authored Jul 4, 2024
2 parents 0fd26c0 + 91582d5 commit 27464ae
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<VersionPrefix>3.9.0</VersionPrefix>
<PackageValidationBaselineVersion>3.8.0</PackageValidationBaselineVersion>
<VersionPrefix>3.10.0</VersionPrefix>
<PackageValidationBaselineVersion>3.9.0</PackageValidationBaselineVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Facility.CodeGen.Console" Version="2.13.0" />
<PackageVersion Include="Facility.ConformanceApi" Version="2.28.2" />
<PackageVersion Include="Facility.Core" Version="2.28.2" />
<PackageVersion Include="Facility.Definition" Version="2.13.0" />
<PackageVersion Include="Facility.CodeGen.Console" Version="2.14.0" />
<PackageVersion Include="Facility.ConformanceApi" Version="2.29.0" />
<PackageVersion Include="Facility.Core" Version="2.29.0" />
<PackageVersion Include="Facility.Definition" Version="2.14.0" />
<PackageVersion Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.3.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 3.10.0

* Support events. (Must opt-in via `FsdParserSettings.SupportsEvents`.)

## 3.9.0

* Add support for service results and errors to `FacilityActionFilter` for controllers.
Expand Down
9 changes: 9 additions & 0 deletions conformance/ConformanceApi.fsd
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ service ConformanceApi
[http(from: body, type: "application/x-output")] content: bytes;
}

[http(method: GET)]
event fibonacci
{
count: int32!;
}:
{
value: int32!;
}

data Any
{
string: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Hosting;
using Facility.ConformanceApi;
using Facility.ConformanceApi.Testing;
using Facility.Core;
Expand Down Expand Up @@ -35,8 +37,15 @@ public void Configuration(IAppBuilder app)
{
var configuration = new HttpConfiguration();
configuration.MapHttpAttributeRoutes();
configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferPolicySelector());
app.UseWebApi(configuration);
}

private sealed class NoBufferPolicySelector : IHostBufferPolicySelector
{
public bool UseBufferedInputStream(object hostContext) => false;
public bool UseBufferedOutputStream(HttpResponseMessage response) => false; //// required for event streaming
}
}

private static IReadOnlyList<ConformanceTestInfo> LoadTests()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Hosting;
using Facility.ConformanceApi.Http;
using Facility.ConformanceApi.Testing;
using Facility.Core;
Expand Down Expand Up @@ -32,8 +34,15 @@ public void Configuration(IAppBuilder app)
Tests = LoadTests(),
JsonSerializer = JsonSerializer,
})));
configuration.Services.Replace(typeof(IHostBufferPolicySelector), new NoBufferPolicySelector());
app.UseWebApi(configuration);
}

private sealed class NoBufferPolicySelector : IHostBufferPolicySelector
{
public bool UseBufferedInputStream(object hostContext) => false;
public bool UseBufferedOutputStream(HttpResponseMessage response) => false; //// required for event streaming
}
}

private static IReadOnlyList<ConformanceTestInfo> LoadTests()
Expand Down
2 changes: 1 addition & 1 deletion dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"facilityconformance": {
"version": "2.28.2",
"version": "2.29.0",
"commands": [
"FacilityConformance"
],
Expand Down
11 changes: 11 additions & 0 deletions src/Facility.CodeGen.AspNet/AspNetGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Facility.Definition;
using Facility.Definition.CodeGen;
using Facility.Definition.Fsd;
using Facility.Definition.Http;

namespace Facility.CodeGen.AspNet;
Expand All @@ -12,8 +13,18 @@ public sealed class AspNetGenerator : CodeGenerator
/// <summary>
/// Generates an ASP.NET controller.
/// </summary>
/// <param name="parser">The parser.</param>
/// <param name="settings">The settings.</param>
/// <returns>The number of updated files.</returns>
public static int GenerateAspNet(ServiceParser parser, AspNetGeneratorSettings settings) =>
FileGenerator.GenerateFiles(parser, new AspNetGenerator { GeneratorName = nameof(AspNetGenerator) }, settings);

/// <summary>
/// Generates an ASP.NET controller.
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns>The number of updated files.</returns>
[Obsolete("Use the overload that takes a parser.")]
public static int GenerateAspNet(AspNetGeneratorSettings settings) =>
FileGenerator.GenerateFiles(new AspNetGenerator { GeneratorName = nameof(AspNetGenerator) }, settings);

Expand Down
2 changes: 1 addition & 1 deletion src/Facility.CodeGen.AspNet/Facility.CodeGen.AspNet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
<Description>A library that generates an ASP.NET controller for a Facility Service Definition.</Description>
<PackageTags>Facility FSD ASP.NET CodeGen</PackageTags>
<IsPackable>true</IsPackable>
Expand Down
3 changes: 3 additions & 0 deletions src/fsdgenaspnet/FsdGenAspNetApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Facility.CodeGen.AspNet;
using Facility.CodeGen.Console;
using Facility.Definition.CodeGen;
using Facility.Definition.Fsd;

namespace fsdgenaspnet;

Expand All @@ -24,6 +25,8 @@ public sealed class FsdGenAspNetApp : CodeGeneratorApp
" The target ASP.NET framework (default webapi).",
];

protected override ServiceParser CreateParser() => new FsdParser(new FsdParserSettings { SupportsEvents = true });

protected override CodeGenerator CreateGenerator() => new AspNetGenerator();

protected override FileGeneratorSettings CreateSettings(ArgsReader args) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void GenerateConformanceApiSuccess()
{
ServiceInfo service;
const string fileName = "Facility.CodeGen.AspNet.UnitTests.ConformanceApi.fsd";
var parser = new FsdParser();
var parser = new FsdParser(new FsdParserSettings { SupportsEvents = true });
var stream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream(fileName);
Assert.That(stream, Is.Not.Null);
using (var reader = new StreamReader(stream!))
Expand Down

0 comments on commit 27464ae

Please sign in to comment.