-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomas Lycken
committed
Dec 5, 2017
1 parent
ee14a56
commit 21777e9
Showing
12 changed files
with
49 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...T WebApi 2 with EF 6/EventSourcing.PoC.Application/Messaging/LatestMessageQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 22 additions & 7 deletions
29
...T WebApi 2 with EF 6/EventSourcing.PoC.Application/Messaging/PostMessageCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventSourcing.PoC.Application.Events; | ||
using MediatR; | ||
using RdbmsEventStore; | ||
|
||
namespace EventSourcing.PoC.Application.Messaging | ||
{ | ||
public class PostMessageCommandHandler : IAsyncRequestHandler<PostMessageCommand> | ||
public class PostMessageCommandHandler : IRequestHandler<PostMessageCommand> | ||
{ | ||
private readonly IEventStream<string, Event, IEventMetadata<string>> _eventWriter; | ||
private readonly IEventStore<string, Event, IEventMetadata<string>> _eventWriter; | ||
|
||
public PostMessageCommandHandler(IEventStream<string, Event, IEventMetadata<string>> eventWriter) | ||
public PostMessageCommandHandler(IEventStore<string, Event, IEventMetadata<string>> eventWriter) | ||
{ | ||
_eventWriter = eventWriter; | ||
} | ||
|
||
public Task Handle(PostMessageCommand command) | ||
=> !string.IsNullOrWhiteSpace(command.Message) | ||
? _eventWriter.Append("1", command.CurrentVersion, new MessagePostedEvent { Message = command.Message }) | ||
: throw new ArgumentException("Posting empty messages is not allowed"); | ||
public async Task Handle(PostMessageCommand command, CancellationToken token) | ||
{ | ||
if (string.IsNullOrWhiteSpace(command.Message)) | ||
{ | ||
throw new ArgumentException("Posting empty messages is not allowed"); | ||
} | ||
|
||
var currentVersion = (await _eventWriter.Events("1")).Select(e => e.Timestamp) | ||
.DefaultIfEmpty(DateTimeOffset.MinValue) | ||
.Max() as DateTimeOffset?; | ||
|
||
if (currentVersion == DateTimeOffset.MinValue) | ||
{ | ||
currentVersion = null; | ||
} | ||
await _eventWriter.Append("1", currentVersion, new MessagePostedEvent {Message = command.Message}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters