-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
215 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Olympics.Interfaces; | ||
using Orleans; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Olympics.Grains | ||
{ | ||
public class ATMGrain : Grain, IATMGrain | ||
{ | ||
public Task Transfer(Guid fromAccount, Guid toAccount, uint amountToTransfer) | ||
{ | ||
return Task.WhenAll( | ||
this.GrainFactory.GetGrain<IAccountGrain>(fromAccount).Withdraw(amountToTransfer), | ||
this.GrainFactory.GetGrain<IAccountGrain>(toAccount).Deposit(amountToTransfer) | ||
); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Olympics.Interfaces; | ||
using Orleans; | ||
using Orleans.CodeGeneration; | ||
using Orleans.Transactions.Abstractions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
[assembly: GenerateSerializer(typeof(Olympics.Grains.Balance))] | ||
namespace Olympics.Grains | ||
{ | ||
public class Balance | ||
{ | ||
public uint Value { get; set; } = 1000; | ||
} | ||
|
||
public class AccountGrain : Grain, IAccountGrain | ||
{ | ||
private readonly ITransactionalState<Balance> balance; | ||
|
||
public AccountGrain([TransactionalState("balance")] ITransactionalState<Balance> balance) | ||
{ | ||
this.balance = balance ?? throw new ArgumentNullException(nameof(balance)); | ||
} | ||
|
||
public Task Deposit(uint amount) | ||
{ | ||
return this.balance.PerformUpdate(x => x.Value += amount); | ||
} | ||
|
||
public Task<uint> GetBalance() | ||
{ | ||
return this.balance.PerformRead(x => x.Value); | ||
} | ||
|
||
public Task Withdraw(uint amount) | ||
{ | ||
return this.balance.PerformUpdate(x => x.Value -= amount); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Olympics.Entities | ||
{ | ||
/// <summary> | ||
/// 账户 | ||
/// </summary> | ||
public class Account | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public decimal Amount { get; set; } | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Olympics.Entities | ||
{ | ||
/// <summary> | ||
/// 结算记录表 | ||
/// </summary> | ||
public class AccountBalanceRecord | ||
{ | ||
public int Id { get; set; } | ||
|
||
public int FromAccountId { get; set; } | ||
|
||
public int ToAccountId { get; set; } | ||
|
||
public string AccountType { get; set; } | ||
|
||
public decimal Amount { get; set; } | ||
|
||
public DateTime CreateTime { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Olympics.Entities | ||
{ | ||
public class AccountRequestRecord | ||
{ | ||
public int Id { get; set; } | ||
|
||
public int FromAccountId { get; set; } | ||
|
||
public int ToAccountId { get; set; } | ||
|
||
public string AccountType { get; set; } | ||
|
||
public decimal Amount { get; set; } | ||
|
||
public int Status { get; set; } | ||
|
||
public DateTime CreateTime { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Orleans; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Olympics.Interfaces | ||
{ | ||
public interface IATMGrain:IGrainWithIntegerKey | ||
{ | ||
[Transaction(TransactionOption.Create)] | ||
Task Transfer(Guid fromAccount, Guid toAccount, uint amountToTransfer); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Orleans; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Olympics.Interfaces | ||
{ | ||
public interface IAccountGrain : IGrainWithGuidKey | ||
{ | ||
[Transaction(TransactionOption.Join)] | ||
Task Withdraw(uint amount); | ||
|
||
[Transaction(TransactionOption.Join)] | ||
Task Deposit(uint amount); | ||
|
||
[Transaction(TransactionOption.CreateOrJoin)] | ||
Task<uint> GetBalance(); | ||
} | ||
} |
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