Skip to content

Commit

Permalink
Added Docker compose for event store
Browse files Browse the repository at this point in the history
  • Loading branch information
althunibat committed Oct 24, 2020
1 parent 58557b4 commit 5820fae
Show file tree
Hide file tree
Showing 47 changed files with 1,780 additions and 1,733 deletions.
702 changes: 351 additions & 351 deletions .gitignore

Large diffs are not rendered by default.

350 changes: 175 additions & 175 deletions Godwit.Grains/AccountGrain.cs

Large diffs are not rendered by default.

160 changes: 80 additions & 80 deletions Godwit.Grains/Domain/AccountState.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Godwit.Interfaces.Messages.Commands;
using Godwit.Interfaces.Messages.Events;

namespace Godwit.Grains.Domain {
[Serializable]
public class AccountState {
private readonly IDictionary<Guid, Transaction> _transactions;

public AccountState() {
Status = AccountStatus.NotInitialized;
Amount = 0;
Version = 0;
_transactions = new Dictionary<Guid, Transaction>();
}

public int Version { get; private set; }
public AccountStatus Status { get; private set; }
public decimal Amount { get; private set; }
public string CustomerNumber { get; private set; }
public string BranchCode { get; private set; }
public string CloseReason { get; private set; }
public DateTimeOffset OpenTimeStamp { get; private set; }
public DateTimeOffset? CloseTimeStamp { get; private set; }

public Transaction this[Guid transactionId] =>
_transactions.ContainsKey(transactionId) ? _transactions[transactionId] : null;
public IEnumerable<Transaction> Transactions => _transactions.Values;
public void Apply(IEvent @event) {
switch (@event) {
case AccountOpenedEvent evt1:
Apply(evt1);
break;
case AccountClosedEvent evt2:
Apply(evt2);
break;
case AccountDepositedEvent evt3:
Apply(evt3);
break;
case AccountWithDrawnEvent evt4:
Apply(evt4);
break;
}
}

private void Apply(AccountOpenedEvent @event) {
Status = AccountStatus.Open;
Amount = @event.Amount;
BranchCode = @event.BranchCode;
CustomerNumber = @event.CustomerNumber;
OpenTimeStamp = @event.TimeStamp;
Version++;
}

private void Apply(AccountClosedEvent @event) {
Status = AccountStatus.Closed;
CloseReason = @event.Reason;
CloseTimeStamp = @event.TimeStamp;
Version++;
}

private void Apply(AccountDepositedEvent @event) {
if (_transactions.ContainsKey(@event.TransactionId))
return;
Amount += @event.Amount;
_transactions.Add(@event.TransactionId, new Transaction(@event));
Version++;
}

private void Apply(AccountWithDrawnEvent @event) {
if (_transactions.ContainsKey(@event.TransactionId))
return;
Amount -= @event.Amount;
_transactions.Add(@event.TransactionId, new Transaction(@event));
Version++;
}
}
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Godwit.Interfaces.Messages.Commands;
using Godwit.Interfaces.Messages.Events;

namespace Godwit.Grains.Domain {
[Serializable]
public class AccountState {
private readonly IDictionary<Guid, Transaction> _transactions;

public AccountState() {
Status = AccountStatus.NotInitialized;
Amount = 0;
Version = 0;
_transactions = new Dictionary<Guid, Transaction>();
}

public int Version { get; private set; }
public AccountStatus Status { get; private set; }
public decimal Amount { get; private set; }
public string CustomerNumber { get; private set; }
public string BranchCode { get; private set; }
public string CloseReason { get; private set; }
public DateTimeOffset OpenTimeStamp { get; private set; }
public DateTimeOffset? CloseTimeStamp { get; private set; }

public Transaction this[Guid transactionId] =>
_transactions.ContainsKey(transactionId) ? _transactions[transactionId] : null;
public IEnumerable<Transaction> Transactions => _transactions.Values;
public void Apply(IEvent @event) {
switch (@event) {
case AccountOpenedEvent evt1:
Apply(evt1);
break;
case AccountClosedEvent evt2:
Apply(evt2);
break;
case AccountDepositedEvent evt3:
Apply(evt3);
break;
case AccountWithDrawnEvent evt4:
Apply(evt4);
break;
}
}

private void Apply(AccountOpenedEvent @event) {
Status = AccountStatus.Open;
Amount = @event.Amount;
BranchCode = @event.BranchCode;
CustomerNumber = @event.CustomerNumber;
OpenTimeStamp = @event.TimeStamp;
Version++;
}

private void Apply(AccountClosedEvent @event) {
Status = AccountStatus.Closed;
CloseReason = @event.Reason;
CloseTimeStamp = @event.TimeStamp;
Version++;
}

private void Apply(AccountDepositedEvent @event) {
if (_transactions.ContainsKey(@event.TransactionId))
return;
Amount += @event.Amount;
_transactions.Add(@event.TransactionId, new Transaction(@event));
Version++;
}

private void Apply(AccountWithDrawnEvent @event) {
if (_transactions.ContainsKey(@event.TransactionId))
return;
Amount -= @event.Amount;
_transactions.Add(@event.TransactionId, new Transaction(@event));
Version++;
}
}
}
12 changes: 6 additions & 6 deletions Godwit.Grains/Domain/AccountStatus.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Godwit.Grains.Domain {
public enum AccountStatus {
NotInitialized,
Closed,
Open
}
namespace Godwit.Grains.Domain {
public enum AccountStatus {
NotInitialized,
Closed,
Open
}
}
42 changes: 21 additions & 21 deletions Godwit.Grains/Domain/Transaction.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using System;
using Godwit.Interfaces.Messages.Events;

namespace Godwit.Grains.Domain {
public class Transaction {
public Transaction(AccountDepositedEvent @event) {
Type = TransactionType.Credit;
Amount = @event.Amount;
TransactionId = @event.TransactionId;
}

public Transaction(AccountWithDrawnEvent @event) {
Type = TransactionType.Debit;
Amount = @event.Amount;
TransactionId = @event.TransactionId;
}

public decimal Amount { get; }
public TransactionType Type { get; }
public Guid TransactionId { get; }
}
using System;
using Godwit.Interfaces.Messages.Events;

namespace Godwit.Grains.Domain {
public class Transaction {
public Transaction(AccountDepositedEvent @event) {
Type = TransactionType.Credit;
Amount = @event.Amount;
TransactionId = @event.TransactionId;
}

public Transaction(AccountWithDrawnEvent @event) {
Type = TransactionType.Debit;
Amount = @event.Amount;
TransactionId = @event.TransactionId;
}

public decimal Amount { get; }
public TransactionType Type { get; }
public Guid TransactionId { get; }
}
}
10 changes: 5 additions & 5 deletions Godwit.Grains/Domain/TransactionType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Godwit.Grains.Domain {
public enum TransactionType {
Credit,
Debit
}
namespace Godwit.Grains.Domain {
public enum TransactionType {
Credit,
Debit
}
}
44 changes: 22 additions & 22 deletions Godwit.Grains/Godwit.Grains.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="20.6.1" />
<PackageReference Include="protobuf-net" Version="3.0.52" />
<ProjectReference Include="..\Godwit.Interfaces\Godwit.Interfaces.csproj" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.EventSourcing" Version="3.3.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="20.6.1" />
<PackageReference Include="protobuf-net" Version="3.0.52" />
<ProjectReference Include="..\Godwit.Interfaces\Godwit.Interfaces.csproj" />
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.EventSourcing" Version="3.3.0" />
</ItemGroup>

</Project>
34 changes: 17 additions & 17 deletions Godwit.Interfaces/AccountTransactionException.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System;
using System.Runtime.Serialization;

namespace Godwit.Interfaces {
public class AccountTransactionException : ApplicationException {
public AccountTransactionException() {
}

public AccountTransactionException(SerializationInfo info, StreamingContext context) : base(info, context) {
}

public AccountTransactionException(string message) : base(message) {
}

public AccountTransactionException(string message, Exception innerException) : base(message, innerException) {
}
}
using System;
using System.Runtime.Serialization;

namespace Godwit.Interfaces {
public class AccountTransactionException : ApplicationException {
public AccountTransactionException() {
}

public AccountTransactionException(SerializationInfo info, StreamingContext context) : base(info, context) {
}

public AccountTransactionException(string message) : base(message) {
}

public AccountTransactionException(string message, Exception innerException) : base(message, innerException) {
}
}
}
8 changes: 4 additions & 4 deletions Godwit.Interfaces/Constants/StreamName.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Godwit.Interfaces.Constants {
public static class StreamName {
public const string AccountStream = nameof(AccountStream);
}
namespace Godwit.Interfaces.Constants {
public static class StreamName {
public const string AccountStream = nameof(AccountStream);
}
}
8 changes: 4 additions & 4 deletions Godwit.Interfaces/Constants/StreamProviderName.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Godwit.Interfaces.Constants {
public static class StreamProviderName {
public const string Default = nameof(Default);
}
namespace Godwit.Interfaces.Constants {
public static class StreamProviderName {
public const string Default = nameof(Default);
}
}
30 changes: 15 additions & 15 deletions Godwit.Interfaces/Godwit.Interfaces.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="3.3.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit 5820fae

Please sign in to comment.