Skip to content

Commit

Permalink
Merge branch 'main' into feature/mstest2
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Svensson authored Jun 9, 2023
2 parents 936f546 + 3158a17 commit 8a7ee69
Show file tree
Hide file tree
Showing 56 changed files with 492 additions and 2,588 deletions.
25 changes: 25 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# 5.3.1 with EFCore 2.0.2 and AspNetCore 0.3.0

* Code Generation
* Switch to using Mono.Cecil to parse pdb files during code generation (#410)
This should make it possible to use portable and embedded pdb's on the server
*
* AspNetCore
* New extension method to add OpenRiaServices to services from #413 by @ehsangfl.
```C#
services.AddOpenRiaServices<T>()
```
* New extension method to add OpenRiaServices to pipeline from #413 by @ehsangfl.
```C#
endpoints.MapOpenRiaServices(opt => opt.AddDomainService<T>())
```
* Add Net7 build target to support "Finally Conventions" (`IEndpointConventionBuilder.Finally`)
* Add `OpenRiaServices.Server.DomainOperationEntry` to endpoint metadata
* This allows end user to easier implement additional conventions (such as Open Api or similar)
* Copy `AuthorizationAttribute`s to endpoint metadata for queries and invokes to support [AspNetCore Authorization](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/simple?view=aspnetcore-7.0)
* Attributes can be set on either method or class level
* Fixed serialization of sizes larger than 1 GB

*Other*
- Updated nuget packages

# 5.3.0 with EFCore 2.0.1

* Fix shadow property issue in EF Core DB Context extensions (#397):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
</dependencies>
</metadata>
<files>
<file src="build\OpenRiaServices.CodeGen.targets" target="build\OpenRiaServices.Client.CodeGen.targets"/>
<file src="..\..\src\bin\Release\net472\OpenRiaServices.Tools.dll" target="build\OpenRiaServices.Tools.dll"/>
<file src="..\..\src\bin\Release\net472\Mono.Cecil.dll" target="build\Mono.Cecil.dll"/>
<file src="..\..\src\OpenRiaServices.Tools\Framework\build\OpenRiaServices.Client.CodeGen.targets" target="build\OpenRiaServices.Client.CodeGen.targets"/>
<file src="..\..\src\bin\Release\net472\OpenRiaServices.Tools.dll" target="tasks\net472\OpenRiaServices.Tools.dll"/>
<file src="..\..\src\bin\Release\net472\Mono.Cecil.dll" target="tasks\net472\Mono.Cecil.dll"/>
<file src="..\..\src\bin\Release\net472\Mono.Cecil.Pdb.dll" target="tasks\net472\Mono.Cecil.Pdb.dll"/>
</files>
</package>
4 changes: 2 additions & 2 deletions NuGet/OpenRiaServices.Client.Core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<group targetFramework="net472" />
<group targetFramework="netstandard2.0">
<dependency id="System.ComponentModel.Annotations" version="5.0.0" />
<dependency id="System.ServiceModel.Http" version="4.8.1" />
<dependency id="System.ServiceModel.Primitives" version="4.8.1" />
<dependency id="System.ServiceModel.Http" version="4.10.2" />
<dependency id="System.ServiceModel.Primitives" version="4.10.2" />
</group>
</dependencies>
<frameworkAssemblies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependencies>
<group targetFramework="net472">
<dependency id="OpenRiaServices.Server" version="$version$"/>
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="6.0.0"/>
<dependency id="Microsoft.Extensions.DependencyInjection.Abstractions" version="7.0.0"/>
</group>
</dependencies>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions NuGet/OpenRiaServices.Server/OpenRiaServices.Server.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
<group targetFramework="netstandard2.0">
<dependency id="System.ComponentModel.Annotations" version="5.0.0"/>
<dependency id="System.Reflection.Emit.Lightweight" version="4.7.0"/>
<dependency id="System.CodeDom" version="6.0.0"/>
<dependency id="System.CodeDom" version="7.0.0"/>
<dependency id="System.Threading.Tasks.Extensions" version="4.5.4"/>
</group>
<group targetFramework="net6.0">
<dependency id="System.CodeDom" version="6.0.0"/>
<dependency id="System.CodeDom" version="7.0.0"/>
</group>
</dependencies>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion NuGet/OpenRiaServices.T4.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tags>WCF RIA Services RIAServices T4 OpenRiaServices</tags>
<dependencies>
<dependency id="OpenRiaServices.Server" version="$version$" />
<dependency id="Mono.Cecil" version="0.11.4" />
<dependency id="Mono.Cecil" version="0.11.5" />
</dependencies>
</metadata>
<files>
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,11 @@ Here are the most common nuget packages and their current versions.
| OpenRiaServices.T4 | [![NuGet](https://img.shields.io/nuget/v/OpenRiaServices.T4.svg)](https://www.nuget.org/packages/OpenRiaServices.T4) | [![NuGet](https://img.shields.io/nuget/vpre/OpenRiaServices.T4.svg)]() |
| OpenRiaServices.Endpoints | [![NuGet](https://img.shields.io/nuget/v/OpenRiaServices.Endpoints.svg)](https://www.nuget.org/packages/OpenRiaServices.Endpoints) | [![NuGet](https://img.shields.io/nuget/vpre/OpenRiaServices.Endpoints.svg)](https://www.nuget.org/packages/OpenRiaServices.Endpoints) |

# Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
For more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).

# .NET Foundation

This project is supported by the [.NET Foundation](https://dotnetfoundation.org).
9 changes: 8 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ variables:

steps:

# install dotnet 6 sdk so we can run tests against them
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.0.x'

# install dotet 7 sdk to allow compilation target
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '7.0.x'

- task: NuGetToolInstaller@1
inputs:
versionSpec: 6.3.0
versionSpec: 6.5.0

- task: gitversion/setup@0
displayName: Install GitVersion
Expand Down
12 changes: 6 additions & 6 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ContinuousIntegrationBuild Condition="'$(BUILD_BUILDID)' != '' and '$(IsFrameworkProject)' == 'true'">true</ContinuousIntegrationBuild>

<!-- Use csharp 10.0 for all projects -->
<LangVersion Condition="'$(MSBuildProjectExtension)' == '.csproj'">10.0</LangVersion>
<LangVersion Condition="'$(MSBuildProjectExtension)' == '.csproj'">11.0</LangVersion>

<SonarQubeTestProject Condition="'$(IsTestProject)' == 'true'">True</SonarQubeTestProject>

Expand All @@ -22,14 +22,16 @@
<VersionSuffix>preview.5</VersionSuffix>
-->
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<Company>Outercurve Foundation</Company>
<Product>Open RIA Services</Product>
<Copyright>Outercurve Foundation. All rights reserved.</Copyright>
<Company>.NET Foundation</Company>
<Product>OpenRiaServices</Product>
<Copyright>.NET Foundation</Copyright>
<Title>$(MSBuildProjectName)</Title>
<PackageProjectUrl>https://github.com/OpenRIAServices/OpenRiaServices/</PackageProjectUrl>
<RepositoryUrl>https://github.com/OpenRIAServices/OpenRiaServices.git</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>For release notes see https://github.com/OpenRIAServices/OpenRiaServices/releases</PackageReleaseNotes>
<Authors>OpenRIAServices</Authors>

<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageOutputPath>$(MSBuildThisFileDirectory)..\Nuget\bin</PackageOutputPath>
Expand All @@ -40,8 +42,6 @@
<!-- Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<PackageReleaseNotes>For release notes see https://github.com/OpenRIAServices/OpenRiaServices/releases</PackageReleaseNotes>
<Authors>Outercurve RIA Services</Authors>

<!-- Setup signing-->
<SignAssembly>true</SignAssembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.2" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Http" Version="4.10.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public static void AddOpenRiaServices(this IServiceCollection services)
services.AddSingleton<OpenRiaServicesEndpointDataSource>();
}

public static void AddOpenRiaServices<T>(this IServiceCollection services) where T : OpenRiaServices.Server.DomainService
{
ArgumentNullException.ThrowIfNull(services);

services.AddSingleton<OpenRiaServicesEndpointDataSource>();

services.AddTransient<T>();
}

public static IEndpointConventionBuilder MapOpenRiaServices(this IEndpointRouteBuilder endpoints, Action<OpenRiaServicesConfigurationBuilder> configure)
{
return endpoints.MapOpenRiaServices(string.Empty, configure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@ public void AddDomainService(Type type)

_dataSource.DomainServices.Add(longName + "/binary", description);
}

public void AddDomainService<T>()
{
var type = typeof(T);
var longName = type.FullName.Replace('.', '-') + ".svc";
var description = DomainServiceDescription.GetDescription(type);

_dataSource.DomainServices.Add(longName + "/binary", description);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
Expand All @@ -16,14 +18,15 @@ namespace OpenRiaServices.Hosting.AspNetCore
{
internal class OpenRiaServicesEndpointDataSource : EndpointDataSource, IEndpointConventionBuilder
{
private readonly List<Action<EndpointBuilder>> _conventions;
private readonly List<Action<EndpointBuilder>> _conventions = new();
private readonly List<Action<EndpointBuilder>> _finallyConventions = new();

public Dictionary<string, DomainServiceDescription> DomainServices { get; } = new();
private List<Endpoint> _endpoints;

public OpenRiaServicesEndpointDataSource(RoutePatternTransformer routePatternTransformer)
public OpenRiaServicesEndpointDataSource()
{
_conventions = new List<Action<EndpointBuilder>>();

}

public override IReadOnlyList<Endpoint> Endpoints
Expand All @@ -47,9 +50,18 @@ private List<Endpoint> BuildEndpoints()
var getOrPost = new HttpMethodMetadata(new[] { "GET", "POST" });
var postOnly = new HttpMethodMetadata(new[] { "POST" });


foreach (var (name, domainService) in DomainServices)
{
var serializationHelper = new SerializationHelper(domainService);
List<object> additionalMetadata = new List<object>();
foreach (Attribute attribute in domainService.Attributes)
{
if (CopyAttributeToEndpointMetadata(attribute))
additionalMetadata.Add(attribute);
}
// Consider adding additional metadata souch as route groups etc
//endpointBuilder.Metadata.Add(new EndpointGroupNameAttribute(domainService));

foreach (var operation in domainService.DomainOperationEntries)
{
Expand All @@ -70,31 +82,25 @@ private List<Endpoint> BuildEndpoints()
else
continue;

AddEndpoint(endpoints, name, invoker, hasSideEffects ? postOnly : getOrPost);
AddEndpoint(endpoints, name, invoker, hasSideEffects ? postOnly : getOrPost, additionalMetadata);
}

var submit = new ReflectionDomainServiceDescriptionProvider.ReflectionDomainOperationEntry(domainService.DomainServiceType,
typeof(DomainService).GetMethod(nameof(DomainService.SubmitAsync)), DomainOperation.Custom);

var submitOperationInvoker = new SubmitOperationInvoker(submit, serializationHelper);
AddEndpoint(endpoints, name, submitOperationInvoker, postOnly);
AddEndpoint(endpoints, name, submitOperationInvoker, postOnly, additionalMetadata);


}

return endpoints;
}

private void AddEndpoint(List<Endpoint> endpoints, string domainService, OperationInvoker invoker, HttpMethodMetadata httpMethod)
private void AddEndpoint(List<Endpoint> endpoints, string domainService, OperationInvoker invoker, HttpMethodMetadata httpMethod, List<object> additionalMetadata)
{
var route = RoutePatternFactory.Parse($"{Prefix}/{domainService}/{invoker.OperationName}");

// TODO: looka at adding authorization and authentication metadata to endpoiunt
// authorization - look for any attribute implementing microsoft.aspnetcore.authorization.iauthorizedata
// https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authorization.iauthorizedata?view=aspnetcore-6.0

//var aut = operation.Attributes.Cast<Attribute>().OfType<Microsoft.spNetCore.Authorization.IAuthorizeData>().ToList();

var endpointBuilder = new RouteEndpointBuilder(
invoker.Invoke,
route,
Expand All @@ -103,14 +109,51 @@ private void AddEndpoint(List<Endpoint> endpoints, string domainService, Operati
DisplayName = $"{domainService}.{invoker.OperationName}"
};
endpointBuilder.Metadata.Add(httpMethod);
//endpointBuilder.Metadata.Add(new EndpointGroupNameAttribute(domainService));
endpointBuilder.Metadata.Add(invoker.DomainOperation);

// Copy all AspNetCore Authorization attributes
foreach (Attribute attribute in invoker.DomainOperation.Attributes)
{
if (CopyAttributeToEndpointMetadata(attribute))
endpointBuilder.Metadata.Add(attribute);
}

// Try to add MethodInfo
//if (TryGetMethodInfo(invoker) is MethodInfo method)
//{
// endpointBuilder.Metadata.Add(method);
//}

foreach (var metadata in additionalMetadata)
endpointBuilder.Metadata.Add(metadata);

foreach (var convention in _conventions)
{
convention(endpointBuilder);
}

foreach (var finallyConvention in _finallyConventions)
finallyConvention(endpointBuilder);

endpoints.Add(endpointBuilder.Build());
}

private static bool CopyAttributeToEndpointMetadata(Attribute authorizeAttribute)
{
return authorizeAttribute is IAuthorizeData;
}

private static MethodInfo TryGetMethodInfo(OperationInvoker invoker)
{
MethodInfo method = invoker.DomainOperation.DomainServiceType.GetMethod(invoker.DomainOperation.Name);
if (method == null && invoker.DomainOperation.IsTaskAsync)
{
method = invoker.DomainOperation.DomainServiceType.GetMethod(invoker.DomainOperation.Name + "Async");
}

return method;
}

public override IChangeToken GetChangeToken()
{
return NullChangeToken.Singleton;
Expand All @@ -120,5 +163,12 @@ void IEndpointConventionBuilder.Add(Action<EndpointBuilder> convention)
{
_conventions.Add(convention);
}

#if NET7_0_OR_GREATER
void IEndpointConventionBuilder.Finally(System.Action<Microsoft.AspNetCore.Builder.EndpointBuilder> finallyConvention)
{
_finallyConventions.Add(finallyConvention);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected OperationInvoker(DomainOperationEntry operation, DomainOperationType o
}

public virtual string OperationName => _operation.Name;
public DomainOperationEntry DomainOperation => _operation;

public abstract Task Invoke(HttpContext context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ internal sealed class ArrayPoolStream : Stream

public ArrayPoolStream(ArrayPool<byte> arrayPool, int maxBlockSize)
{
if (maxBlockSize < 0)
throw new ArgumentOutOfRangeException(nameof(maxBlockSize), maxBlockSize, "Max size can not have a negative value");

_arrayPool = arrayPool;
_maxSize = maxBlockSize;
}
Expand Down Expand Up @@ -116,7 +119,23 @@ private void EnsureBufferCapacity()
// Ensure we never return buffer twice in case TakeBuffer below throws
_buffer = null;

int nextSize = Math.Min(_position * 2, _maxSize);
int nextSize = _position * 2;
// If the size is >1GB the next size might be larger than int.MaxValue
// which means it will become negative
if (nextSize < 0)
{
if (_position > 0 && _position < int.MaxValue)
{
//This is the space left before we hit max int
nextSize = int.MaxValue - _position;
}
else
{
throw new InsufficientMemoryException();
}
}

nextSize = Math.Min(nextSize, _maxSize);
_buffer = _arrayPool.Rent(nextSize);
_bufferWritten = 0;
}
Expand Down
Loading

0 comments on commit 8a7ee69

Please sign in to comment.