Skip to content

Commit

Permalink
Ad-hoc fixes/updates. (#104)
Browse files Browse the repository at this point in the history
* Rename ResultHandling.Stop to ResultHandling.ThrowException - this is the more meaningful name. The host will then decide on how to handle.

* Fix Issue #102

* Update template solution.
Re-publish Beef.Core - merge challenge.
  • Loading branch information
chullybun committed Feb 9, 2021
1 parent 9f52c2d commit 6b5049f
Show file tree
Hide file tree
Showing 41 changed files with 143 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Defines the internal model (persisted in Cosmos) that inherits the AccountModel which adds the Balance. -->
<CodeGeneration xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<!-- In this example there is almost a one-to-one entity-to-model mapping; however, it is still considered good practice to seperate.
Reference data properties need to be simplified (as string) for Cosmos.
-->
Expand Down
2 changes: 1 addition & 1 deletion samples/Cdr.Banking/Cdr.Banking.CodeGen/Cdr.Banking.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<CodeGeneration RefDataNamespace="Cdr.Banking.Common.Entities" xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration RefDataNamespace="Cdr.Banking.Common.Entities" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">

<!-- Account as per the defined schema, including corresponding collection/result.
API route prefixed defined.
Expand Down
2 changes: 1 addition & 1 deletion samples/Cdr.Banking/Cdr.Banking.CodeGen/Cdr.RefData.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<CodeGeneration RefDataNamespace="Cdr.Banking.Common.Entities" RefDataWebApiRoute="api/v1/ref" xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration RefDataNamespace="Cdr.Banking.Common.Entities" RefDataWebApiRoute="api/v1/ref" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<!-- Each of the requred reference data entities defined.
Use the same Cosmos Container given small volume which helps manage costs.
-->
Expand Down
2 changes: 1 addition & 1 deletion samples/Demo/Beef.Demo.CodeGen/Beef.Demo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<CodeGeneration RefDataNamespace="Beef.Demo.Common.Entities" Grpc="true" ValidatorLayer="Business" MapperDefaultRefDataConverter="ReferenceDataCodeConverter" RefDataText="true" EventPublish="true" AppBasedAgentArgs="true" xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration RefDataNamespace="Beef.Demo.Common.Entities" Grpc="true" ValidatorLayer="Business" MapperDefaultRefDataConverter="ReferenceDataCodeConverter" RefDataText="true" EventPublish="true" AppBasedAgentArgs="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<Entity Name="Person" Text="Person" Implements="IETag, IChangeLog" Collection="true" CollectionResult="true" Grpc="true" Validator="PersonValidator" WebApiAuthorize="false" WebApiRoutePrefix="api/v1/persons" Create="true" Delete="true" AutoImplement="Database" DatabaseSchema="Demo" EntityFrameworkEntity="EfModel.Person" DataCtorParams="Microsoft.Extensions.Logging.ILogger&lt;PersonData&gt;^Logger, Common.Agents.IPersonAgent" ManagerExtensions="true" DataSvcExtensions="true" DataExtensions="true" EventTransaction="true" TestCodeGen="true" TestExtra="Unknown-Config">
<Property Name="Id" Text="{{Person}} identifier" Type="Guid" GrpcFieldNo="1" UniqueKey="true" IdentifierGenerator="IGuidIdentifierGenerator^GuidIdGen" DataName="PersonId" />
<Property Name="FirstName" Type="string" GrpcFieldNo="2" />
Expand Down
2 changes: 1 addition & 1 deletion samples/Demo/Beef.Demo.CodeGen/Beef.RefData.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<CodeGeneration RefDataNamespace="Beef.Demo.Common.Entities" RefDataWebApiRoute="api/v1/demo/ref" MapperDefaultRefDataConverter="ReferenceDataInt32IdConverter" WebApiAuthorize="false" AppBasedAgentArgs="true" xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration RefDataNamespace="Beef.Demo.Common.Entities" RefDataWebApiRoute="api/v1/demo/ref" MapperDefaultRefDataConverter="ReferenceDataInt32IdConverter" WebApiAuthorize="false" AppBasedAgentArgs="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<!-- A Get/Create/Update/Delete are not required unless specific CRUD operations are required. -->
<Entity Name="Country" RefDataType="Guid" Collection="true" WebApiRoutePrefix="api/v1/demo/ref/countries" AutoImplement="Database" DatabaseSchema="Ref" />
<Entity Name="USState" RefDataType="Guid" Collection="true" WebApiRoutePrefix="api/v1/demo/ref/usStates" AutoImplement="Database" DatabaseSchema="Ref" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Beef.Demo.Common.Entities
/// Represents the Product entity.
/// </summary>
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public partial class Product : EntityBase, IIntIdentifier, IUniqueKey, IEquatable<Product>
public partial class Product : EntityBase, IUniqueKey, IEquatable<Product>
{
#region Privates

Expand Down
2 changes: 1 addition & 1 deletion samples/Demo/Beef.Demo.Database/Beef.Demo.Database.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<CodeGeneration CdcSchema="DemoCdc" EventActionFormat="PastTense" xmlns="http://schemas.beef.com/codegen/2015/01/database" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/Avanade/Beef/master/tools/Beef.CodeGen.Core/Schema/codegen.table.xsd">
<CodeGeneration CdcSchema="DemoCdc" EventActionFormat="PastTense" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/Avanade/Beef/master/tools/Beef.CodeGen.Core/Schema/codegen.table.xsd">
<!-- New "Query" configuration. -->
<Query Name="Table" Schema="Test" View="true" ViewName="vwTestQuery" ExcludeColumns="CreatedBy, UpdatedBy" Permission="TestSec">
<QueryJoin Name="Person" Schema="Demo" ExcludeColumns="CreatedDate, UpdatedDate" AliasColumns="RowVersion^RowVersionP">
Expand Down
2 changes: 1 addition & 1 deletion samples/My.Hr/My.Hr.CodeGen/entity.beef.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<CodeGeneration RefDataNamespace="My.Hr.Common.Entities" RefDataText="true" EventSubjectRoot="My" EventActionFormat="PastTense" AppBasedAgentArgs="true" DatabaseSchema="Hr" xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration RefDataNamespace="My.Hr.Common.Entities" RefDataText="true" EventSubjectRoot="My" EventActionFormat="PastTense" AppBasedAgentArgs="true" DatabaseSchema="Hr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<!-- Creating an Employee base with only the subset of fields that we want returned from the GetByArgs.
- As we will be returning more than one we need the Collection and CollectionResult.
- Any Text with a handlebars '{{xxx}}' is a shortcut for .NET see comments; e.g. '<see cref="xxx"/>'.
Expand Down
2 changes: 1 addition & 1 deletion samples/My.Hr/My.Hr.CodeGen/refdata.beef.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<CodeGeneration RefDataNamespace="My.Hr.Common.Entities" RefDataWebApiRoute="api/v1/ref" AppBasedAgentArgs="true" DatabaseSchema="Hr" xmlns="http://schemas.beef.com/codegen/2015/01/entity" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<CodeGeneration RefDataNamespace="My.Hr.Common.Entities" RefDataWebApiRoute="api/v1/ref" AppBasedAgentArgs="true" DatabaseSchema="Hr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.entity.xsd">
<Entity Name="Gender" RefDataType="Guid" Collection="true" WebApiRoutePrefix="api/v1/ref/genders" AutoImplement="EntityFramework" EntityFrameworkEntity="EfModel.Gender" />
<Entity Name="TerminationReason" RefDataType="Guid" Collection="true" WebApiRoutePrefix="api/v1/ref/terminationReasons" AutoImplement="EntityFramework" EntityFrameworkEntity="EfModel.TerminationReason" />
<Entity Name="RelationshipType" RefDataType="Guid" Collection="true" WebApiRoutePrefix="api/v1/ref/relationshipTypes" AutoImplement="EntityFramework" EntityFrameworkEntity="EfModel.RelationshipType" />
Expand Down
2 changes: 1 addition & 1 deletion samples/My.Hr/My.Hr.Database/database.beef.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<CodeGeneration Schema="Hr" RefDatabasexmlns="http://schemas.beef.com/codegen/2015/01/database" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.table.xsd">
<CodeGeneration Schema="Hr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.table.xsd">
<!-- Reference data tables/models. -->
<Table Name="Gender" EfModel="true" />
<Table Name="TerminationReason" EfModel="true" />
Expand Down
2 changes: 1 addition & 1 deletion samples/My.Hr/docs/Employee-DB.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Remove all existing configuration from `My.Hr.Database.xml` and replace. Each ta

``` XML
<?xml version="1.0" encoding="utf-8" ?>
<CodeGeneration DatabaseSchema="Hr" xmlns="http://schemas.beef.com/codegen/2015/01/database" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.table.xsd">
<CodeGeneration DatabaseSchema="Hr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://github.com/Avanade/Beef/raw/master/tools/Beef.CodeGen.Core/Schema/codegen.table.xsd">
<!-- Reference data tables/models. -->
<Table Name="Gender" EfModel="true" />
<Table Name="TerminationReason" EfModel="true" />
Expand Down
2 changes: 1 addition & 1 deletion src/Beef.Core/Beef.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Beef</RootNamespace>
<Version>4.1.4</Version>
<Version>4.1.5</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Beef Developers</Authors>
<Company>Avanade</Company>
Expand Down
3 changes: 3 additions & 0 deletions src/Beef.Core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v4.1.5
- *Republish:* Fixed code merge issues.

## v4.1.4
- *Enhancement:* Issue [97](https://github.com/Avanade/Beef/issues/97).
- *Enhancement:* Issue [98](https://github.com/Avanade/Beef/issues/98).
Expand Down
2 changes: 1 addition & 1 deletion src/Beef.Events/Beef.Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>4.1.3</Version>
<Version>4.1.4</Version>
<Authors>Beef Developers</Authors>
<Company>Avanade</Company>
<Description>Business Entity Execution Framework (Beef) Events framework.</Description>
Expand Down
3 changes: 3 additions & 0 deletions src/Beef.Events/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v4.1.4
- *Fixed:* **Breaking change**. The `ResultHandling.Stop` has been renamed to `ResultHandling.ThrowException` as this is more aligned to what is happening. The corresponding`EventSubscriberStopException` has been renamed `EventSubscriberUnhandledException`.

## v4.1.3
- *Enhancement:* Added support for the new unique `EventData.EventId`.
- *Enhancement:* `EventHubPublisher` updated to reflect `IEventHubPublisher` changes.
Expand Down
36 changes: 28 additions & 8 deletions src/Beef.Events/Subscribe/EventHubSubscriberHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ public class EventHubSubscriberHost : EventSubscriberHost
/// Initializes a new instance of the <see cref="EventHubSubscriberHost"/> with the specified <see cref="EventSubscriberHostArgs"/>.
/// </summary>
/// <param name="args">The optional <see cref="EventHubSubscriberHost"/>.</param>
public EventHubSubscriberHost(EventSubscriberHostArgs args) : base(args)
{
if (args == null)
throw new ArgumentNullException(nameof(args));

if (args.AuditWriter == null)
args.AuditWriter = (result) => throw new EventSubscriberStopException(result);
}
public EventHubSubscriberHost(EventSubscriberHostArgs args) : base(args) { }

/// <summary>
/// Performs the receive processing for an <see cref="EventHubs.EventData"/> instance.
Expand All @@ -44,5 +37,32 @@ public async Task ReceiveAsync(EventHubs.EventData @event)
catch (Exception ex) { throw new InvalidEventDataException(ex); }
}).ConfigureAwait(false);
}

/// <summary>
/// Performs the receive processing for an <see cref="EventHubs.EventData"/> instance.
/// </summary>
/// <param name="events">The <see cref="EventHubs.EventData"/> array to receive/process.</param>
public async Task ReceiveAsync(EventHubs.EventData[] events)
{
if (events == null || events.Length == 0)
return;

if (events.Length != 1 && !Args.AreMultipleMessagesSupported)
throw new EventSubscriberException($"The '{nameof(EventDataSubscriberHost)}' does not AllowMultipleMessages; there were {events.Length} event messages.");

// Convert EventHubs.EventData to Beef.EventData.
foreach (var @event in events)
{
var (_, subject, action, _) = @event.GetBeefMetadata();
await ReceiveAsync(subject, action, (subscriber) =>
{
try
{
return subscriber.ValueType == null ? @event.ToBeefEventData() : @event.ToBeefEventData(subscriber.ValueType);
}
catch (Exception ex) { throw new InvalidEventDataException(ex); }
}).ConfigureAwait(false);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Beef.Events/Subscribe/EventSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public abstract class EventSubscriberBase : IEventSubscriber
public RunAsUser RunAsUser { get; protected set; } = RunAsUser.Originating;

/// <summary>
/// Determines the <see cref="Subscribe.UnhandledExceptionHandling"/> option; defaults to <see cref="UnhandledExceptionHandling.Stop"/>.
/// Determines the <see cref="Subscribe.UnhandledExceptionHandling"/> option; defaults to <see cref="UnhandledExceptionHandling.ThrowException"/>.
/// </summary>
public UnhandledExceptionHandling UnhandledExceptionHandling { get; protected set; } = UnhandledExceptionHandling.Stop;
public UnhandledExceptionHandling UnhandledExceptionHandling { get; protected set; } = UnhandledExceptionHandling.ThrowException;

/// <summary>
/// Gets or sets the <see cref="ResultHandling"/> for a <see cref="Result"/> with a <see cref="SubscriberStatus.InvalidEventData"/> status (overrides <see cref="EventSubscriberHostArgs.InvalidEventDataHandling"/>).
Expand Down
8 changes: 4 additions & 4 deletions src/Beef.Events/Subscribe/EventSubscriberHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected static string GetUsername(IEventSubscriber subscriber, EventData @even
protected async Task<Result> ReceiveAsync(string? subject, string? action, Func<IEventSubscriber, EventData> getEventData)
{
if (Args.AuditWriter == null)
throw new InvalidOperationException("The Args.AuditWriter must be specified; otherwise, ResultHandling.ContinueWithAudit cannot be actioned.");
throw new InvalidOperationException("The Args.AuditWriter must be specified for the ResultHandling.ContinueWithAudit and ResultHandling.ThrowException to function correctly.");

if (getEventData == null)
throw new ArgumentNullException(nameof(getEventData));
Expand Down Expand Up @@ -101,7 +101,7 @@ protected async Task<Result> ReceiveAsync(string? subject, string? action, Func<
catch (ValidationException vex) { return CheckResult(Result.InvalidData(vex), subject, action, subscriber); }
catch (BusinessException bex) { return CheckResult(Result.InvalidData(bex), subject, action, subscriber); }
catch (NotFoundException) { return CheckResult(Result.DataNotFound(), subject, action, subscriber); }
catch (EventSubscriberStopException) { throw; }
catch (EventSubscriberUnhandledException) { throw; }
catch (Exception ex)
{
// Handle the exception as per the subscriber configuration.
Expand Down Expand Up @@ -168,8 +168,8 @@ private void HandleTheHandling(Result result, ResultHandling handling)
Args.AuditWriter?.Invoke(result);
break;

case ResultHandling.Stop:
throw new EventSubscriberStopException(result);
case ResultHandling.ThrowException:
throw new EventSubscriberUnhandledException(result);

case ResultHandling.ContinueSilent:
default:
Expand Down
Loading

0 comments on commit 6b5049f

Please sign in to comment.