diff --git a/src/Http/DeepMiddlewareUsage/DeepMiddlewareUsage.csproj b/src/Http/DeepMiddlewareUsage/DeepMiddlewareUsage.csproj new file mode 100644 index 000000000..5773bd851 --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/DeepMiddlewareUsage.csproj @@ -0,0 +1,19 @@ + + + + net9.0 + enable + enable + + + + + + + + + Servers.cs + + + + diff --git a/src/Http/DeepMiddlewareUsage/DeepMiddlewareUsage.http b/src/Http/DeepMiddlewareUsage/DeepMiddlewareUsage.http new file mode 100644 index 000000000..b442d7cbf --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/DeepMiddlewareUsage.http @@ -0,0 +1,6 @@ +@DeepMiddlewareUsage_HostAddress = http://localhost:5063 + +GET {{DeepMiddlewareUsage_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/src/Http/DeepMiddlewareUsage/Internal/Generated/DocumentStorage/DeadLetterEventProvider1642069326.cs b/src/Http/DeepMiddlewareUsage/Internal/Generated/DocumentStorage/DeadLetterEventProvider1642069326.cs new file mode 100644 index 000000000..8687d107c --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/Internal/Generated/DocumentStorage/DeadLetterEventProvider1642069326.cs @@ -0,0 +1,831 @@ +// +#pragma warning disable +using JasperFx.Events.Daemon; +using Marten.Internal; +using Marten.Internal.Storage; +using Marten.Schema; +using Marten.Schema.Arguments; +using Npgsql; +using System; +using System.Collections.Generic; +using Weasel.Core; +using Weasel.Postgresql; + +namespace Marten.Generated.DocumentStorage +{ + // START: UpsertDeadLetterEventOperation1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class UpsertDeadLetterEventOperation1642069326 : Marten.Internal.Operations.StorageOperation + { + private readonly JasperFx.Events.Daemon.DeadLetterEvent _document; + private readonly System.Guid _id; + private readonly System.Collections.Generic.Dictionary _versions; + private readonly Marten.Schema.DocumentMapping _mapping; + + public UpsertDeadLetterEventOperation1642069326(JasperFx.Events.Daemon.DeadLetterEvent document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) + { + _document = document; + _id = id; + _versions = versions; + _mapping = mapping; + } + + + + public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) + { + storeVersion(); + } + + + public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) + { + storeVersion(); + // Nothing + return System.Threading.Tasks.Task.CompletedTask; + } + + + public override Marten.Internal.Operations.OperationRole Role() + { + return Marten.Internal.Operations.OperationRole.Upsert; + } + + + public override NpgsqlTypes.NpgsqlDbType DbType() + { + return NpgsqlTypes.NpgsqlDbType.Uuid; + } + + + public override void ConfigureParameters(Weasel.Postgresql.IGroupedParameterBuilder parameterBuilder, Weasel.Postgresql.ICommandBuilder builder, JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session) + { + builder.Append("select trainers.mt_upsert_deadletterevent("); + var parameter0 = parameterBuilder.AppendParameter(session.Serializer.ToJson(_document)); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; + // .Net Class Type + var parameter1 = parameterBuilder.AppendParameter(_document.GetType().FullName); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; + var parameter2 = parameterBuilder.AppendParameter((document is JasperFx.Events.Daemon.DeadLetterEvent ? ((JasperFx.Events.Daemon.DeadLetterEvent)document).Id : default(System.Guid))); + setVersionParameter(parameterBuilder); + builder.Append(')'); + } + + } + + // END: UpsertDeadLetterEventOperation1642069326 + + + // START: InsertDeadLetterEventOperation1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class InsertDeadLetterEventOperation1642069326 : Marten.Internal.Operations.StorageOperation + { + private readonly JasperFx.Events.Daemon.DeadLetterEvent _document; + private readonly System.Guid _id; + private readonly System.Collections.Generic.Dictionary _versions; + private readonly Marten.Schema.DocumentMapping _mapping; + + public InsertDeadLetterEventOperation1642069326(JasperFx.Events.Daemon.DeadLetterEvent document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) + { + _document = document; + _id = id; + _versions = versions; + _mapping = mapping; + } + + + + public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) + { + storeVersion(); + } + + + public override System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) + { + storeVersion(); + // Nothing + return System.Threading.Tasks.Task.CompletedTask; + } + + + public override Marten.Internal.Operations.OperationRole Role() + { + return Marten.Internal.Operations.OperationRole.Insert; + } + + + public override NpgsqlTypes.NpgsqlDbType DbType() + { + return NpgsqlTypes.NpgsqlDbType.Uuid; + } + + + public override void ConfigureParameters(Weasel.Postgresql.IGroupedParameterBuilder parameterBuilder, Weasel.Postgresql.ICommandBuilder builder, JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session) + { + builder.Append("select trainers.mt_insert_deadletterevent("); + var parameter0 = parameterBuilder.AppendParameter(session.Serializer.ToJson(_document)); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; + // .Net Class Type + var parameter1 = parameterBuilder.AppendParameter(_document.GetType().FullName); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; + var parameter2 = parameterBuilder.AppendParameter((document is JasperFx.Events.Daemon.DeadLetterEvent ? ((JasperFx.Events.Daemon.DeadLetterEvent)document).Id : default(System.Guid))); + setVersionParameter(parameterBuilder); + builder.Append(')'); + } + + } + + // END: InsertDeadLetterEventOperation1642069326 + + + // START: UpdateDeadLetterEventOperation1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class UpdateDeadLetterEventOperation1642069326 : Marten.Internal.Operations.StorageOperation + { + private readonly JasperFx.Events.Daemon.DeadLetterEvent _document; + private readonly System.Guid _id; + private readonly System.Collections.Generic.Dictionary _versions; + private readonly Marten.Schema.DocumentMapping _mapping; + + public UpdateDeadLetterEventOperation1642069326(JasperFx.Events.Daemon.DeadLetterEvent document, System.Guid id, System.Collections.Generic.Dictionary versions, Marten.Schema.DocumentMapping mapping) : base(document, id, versions, mapping) + { + _document = document; + _id = id; + _versions = versions; + _mapping = mapping; + } + + + + public override void Postprocess(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions) + { + storeVersion(); + postprocessUpdate(reader, exceptions); + } + + + public override async System.Threading.Tasks.Task PostprocessAsync(System.Data.Common.DbDataReader reader, System.Collections.Generic.IList exceptions, System.Threading.CancellationToken token) + { + storeVersion(); + await postprocessUpdateAsync(reader, exceptions, token); + } + + + public override Marten.Internal.Operations.OperationRole Role() + { + return Marten.Internal.Operations.OperationRole.Update; + } + + + public override NpgsqlTypes.NpgsqlDbType DbType() + { + return NpgsqlTypes.NpgsqlDbType.Uuid; + } + + + public override void ConfigureParameters(Weasel.Postgresql.IGroupedParameterBuilder parameterBuilder, Weasel.Postgresql.ICommandBuilder builder, JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session) + { + builder.Append("select trainers.mt_update_deadletterevent("); + var parameter0 = parameterBuilder.AppendParameter(session.Serializer.ToJson(_document)); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; + // .Net Class Type + var parameter1 = parameterBuilder.AppendParameter(_document.GetType().FullName); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Varchar; + var parameter2 = parameterBuilder.AppendParameter((document is JasperFx.Events.Daemon.DeadLetterEvent ? ((JasperFx.Events.Daemon.DeadLetterEvent)document).Id : default(System.Guid))); + setVersionParameter(parameterBuilder); + builder.Append(')'); + } + + } + + // END: UpdateDeadLetterEventOperation1642069326 + + + // START: QueryOnlyDeadLetterEventSelector1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class QueryOnlyDeadLetterEventSelector1642069326 : Marten.Internal.CodeGeneration.DocumentSelectorWithOnlySerializer, Marten.Linq.Selectors.ISelector + { + private readonly Marten.Internal.IMartenSession _session; + private readonly Marten.Schema.DocumentMapping _mapping; + + public QueryOnlyDeadLetterEventSelector1642069326(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) + { + _session = session; + _mapping = mapping; + } + + + + public JasperFx.Events.Daemon.DeadLetterEvent Resolve(System.Data.Common.DbDataReader reader) + { + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = _serializer.FromJson(reader, 0); + return document; + } + + + public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) + { + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = await _serializer.FromJsonAsync(reader, 0, token).ConfigureAwait(false); + return document; + } + + } + + // END: QueryOnlyDeadLetterEventSelector1642069326 + + + // START: LightweightDeadLetterEventSelector1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class LightweightDeadLetterEventSelector1642069326 : Marten.Internal.CodeGeneration.DocumentSelectorWithVersions, Marten.Linq.Selectors.ISelector + { + private readonly Marten.Internal.IMartenSession _session; + private readonly Marten.Schema.DocumentMapping _mapping; + + public LightweightDeadLetterEventSelector1642069326(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) + { + _session = session; + _mapping = mapping; + } + + + + public JasperFx.Events.Daemon.DeadLetterEvent Resolve(System.Data.Common.DbDataReader reader) + { + var id = reader.GetFieldValue(0); + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = _serializer.FromJson(reader, 1); + _session.MarkAsDocumentLoaded(id, document); + return document; + } + + + public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) + { + var id = await reader.GetFieldValueAsync(0, token); + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); + _session.MarkAsDocumentLoaded(id, document); + return document; + } + + } + + // END: LightweightDeadLetterEventSelector1642069326 + + + // START: IdentityMapDeadLetterEventSelector1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class IdentityMapDeadLetterEventSelector1642069326 : Marten.Internal.CodeGeneration.DocumentSelectorWithIdentityMap, Marten.Linq.Selectors.ISelector + { + private readonly Marten.Internal.IMartenSession _session; + private readonly Marten.Schema.DocumentMapping _mapping; + + public IdentityMapDeadLetterEventSelector1642069326(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) + { + _session = session; + _mapping = mapping; + } + + + + public JasperFx.Events.Daemon.DeadLetterEvent Resolve(System.Data.Common.DbDataReader reader) + { + var id = reader.GetFieldValue(0); + if (_identityMap.TryGetValue(id, out var existing)) return existing; + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = _serializer.FromJson(reader, 1); + _session.MarkAsDocumentLoaded(id, document); + _identityMap[id] = document; + return document; + } + + + public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) + { + var id = await reader.GetFieldValueAsync(0, token); + if (_identityMap.TryGetValue(id, out var existing)) return existing; + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); + _session.MarkAsDocumentLoaded(id, document); + _identityMap[id] = document; + return document; + } + + } + + // END: IdentityMapDeadLetterEventSelector1642069326 + + + // START: DirtyTrackingDeadLetterEventSelector1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class DirtyTrackingDeadLetterEventSelector1642069326 : Marten.Internal.CodeGeneration.DocumentSelectorWithDirtyChecking, Marten.Linq.Selectors.ISelector + { + private readonly Marten.Internal.IMartenSession _session; + private readonly Marten.Schema.DocumentMapping _mapping; + + public DirtyTrackingDeadLetterEventSelector1642069326(Marten.Internal.IMartenSession session, Marten.Schema.DocumentMapping mapping) : base(session, mapping) + { + _session = session; + _mapping = mapping; + } + + + + public JasperFx.Events.Daemon.DeadLetterEvent Resolve(System.Data.Common.DbDataReader reader) + { + var id = reader.GetFieldValue(0); + if (_identityMap.TryGetValue(id, out var existing)) return existing; + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = _serializer.FromJson(reader, 1); + _session.MarkAsDocumentLoaded(id, document); + _identityMap[id] = document; + StoreTracker(_session, document); + return document; + } + + + public async System.Threading.Tasks.Task ResolveAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) + { + var id = await reader.GetFieldValueAsync(0, token); + if (_identityMap.TryGetValue(id, out var existing)) return existing; + + JasperFx.Events.Daemon.DeadLetterEvent document; + document = await _serializer.FromJsonAsync(reader, 1, token).ConfigureAwait(false); + _session.MarkAsDocumentLoaded(id, document); + _identityMap[id] = document; + StoreTracker(_session, document); + return document; + } + + } + + // END: DirtyTrackingDeadLetterEventSelector1642069326 + + + // START: QueryOnlyDeadLetterEventDocumentStorage1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class QueryOnlyDeadLetterEventDocumentStorage1642069326 : Marten.Internal.Storage.QueryOnlyDocumentStorage + { + private readonly Marten.Schema.DocumentMapping _document; + + public QueryOnlyDeadLetterEventDocumentStorage1642069326(Marten.Schema.DocumentMapping document) : base(document) + { + _document = document; + } + + + + public override System.Guid AssignIdentity(JasperFx.Events.Daemon.DeadLetterEvent document, string tenantId, Marten.Storage.IMartenDatabase database) + { + if (document.Id == Guid.Empty) _setter(document, JasperFx.Core.CombGuidIdGeneration.NewGuid()); + return document.Id; + } + + + public override Marten.Internal.Operations.IStorageOperation Update(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpdateDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Insert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.InsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Upsert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Overwrite(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + throw new System.NotSupportedException(); + } + + + public override System.Guid Identity(JasperFx.Events.Daemon.DeadLetterEvent document) + { + return document.Id; + } + + + public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) + { + return new Marten.Generated.DocumentStorage.QueryOnlyDeadLetterEventSelector1642069326(session, _document); + } + + + public override object RawIdentityValue(System.Guid id) + { + return id; + } + + + public override Npgsql.NpgsqlParameter BuildManyIdParameter(System.Guid[] ids) + { + return base.BuildManyIdParameter(ids); + } + + } + + // END: QueryOnlyDeadLetterEventDocumentStorage1642069326 + + + // START: LightweightDeadLetterEventDocumentStorage1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class LightweightDeadLetterEventDocumentStorage1642069326 : Marten.Internal.Storage.LightweightDocumentStorage + { + private readonly Marten.Schema.DocumentMapping _document; + + public LightweightDeadLetterEventDocumentStorage1642069326(Marten.Schema.DocumentMapping document) : base(document) + { + _document = document; + } + + + + public override System.Guid AssignIdentity(JasperFx.Events.Daemon.DeadLetterEvent document, string tenantId, Marten.Storage.IMartenDatabase database) + { + if (document.Id == Guid.Empty) _setter(document, JasperFx.Core.CombGuidIdGeneration.NewGuid()); + return document.Id; + } + + + public override Marten.Internal.Operations.IStorageOperation Update(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpdateDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Insert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.InsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Upsert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Overwrite(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + throw new System.NotSupportedException(); + } + + + public override System.Guid Identity(JasperFx.Events.Daemon.DeadLetterEvent document) + { + return document.Id; + } + + + public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) + { + return new Marten.Generated.DocumentStorage.LightweightDeadLetterEventSelector1642069326(session, _document); + } + + + public override object RawIdentityValue(System.Guid id) + { + return id; + } + + + public override Npgsql.NpgsqlParameter BuildManyIdParameter(System.Guid[] ids) + { + return base.BuildManyIdParameter(ids); + } + + } + + // END: LightweightDeadLetterEventDocumentStorage1642069326 + + + // START: IdentityMapDeadLetterEventDocumentStorage1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class IdentityMapDeadLetterEventDocumentStorage1642069326 : Marten.Internal.Storage.IdentityMapDocumentStorage + { + private readonly Marten.Schema.DocumentMapping _document; + + public IdentityMapDeadLetterEventDocumentStorage1642069326(Marten.Schema.DocumentMapping document) : base(document) + { + _document = document; + } + + + + public override System.Guid AssignIdentity(JasperFx.Events.Daemon.DeadLetterEvent document, string tenantId, Marten.Storage.IMartenDatabase database) + { + if (document.Id == Guid.Empty) _setter(document, JasperFx.Core.CombGuidIdGeneration.NewGuid()); + return document.Id; + } + + + public override Marten.Internal.Operations.IStorageOperation Update(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpdateDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Insert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.InsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Upsert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Overwrite(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + throw new System.NotSupportedException(); + } + + + public override System.Guid Identity(JasperFx.Events.Daemon.DeadLetterEvent document) + { + return document.Id; + } + + + public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) + { + return new Marten.Generated.DocumentStorage.IdentityMapDeadLetterEventSelector1642069326(session, _document); + } + + + public override object RawIdentityValue(System.Guid id) + { + return id; + } + + + public override Npgsql.NpgsqlParameter BuildManyIdParameter(System.Guid[] ids) + { + return base.BuildManyIdParameter(ids); + } + + } + + // END: IdentityMapDeadLetterEventDocumentStorage1642069326 + + + // START: DirtyTrackingDeadLetterEventDocumentStorage1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class DirtyTrackingDeadLetterEventDocumentStorage1642069326 : Marten.Internal.Storage.DirtyCheckedDocumentStorage + { + private readonly Marten.Schema.DocumentMapping _document; + + public DirtyTrackingDeadLetterEventDocumentStorage1642069326(Marten.Schema.DocumentMapping document) : base(document) + { + _document = document; + } + + + + public override System.Guid AssignIdentity(JasperFx.Events.Daemon.DeadLetterEvent document, string tenantId, Marten.Storage.IMartenDatabase database) + { + if (document.Id == Guid.Empty) _setter(document, JasperFx.Core.CombGuidIdGeneration.NewGuid()); + return document.Id; + } + + + public override Marten.Internal.Operations.IStorageOperation Update(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpdateDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Insert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.InsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Upsert(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + + return new Marten.Generated.DocumentStorage.UpsertDeadLetterEventOperation1642069326 + ( + document, Identity(document), + session.Versions.ForType(), + _document + + ); + } + + + public override Marten.Internal.Operations.IStorageOperation Overwrite(JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Internal.IMartenSession session, string tenant) + { + throw new System.NotSupportedException(); + } + + + public override System.Guid Identity(JasperFx.Events.Daemon.DeadLetterEvent document) + { + return document.Id; + } + + + public override Marten.Linq.Selectors.ISelector BuildSelector(Marten.Internal.IMartenSession session) + { + return new Marten.Generated.DocumentStorage.DirtyTrackingDeadLetterEventSelector1642069326(session, _document); + } + + + public override object RawIdentityValue(System.Guid id) + { + return id; + } + + + public override Npgsql.NpgsqlParameter BuildManyIdParameter(System.Guid[] ids) + { + return base.BuildManyIdParameter(ids); + } + + } + + // END: DirtyTrackingDeadLetterEventDocumentStorage1642069326 + + + // START: DeadLetterEventBulkLoader1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class DeadLetterEventBulkLoader1642069326 : Marten.Internal.CodeGeneration.BulkLoader + { + private readonly Marten.Internal.Storage.IDocumentStorage _storage; + + public DeadLetterEventBulkLoader1642069326(Marten.Internal.Storage.IDocumentStorage storage) : base(storage) + { + _storage = storage; + } + + + public const string MAIN_LOADER_SQL = "COPY trainers.mt_doc_deadletterevent(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; + + public const string TEMP_LOADER_SQL = "COPY mt_doc_deadletterevent_temp(\"mt_dotnet_type\", \"id\", \"mt_version\", \"data\") FROM STDIN BINARY"; + + public const string COPY_NEW_DOCUMENTS_SQL = "insert into trainers.mt_doc_deadletterevent (\"id\", \"data\", \"mt_version\", \"mt_dotnet_type\", mt_last_modified) (select mt_doc_deadletterevent_temp.\"id\", mt_doc_deadletterevent_temp.\"data\", mt_doc_deadletterevent_temp.\"mt_version\", mt_doc_deadletterevent_temp.\"mt_dotnet_type\", transaction_timestamp() from mt_doc_deadletterevent_temp left join trainers.mt_doc_deadletterevent on mt_doc_deadletterevent_temp.id = trainers.mt_doc_deadletterevent.id where trainers.mt_doc_deadletterevent.id is null)"; + + public const string OVERWRITE_SQL = "update trainers.mt_doc_deadletterevent target SET data = source.data, mt_version = source.mt_version, mt_dotnet_type = source.mt_dotnet_type, mt_last_modified = transaction_timestamp() FROM mt_doc_deadletterevent_temp source WHERE source.id = target.id"; + + public const string CREATE_TEMP_TABLE_FOR_COPYING_SQL = "create temporary table mt_doc_deadletterevent_temp (like trainers.mt_doc_deadletterevent including defaults)"; + + + public override string CreateTempTableForCopying() + { + return CREATE_TEMP_TABLE_FOR_COPYING_SQL; + } + + + public override string CopyNewDocumentsFromTempTable() + { + return COPY_NEW_DOCUMENTS_SQL; + } + + + public override string OverwriteDuplicatesFromTempTable() + { + return OVERWRITE_SQL; + } + + + public override async System.Threading.Tasks.Task LoadRowAsync(Npgsql.NpgsqlBinaryImporter writer, JasperFx.Events.Daemon.DeadLetterEvent document, Marten.Storage.Tenant tenant, Marten.ISerializer serializer, System.Threading.CancellationToken cancellation) + { + await writer.WriteAsync(document.GetType().FullName, NpgsqlTypes.NpgsqlDbType.Varchar, cancellation); + await writer.WriteAsync(((JasperFx.Events.Daemon.DeadLetterEvent)document).Id, NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); + await writer.WriteAsync(JasperFx.Core.CombGuidIdGeneration.NewGuid(), NpgsqlTypes.NpgsqlDbType.Uuid, cancellation); + await writer.WriteAsync(serializer.ToJson(document), NpgsqlTypes.NpgsqlDbType.Jsonb, cancellation); + } + + + public override string MainLoaderSql() + { + return MAIN_LOADER_SQL; + } + + + public override string TempLoaderSql() + { + return TEMP_LOADER_SQL; + } + + } + + // END: DeadLetterEventBulkLoader1642069326 + + + // START: DeadLetterEventProvider1642069326 + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class DeadLetterEventProvider1642069326 : Marten.Internal.Storage.DocumentProvider + { + private readonly Marten.Schema.DocumentMapping _mapping; + + public DeadLetterEventProvider1642069326(Marten.Schema.DocumentMapping mapping) : base(new DeadLetterEventBulkLoader1642069326(new QueryOnlyDeadLetterEventDocumentStorage1642069326(mapping)), new QueryOnlyDeadLetterEventDocumentStorage1642069326(mapping), new LightweightDeadLetterEventDocumentStorage1642069326(mapping), new IdentityMapDeadLetterEventDocumentStorage1642069326(mapping), new DirtyTrackingDeadLetterEventDocumentStorage1642069326(mapping)) + { + _mapping = mapping; + } + + + } + + // END: DeadLetterEventProvider1642069326 + + +} + diff --git a/src/Http/DeepMiddlewareUsage/Internal/Generated/EventStore/EventStorage.cs b/src/Http/DeepMiddlewareUsage/Internal/Generated/EventStore/EventStorage.cs new file mode 100644 index 000000000..7c21ecfaf --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/Internal/Generated/EventStore/EventStorage.cs @@ -0,0 +1,375 @@ +// +#pragma warning disable +using JasperFx.Events; +using Marten; +using System; + +namespace Marten.Generated.EventStore +{ + // START: GeneratedEventDocumentStorage + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class GeneratedEventDocumentStorage : Marten.Events.EventDocumentStorage + { + private readonly Marten.StoreOptions _options; + + public GeneratedEventDocumentStorage(Marten.StoreOptions options) : base(options) + { + _options = options; + } + + + + public override Marten.Internal.Operations.IStorageOperation AppendEvent(Marten.Events.EventGraph events, Marten.Internal.IMartenSession session, JasperFx.Events.StreamAction stream, JasperFx.Events.IEvent e) + { + return new Marten.Generated.EventStore.AppendEventOperation(stream, e); + } + + + public override Marten.Internal.Operations.IStorageOperation InsertStream(JasperFx.Events.StreamAction stream) + { + return new Marten.Generated.EventStore.GeneratedInsertStream(stream); + } + + + public override Marten.Linq.QueryHandlers.IQueryHandler QueryForStream(JasperFx.Events.StreamAction stream) + { + return new Marten.Generated.EventStore.GeneratedStreamStateQueryHandler(stream.Id); + } + + + public override Marten.Internal.Operations.IStorageOperation UpdateStreamVersion(JasperFx.Events.StreamAction stream) + { + return new Marten.Generated.EventStore.GeneratedStreamVersionOperation(stream); + } + + + public override void ApplyReaderDataToEvent(System.Data.Common.DbDataReader reader, JasperFx.Events.IEvent e) + { + if (!reader.IsDBNull(3)) + { + var sequence = reader.GetFieldValue(3); + e.Sequence = sequence; + } + if (!reader.IsDBNull(4)) + { + var id = reader.GetFieldValue(4); + e.Id = id; + } + var streamId = reader.GetFieldValue(5); + e.StreamId = streamId; + if (!reader.IsDBNull(6)) + { + var version = reader.GetFieldValue(6); + e.Version = version; + } + if (!reader.IsDBNull(7)) + { + var timestamp = reader.GetFieldValue(7); + e.Timestamp = timestamp; + } + if (!reader.IsDBNull(8)) + { + var tenantId = reader.GetFieldValue(8); + e.TenantId = tenantId; + } + var isArchived = reader.GetFieldValue(9); + e.IsArchived = isArchived; + } + + + public override async System.Threading.Tasks.Task ApplyReaderDataToEventAsync(System.Data.Common.DbDataReader reader, JasperFx.Events.IEvent e, System.Threading.CancellationToken token) + { + if (!(await reader.IsDBNullAsync(3, token).ConfigureAwait(false))) + { + var sequence = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); + e.Sequence = sequence; + } + if (!(await reader.IsDBNullAsync(4, token).ConfigureAwait(false))) + { + var id = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); + e.Id = id; + } + var streamId = await reader.GetFieldValueAsync(5, token).ConfigureAwait(false); + e.StreamId = streamId; + if (!(await reader.IsDBNullAsync(6, token).ConfigureAwait(false))) + { + var version = await reader.GetFieldValueAsync(6, token).ConfigureAwait(false); + e.Version = version; + } + if (!(await reader.IsDBNullAsync(7, token).ConfigureAwait(false))) + { + var timestamp = await reader.GetFieldValueAsync(7, token).ConfigureAwait(false); + e.Timestamp = timestamp; + } + if (!(await reader.IsDBNullAsync(8, token).ConfigureAwait(false))) + { + var tenantId = await reader.GetFieldValueAsync(8, token).ConfigureAwait(false); + e.TenantId = tenantId; + } + var isArchived = await reader.GetFieldValueAsync(9, token).ConfigureAwait(false); + e.IsArchived = isArchived; + } + + + public override Marten.Internal.Operations.IStorageOperation QuickAppendEventWithVersion(JasperFx.Events.StreamAction stream, JasperFx.Events.IEvent e) + { + return new Marten.Generated.EventStore.AppendEventOperationQuickWithVersion(stream, e); + } + + + public override Marten.Internal.Operations.IStorageOperation QuickAppendEvents(JasperFx.Events.StreamAction stream) + { + return new Marten.Generated.EventStore.QuickAppendEventsOperation(stream); + } + + } + + // END: GeneratedEventDocumentStorage + + + // START: AppendEventOperation + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class AppendEventOperation : Marten.Events.Operations.AppendEventOperationBase + { + private readonly JasperFx.Events.StreamAction _stream; + private readonly JasperFx.Events.IEvent _e; + + public AppendEventOperation(JasperFx.Events.StreamAction stream, JasperFx.Events.IEvent e) : base(stream, e) + { + _stream = stream; + _e = e; + } + + + + public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session) + { + builder.Append("insert into trainers.mt_events (data, type, mt_dotnet_type, id, stream_id, version, timestamp, tenant_id, seq_id) values ("); + var parameterBuilder = builder.CreateGroupedParameterBuilder(','); + var parameter0 = parameterBuilder.AppendParameter(session.Serializer.ToJson(Event.Data)); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; + var parameter1 = Event.EventTypeName != null ? parameterBuilder.AppendParameter(Event.EventTypeName) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + var parameter2 = Event.DotNetTypeName != null ? parameterBuilder.AppendParameter(Event.DotNetTypeName) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter2.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + var parameter3 = parameterBuilder.AppendParameter(Event.Id); + parameter3.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; + var parameter4 = parameterBuilder.AppendParameter(Stream.Id); + parameter4.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; + var parameter5 = parameterBuilder.AppendParameter(Event.Version); + parameter5.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; + var parameter6 = parameterBuilder.AppendParameter(Event.Timestamp); + parameter6.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.TimestampTz; + var parameter7 = Stream.TenantId != null ? parameterBuilder.AppendParameter(Stream.TenantId) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter7.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + var parameter8 = parameterBuilder.AppendParameter(Event.Sequence); + parameter8.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; + builder.Append(')'); + } + + } + + // END: AppendEventOperation + + + // START: AppendEventOperationQuickWithVersion + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class AppendEventOperationQuickWithVersion : Marten.Events.Operations.AppendEventOperationBase + { + private readonly JasperFx.Events.StreamAction _stream; + private readonly JasperFx.Events.IEvent _e; + + public AppendEventOperationQuickWithVersion(JasperFx.Events.StreamAction stream, JasperFx.Events.IEvent e) : base(stream, e) + { + _stream = stream; + _e = e; + } + + + + public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session) + { + builder.Append("insert into trainers.mt_events (data, type, mt_dotnet_type, id, stream_id, version, timestamp, tenant_id, seq_id) values ("); + var parameterBuilder = builder.CreateGroupedParameterBuilder(','); + var parameter0 = parameterBuilder.AppendParameter(session.Serializer.ToJson(Event.Data)); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb; + var parameter1 = Event.EventTypeName != null ? parameterBuilder.AppendParameter(Event.EventTypeName) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + var parameter2 = Event.DotNetTypeName != null ? parameterBuilder.AppendParameter(Event.DotNetTypeName) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter2.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + var parameter3 = parameterBuilder.AppendParameter(Event.Id); + parameter3.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; + var parameter4 = parameterBuilder.AppendParameter(Stream.Id); + parameter4.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; + var parameter5 = parameterBuilder.AppendParameter(Event.Version); + parameter5.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; + var parameter6 = parameterBuilder.AppendParameter(Event.Timestamp); + parameter6.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.TimestampTz; + var parameter7 = Stream.TenantId != null ? parameterBuilder.AppendParameter(Stream.TenantId) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter7.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + builder.Append(",nextval('trainers.mt_events_sequence')"); + builder.Append(')'); + } + + } + + // END: AppendEventOperationQuickWithVersion + + + // START: QuickAppendEventsOperation + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class QuickAppendEventsOperation : Marten.Events.Operations.QuickAppendEventsOperationBase + { + private readonly JasperFx.Events.StreamAction _stream; + + public QuickAppendEventsOperation(JasperFx.Events.StreamAction stream) : base(stream) + { + _stream = stream; + } + + + + public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session) + { + builder.Append("select trainers.mt_quick_append_events("); + var parameterBuilder = builder.CreateGroupedParameterBuilder(','); + writeId(parameterBuilder); + writeBasicParameters(parameterBuilder, session); + builder.Append(')'); + } + + } + + // END: QuickAppendEventsOperation + + + // START: GeneratedInsertStream + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class GeneratedInsertStream : Marten.Events.Operations.InsertStreamBase + { + private readonly JasperFx.Events.StreamAction _stream; + + public GeneratedInsertStream(JasperFx.Events.StreamAction stream) : base(stream) + { + _stream = stream; + } + + + + public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session) + { + builder.Append("insert into trainers.mt_streams (id, type, version, tenant_id) values ("); + var parameterBuilder = builder.CreateGroupedParameterBuilder(','); + var parameter0 = parameterBuilder.AppendParameter(Stream.Id); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; + var parameter1 = Stream.AggregateTypeName != null ? parameterBuilder.AppendParameter(Stream.AggregateTypeName) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + var parameter2 = parameterBuilder.AppendParameter(Stream.Version); + parameter2.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; + var parameter3 = Stream.TenantId != null ? parameterBuilder.AppendParameter(Stream.TenantId) : parameterBuilder.AppendParameter(System.DBNull.Value); + parameter3.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text; + builder.Append(')'); + } + + } + + // END: GeneratedInsertStream + + + // START: GeneratedStreamStateQueryHandler + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class GeneratedStreamStateQueryHandler : Marten.Events.Querying.StreamStateQueryHandler + { + private readonly System.Guid _streamId; + + public GeneratedStreamStateQueryHandler(System.Guid streamId) + { + _streamId = streamId; + } + + + + public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session) + { + builder.Append("select id, version, type, timestamp, created as timestamp, is_archived from trainers.mt_streams where id = "); + var parameter1 = builder.AppendParameter(_streamId); + parameter1.DbType = System.Data.DbType.Guid; + } + + + public override Marten.Events.StreamState Resolve(Marten.Internal.IMartenSession session, System.Data.Common.DbDataReader reader) + { + var streamState = new Marten.Events.StreamState(); + var id = reader.GetFieldValue(0); + streamState.Id = id; + var version = reader.GetFieldValue(1); + streamState.Version = version; + SetAggregateType(streamState, reader, session); + var lastTimestamp = reader.GetFieldValue(3); + streamState.LastTimestamp = lastTimestamp; + var created = reader.GetFieldValue(4); + streamState.Created = created; + var isArchived = reader.GetFieldValue(5); + streamState.IsArchived = isArchived; + return streamState; + } + + + public override async System.Threading.Tasks.Task ResolveAsync(Marten.Internal.IMartenSession session, System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token) + { + var streamState = new Marten.Events.StreamState(); + var id = await reader.GetFieldValueAsync(0, token).ConfigureAwait(false); + streamState.Id = id; + var version = await reader.GetFieldValueAsync(1, token).ConfigureAwait(false); + streamState.Version = version; + await SetAggregateTypeAsync(streamState, reader, session, token).ConfigureAwait(false); + var lastTimestamp = await reader.GetFieldValueAsync(3, token).ConfigureAwait(false); + streamState.LastTimestamp = lastTimestamp; + var created = await reader.GetFieldValueAsync(4, token).ConfigureAwait(false); + streamState.Created = created; + var isArchived = await reader.GetFieldValueAsync(5, token).ConfigureAwait(false); + streamState.IsArchived = isArchived; + return streamState; + } + + } + + // END: GeneratedStreamStateQueryHandler + + + // START: GeneratedStreamVersionOperation + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class GeneratedStreamVersionOperation : Marten.Events.Operations.UpdateStreamVersion + { + private readonly JasperFx.Events.StreamAction _stream; + + public GeneratedStreamVersionOperation(JasperFx.Events.StreamAction stream) : base(stream) + { + _stream = stream; + } + + + + public override void ConfigureCommand(Weasel.Postgresql.ICommandBuilder builder, Marten.Internal.IMartenSession session) + { + builder.Append("update trainers.mt_streams "); + var parameterBuilder = builder.CreateGroupedParameterBuilder(); + builder.Append("set version = "); + var parameter0 = parameterBuilder.AppendParameter(Stream.Version); + parameter0.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; + builder.Append(" where id = "); + var parameter1 = parameterBuilder.AppendParameter(Stream.Id); + parameter1.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid; + builder.Append(" and version = "); + var parameter2 = parameterBuilder.AppendParameter(Stream.ExpectedVersionOnServer); + parameter2.NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint; + builder.Append(" returning version"); + } + + } + + // END: GeneratedStreamVersionOperation + + +} + diff --git a/src/Http/DeepMiddlewareUsage/Internal/Generated/WolverineHandlers/GET_api_trainer.cs b/src/Http/DeepMiddlewareUsage/Internal/Generated/WolverineHandlers/GET_api_trainer.cs new file mode 100644 index 000000000..daebca86d --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/Internal/Generated/WolverineHandlers/GET_api_trainer.cs @@ -0,0 +1,66 @@ +// +#pragma warning disable +using Microsoft.AspNetCore.Routing; +using System; +using System.Linq; +using Wolverine.Http; +using Wolverine.Marten.Publishing; +using Wolverine.Runtime; + +namespace Internal.Generated.WolverineHandlers +{ + // START: GET_api_trainer + [global::System.CodeDom.Compiler.GeneratedCode("JasperFx", "1.0.0")] + public sealed class GET_api_trainer : Wolverine.Http.HttpHandler + { + private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions; + private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory; + private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime; + + public GET_api_trainer(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(wolverineHttpOptions) + { + _wolverineHttpOptions = wolverineHttpOptions; + _outboxedSessionFactory = outboxedSessionFactory; + _wolverineRuntime = wolverineRuntime; + } + + + + public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext) + { + var messageContext = new Wolverine.Runtime.MessageContext(_wolverineRuntime); + // Building the Marten session + await using var documentSession = _outboxedSessionFactory.OpenSession(messageContext); + (var userId, var problemDetails1) = DeepMiddlewareUsage.UserIdMiddleWare.Load(httpContext.User, httpContext); + // Evaluate whether the processing should stop if there are any problems + if (!(ReferenceEquals(problemDetails1, Wolverine.Http.WolverineContinue.NoProblems))) + { + await WriteProblems(problemDetails1, httpContext).ConfigureAwait(false); + return; + } + + + (var trainer, var problemDetails2) = await DeepMiddlewareUsage.TrainerMiddleware.LoadAsync(userId, documentSession, httpContext.RequestAborted, httpContext).ConfigureAwait(false); + // Evaluate whether the processing should stop if there are any problems + if (!(ReferenceEquals(problemDetails2, Wolverine.Http.WolverineContinue.NoProblems))) + { + await WriteProblems(problemDetails2, httpContext).ConfigureAwait(false); + return; + } + + + + // The actual HTTP request handler execution + var trainerResponse_response = DeepMiddlewareUsage.TrainerGet.Get(trainer); + + // Writing the response body to JSON because this was the first 'return variable' in the method signature + await WriteJsonAsync(httpContext, trainerResponse_response); + } + + } + + // END: GET_api_trainer + + +} + diff --git a/src/Http/DeepMiddlewareUsage/Program.cs b/src/Http/DeepMiddlewareUsage/Program.cs new file mode 100644 index 000000000..306df38cc --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/Program.cs @@ -0,0 +1,40 @@ +using DeepMiddlewareUsage; +using IntegrationTests; +using JasperFx; +using Marten; +using Wolverine; +using Wolverine.Http; +using Wolverine.Marten; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddMarten(options => + { + options.Connection(Servers.PostgresConnectionString); + options.DatabaseSchemaName = "trainers"; + }) + .IntegrateWithWolverine(); + +builder.Host.ApplyJasperFxExtensions(); + +builder.Host.UseWolverine(options => +{ + // Setting up the outbox on all locally handled + // background tasks + options.Policies.AutoApplyTransactions(); + options.Policies.UseDurableLocalQueues(); + options.Policies.UseDurableOutboxOnAllSendingEndpoints(); +}); + +builder.Services.AddWolverineHttp(); + +WebApplication app = builder.Build(); + +app.MapWolverineEndpoints(options => +{ + options.AddMiddleware(typeof(UserIdMiddleWare)); + options.AddPolicy(); + options.ConfigureEndpoints(e => { }); +}); + +return await app.RunJasperFxCommands(args); \ No newline at end of file diff --git a/src/Http/DeepMiddlewareUsage/Properties/launchSettings.json b/src/Http/DeepMiddlewareUsage/Properties/launchSettings.json new file mode 100644 index 000000000..53805d969 --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5063", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7258;http://localhost:5063", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Http/DeepMiddlewareUsage/Trainer.cs b/src/Http/DeepMiddlewareUsage/Trainer.cs new file mode 100644 index 000000000..183397a8a --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/Trainer.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; +using Marten.Schema; + +namespace DeepMiddlewareUsage; + +public class Participant { } + +public class Trainer: Participant +{ + [DefaultValue(null)] + [UniqueIndex(IndexType = UniqueIndexType.Computed)] + public string? Name { get; set; } + + [DefaultValue(null)] + public string? Country { get; set; } + + [DefaultValue(null)] + public string? TimeZone { get; set; } +} \ No newline at end of file diff --git a/src/Http/DeepMiddlewareUsage/TrainerGet.cs b/src/Http/DeepMiddlewareUsage/TrainerGet.cs new file mode 100644 index 000000000..5f2708efd --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/TrainerGet.cs @@ -0,0 +1,15 @@ +using Wolverine.Http; + +namespace DeepMiddlewareUsage; + +public static class TrainerGet +{ + [Tags("Trainer")] + [WolverineGet("/api/trainer")] + public static TrainerResponse Get(Trainer trainer) + { + return new TrainerResponse(trainer.Name ?? "Unknown", trainer.Country); + } +} + +public record TrainerResponse(string Name, string? Country); \ No newline at end of file diff --git a/src/Http/DeepMiddlewareUsage/TrainerMiddleware.cs b/src/Http/DeepMiddlewareUsage/TrainerMiddleware.cs new file mode 100644 index 000000000..54ab07f5e --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/TrainerMiddleware.cs @@ -0,0 +1,49 @@ +using JasperFx; +using JasperFx.CodeGeneration; +using JasperFx.CodeGeneration.Frames; +using Marten; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Wolverine.Http; + +namespace DeepMiddlewareUsage; + +public static class TrainerMiddleware +{ + public static async Task<(Trainer? trainer, ProblemDetails)> LoadAsync( + UserId userId, + IDocumentSession session, + CancellationToken ct, + HttpContext context) + { + if (userId.Id == Guid.Empty) + return (null, WolverineContinue.NoProblems); + + var trainer = await session.LoadAsync(userId.Id, ct); + + bool allowAnonymous = context.GetEndpoint()?.Metadata.GetMetadata() != null; + if (trainer == null && !allowAnonymous) + return (null, new ProblemDetails + { + Title = "Unauthorized", + Status = StatusCodes.Status401Unauthorized + }); + + return (trainer, WolverineContinue.NoProblems); + } +} + +internal class RequestTrainerPolicy : IHttpPolicy +{ + public void Apply(IReadOnlyList chains, GenerationRules rules, IServiceContainer container) + { + foreach (HttpChain chain in chains) + { + Type[] serviceDependencies = chain.ServiceDependencies(container, Type.EmptyTypes).ToArray(); + if (serviceDependencies.Contains(typeof(Trainer))) + { + chain.Middleware.Add(new MethodCall(typeof(TrainerMiddleware), nameof(TrainerMiddleware.LoadAsync))); + } + } + } +} \ No newline at end of file diff --git a/src/Http/DeepMiddlewareUsage/UserMiddleware.cs b/src/Http/DeepMiddlewareUsage/UserMiddleware.cs new file mode 100644 index 000000000..588b38551 --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/UserMiddleware.cs @@ -0,0 +1,25 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Wolverine.Http; + +namespace DeepMiddlewareUsage; + +public record UserId(Guid Id); + +public static class UserIdMiddleWare +{ + public static (UserId, ProblemDetails) Load(ClaimsPrincipal principal, HttpContext context) + { + Claim? userIdClaim = principal.FindFirst("sub"); + if (userIdClaim != null && Guid.TryParse(userIdClaim.Value, out var id)) + { + return ( new UserId(id), WolverineContinue.NoProblems); + } + + Endpoint? endpoint = context.GetEndpoint(); + return endpoint?.Metadata.GetMetadata() != null + ? ( new UserId(Guid.Empty), WolverineContinue.NoProblems) + : (new UserId(Guid.Empty), new ProblemDetails { Detail = "Unauthorized", Status = 401}); + } +} \ No newline at end of file diff --git a/src/Http/DeepMiddlewareUsage/appsettings.Development.json b/src/Http/DeepMiddlewareUsage/appsettings.Development.json new file mode 100644 index 000000000..0c208ae91 --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/Http/DeepMiddlewareUsage/appsettings.json b/src/Http/DeepMiddlewareUsage/appsettings.json new file mode 100644 index 000000000..10f68b8c8 --- /dev/null +++ b/src/Http/DeepMiddlewareUsage/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/Http/Wolverine.Http/CodeGen/ProblemDetailsContinuationPolicy.cs b/src/Http/Wolverine.Http/CodeGen/ProblemDetailsContinuationPolicy.cs index 71d39876f..64d5ad587 100644 --- a/src/Http/Wolverine.Http/CodeGen/ProblemDetailsContinuationPolicy.cs +++ b/src/Http/Wolverine.Http/CodeGen/ProblemDetailsContinuationPolicy.cs @@ -1,3 +1,4 @@ +using JasperFx; using JasperFx.CodeGeneration; using JasperFx.CodeGeneration.Frames; using JasperFx.CodeGeneration.Model; @@ -11,6 +12,25 @@ namespace Wolverine.Http.CodeGen; +internal class ProblemDetailsFromMiddleware : IHttpPolicy +{ + public void Apply(IReadOnlyList chains, GenerationRules rules, IServiceContainer container) + { + foreach (var chain in chains) + { + foreach (var methodCall in chain.Middleware.OfType().ToArray()) + { + foreach (var details in methodCall.Creates.Where(x => x.VariableType == typeof(ProblemDetails) && !x.Properties.ContainsKey("checked"))) + { + var index = chain.Middleware.IndexOf(methodCall); + chain.Middleware.Insert(index + 1, new MaybeEndWithProblemDetailsFrame(details)); + details.Properties["checked"] = true; + } + } + } + } +} + public class ProblemDetailsContinuationPolicy : IContinuationStrategy { public static void WriteProblems(ILogger logger, ProblemDetails details) @@ -23,8 +43,16 @@ public bool TryFindContinuationHandler(IChain chain, MethodCall call, out Frame? { var details = call.Creates.FirstOrDefault(x => x.VariableType == typeof(ProblemDetails)); - if (details != null) + + if (details != null && !details.Properties.ContainsKey("checked")) { + if (chain.Middleware.OfType().Any(x => ReferenceEquals(x.Details, details))) + { + frame = null; + return false; + } + + details.Properties["checked"] = true; if (chain is HttpChain) { frame = new MaybeEndWithProblemDetailsFrame(details); @@ -42,21 +70,27 @@ public bool TryFindContinuationHandler(IChain chain, MethodCall call, out Frame? } } +internal interface IMaybeEndWithProblemDetails +{ + Variable Details { get; } +} + /// /// Used to potentially stop the execution of an Http request /// based on whether the IResult is a WolverineContinue or something else /// -internal class MaybeEndWithProblemDetailsFrame : AsyncFrame +internal class MaybeEndWithProblemDetailsFrame : AsyncFrame, IMaybeEndWithProblemDetails { - private readonly Variable _details; private Variable? _context; public MaybeEndWithProblemDetailsFrame(Variable details) { uses.Add(details); - _details = details; + Details = details; } - + + public Variable Details { get; } + public override IEnumerable FindVariables(IMethodVariables chain) { _context = chain.FindVariable(typeof(HttpContext)); @@ -66,8 +100,8 @@ public override IEnumerable FindVariables(IMethodVariables chain) public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteComment("Evaluate whether the processing should stop if there are any problems"); - writer.Write($"BLOCK:if (!(ReferenceEquals({_details.Usage}, {typeof(WolverineContinue).FullNameInCode()}.{nameof(WolverineContinue.NoProblems)})))"); - writer.Write($"await {nameof(HttpHandler.WriteProblems)}({_details.Usage}, {_context!.Usage}).ConfigureAwait(false);"); + writer.Write($"BLOCK:if (!(ReferenceEquals({Details.Usage}, {typeof(WolverineContinue).FullNameInCode()}.{nameof(WolverineContinue.NoProblems)})))"); + writer.Write($"await {nameof(HttpHandler.WriteProblems)}({Details.Usage}, {_context!.Usage}).ConfigureAwait(false);"); writer.Write("return;"); writer.FinishBlock(); writer.BlankLine(); @@ -80,17 +114,18 @@ public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) /// Used to potentially stop the execution of an Http request /// based on whether the IResult is a WolverineContinue or something else /// -public class MaybeEndHandlerWithProblemDetailsFrame : AsyncFrame +public class MaybeEndHandlerWithProblemDetailsFrame : AsyncFrame, IMaybeEndWithProblemDetails { - private readonly Variable _details; private Variable? _logger; public MaybeEndHandlerWithProblemDetailsFrame(Variable details) { uses.Add(details); - _details = details; + Details = details; } + public Variable Details { get; } + public override IEnumerable FindVariables(IMethodVariables chain) { _logger = chain.FindVariable(typeof(ILogger)); @@ -100,8 +135,8 @@ public override IEnumerable FindVariables(IMethodVariables chain) public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { writer.WriteComment("Evaluate whether the processing should stop if there are any problems"); - writer.Write($"BLOCK:if (!(ReferenceEquals({_details.Usage}, {typeof(WolverineContinue).FullNameInCode()}.{nameof(WolverineContinue.NoProblems)})))"); - writer.Write($"{typeof(ProblemDetailsContinuationPolicy).FullNameInCode()}.{nameof(ProblemDetailsContinuationPolicy.WriteProblems)}({_logger.Usage}, {_details.Usage});"); + writer.Write($"BLOCK:if (!(ReferenceEquals({Details.Usage}, {typeof(WolverineContinue).FullNameInCode()}.{nameof(WolverineContinue.NoProblems)})))"); + writer.Write($"{typeof(ProblemDetailsContinuationPolicy).FullNameInCode()}.{nameof(ProblemDetailsContinuationPolicy.WriteProblems)}({_logger.Usage}, {Details.Usage});"); writer.Write("return;"); writer.FinishBlock(); writer.BlankLine(); diff --git a/src/Http/Wolverine.Http/WolverineHttpEndpointRouteBuilderExtensions.cs b/src/Http/Wolverine.Http/WolverineHttpEndpointRouteBuilderExtensions.cs index 751e3bdc8..153a8a86a 100644 --- a/src/Http/Wolverine.Http/WolverineHttpEndpointRouteBuilderExtensions.cs +++ b/src/Http/Wolverine.Http/WolverineHttpEndpointRouteBuilderExtensions.cs @@ -193,6 +193,8 @@ public static void MapWolverineEndpoints(this IEndpointRouteBuilder endpoints, configure?.Invoke(options); + options.Policies.Add(new ProblemDetailsFromMiddleware()); + if (Environment.CommandLine.Contains("codegen", StringComparison.OrdinalIgnoreCase)) { options.WarmUpRoutes = RouteWarmup.Lazy; diff --git a/src/Wolverine/Middleware/ContinuationHandling.cs b/src/Wolverine/Middleware/ContinuationHandling.cs index 4db9d626e..8bb63d875 100644 --- a/src/Wolverine/Middleware/ContinuationHandling.cs +++ b/src/Wolverine/Middleware/ContinuationHandling.cs @@ -47,10 +47,12 @@ public static bool TryFindContinuationHandler(this GenerationRules rules, IChain { var strategies = rules.ContinuationStrategies(); foreach (var strategy in strategies) + { if (strategy.TryFindContinuationHandler(chain, call, out frame)) { return true; } + } frame = null; return false; diff --git a/wolverine.sln b/wolverine.sln index a7281f723..be24428a8 100644 --- a/wolverine.sln +++ b/wolverine.sln @@ -303,6 +303,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DomainEventsWithEfCore", "D EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BackLogService", "DomainEventsWithEfCore\BackLogService\BackLogService.csproj", "{912B3B0A-7CFB-4838-992F-DA5DBF70308C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeepMiddlewareUsage", "src\Http\DeepMiddlewareUsage\DeepMiddlewareUsage.csproj", "{1D14EDEB-FCC6-400C-B74E-7DBD8199A151}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1693,6 +1695,18 @@ Global {912B3B0A-7CFB-4838-992F-DA5DBF70308C}.Release|x64.Build.0 = Release|Any CPU {912B3B0A-7CFB-4838-992F-DA5DBF70308C}.Release|x86.ActiveCfg = Release|Any CPU {912B3B0A-7CFB-4838-992F-DA5DBF70308C}.Release|x86.Build.0 = Release|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Debug|x64.ActiveCfg = Debug|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Debug|x64.Build.0 = Debug|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Debug|x86.ActiveCfg = Debug|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Debug|x86.Build.0 = Debug|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Release|Any CPU.Build.0 = Release|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Release|x64.ActiveCfg = Release|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Release|x64.Build.0 = Release|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Release|x86.ActiveCfg = Release|Any CPU + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1833,5 +1847,6 @@ Global {501C5BD8-41D5-4032-85C7-33F8815EA60D} = {96119B5E-B5F0-400A-9580-B342EBE26212} {B0C50461-1C9C-4867-8023-94AA6755257E} = {D953D733-D154-4DF2-B2B9-30BF942E1B6B} {912B3B0A-7CFB-4838-992F-DA5DBF70308C} = {B0C50461-1C9C-4867-8023-94AA6755257E} + {1D14EDEB-FCC6-400C-B74E-7DBD8199A151} = {4B0BC1E5-17F9-4DD0-AC93-DDC522E1BE3C} EndGlobalSection EndGlobal