/// <summary> /// Get base information on the account /// </summary> public async Task <BankAccountStateBase> GetAccountInfo() { ActorEventSource.Current.ActorMessage(this, "@BankAccount.GetAccountInfo for account '{0}'", Id.GetStringId()); BankAccountStateBase state = await StateManager.GetStateAsync <BankAccountStateBase>("AccountState"); return(state); }
public List <string> CreateAccounts([FromBody] int count) { List <string> accounts = new List <string>(); Random r = new Random(); #region Random customer name generator with AutoPoco // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <Person>(); x.Include <Person>().Setup(p => p.FirstName).Use <FirstNameSource>() .Setup(p => p.LastName).Use <LastNameSource>(); }); // Generate one of these per test (factory will be a static variable most likely) IGenerationSession session = factory.CreateSession(); #endregion #region Create N bank accounts ServiceEventSource.Current.Message("@AccountsController.Create - Instanciating and initializating '{0}' actors", count); // Console.WriteLine(": "); for (int j = 0; j < count; j++) { // generate random account number string accountNumber = r.Next(0, 50000000).ToString("00000000"); // generate name of customer Person p = session.Single <Person>().Get(); string accountOwner = p.FirstName + " " + p.LastName; // generate starting balance for the account. Always multiple of 10 to make it easier to detect changes because of transfers int startingBalance = r.Next(0, 10000) * 10; // 'create' and initialize the actor ActorId newActorId = new ActorId(accountNumber); IBankAccount newBankAccount = ActorProxy.Create <IBankAccount>(newActorId, "fabric:/SFActors.BankAccounts"); newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult(); // debug BankAccountStateBase state = newBankAccount.GetAccountInfo().GetAwaiter().GetResult(); ServiceEventSource.Current.Message("@AccountsController.Create - " + state.CustomerName + " has €" + state.Balance + " in account nb: " + state.AccountNumber); accounts.Add(accountNumber); } #endregion return(accounts); }
public AccountDetail GetAccountBalance(string accountId) { ServiceEventSource.Current.Message("@AccountsController.GetAccountBalance"); ActorId actorId = new ActorId(accountId); IBankAccount bankAccount = ActorProxy.Create <IBankAccount>(actorId, "fabric:/SFActors.BankAccounts"); BankAccountStateBase state = bankAccount.GetAccountInfo().GetAwaiter().GetResult(); return(new AccountDetail { AccountNumber = state.AccountNumber, Balance = state.Balance }); }
static void Main(string[] args) { List <string> _accounts = new List <string>(); Random r = new Random(); #region Random customer name generator with AutoPoco // Perform factory set up (once for entire test run) IGenerationSessionFactory factory = AutoPocoContainer.Configure(x => { x.Conventions(c => { c.UseDefaultConventions(); }); x.AddFromAssemblyContainingType <Person>(); x.Include <Person>().Setup(p => p.FirstName).Use <FirstNameSource>() .Setup(p => p.LastName).Use <LastNameSource>(); }); // Generate one of these per test (factory will be a static variable most likely) IGenerationSession session = factory.CreateSession(); #endregion #region Create 100 bank accounts Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Instanciating and initializating 100 actors: "); Console.ForegroundColor = ConsoleColor.Gray; for (int j = 0; j < 100; j++) { // generate account number string accountNumber = r.Next(0, 50000000).ToString("00000000"); // generate name Person p = session.Single <Person>().Get(); string accountOwner = p.FirstName + " " + p.LastName; // generate starting balance int startingBalance = r.Next(0, 10000); // 'create' the actor ActorId newActorId = new ActorId(accountNumber); IBankAccount newBankAccount = ActorProxy.Create <IBankAccount>(newActorId, "fabric:/SFActors.BankAccounts"); newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult(); BankAccountStateBase state = newBankAccount.GetAccountInfo().GetAwaiter().GetResult(); Console.WriteLine(state.CustomerName + " has €" + state.Balance + " in account nb: " + state.AccountNumber); _accounts.Add(accountNumber); } #endregion #region Create 100 Standing Orders Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("100 Bank Account actors created. Press a key to create 100 standing orders."); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadLine(); for (int j = 0; j < 100; j++) { int posSource = r.Next(0, _accounts.Count); int posTarget = r.Next(0, _accounts.Count); if (posSource == posTarget) { // one less transfer... continue; } ActorId sourceAccountId = new ActorId(_accounts[posSource]); IBankAccount sourceAccountProxy = ActorProxy.Create <IBankAccount>(sourceAccountId, "fabric:/SFActors.BankAccounts"); double howMuch = r.NextDouble() * 500; short onMinute = (short)r.Next(0, 60); sourceAccountProxy.AddStandingOrder(_accounts[posTarget], howMuch, onMinute); Console.WriteLine("SO payable to account {0} of €{1:f2} on minute {2}", _accounts[posTarget], howMuch, onMinute); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("100 Standing orders registered created"); Console.ForegroundColor = ConsoleColor.Gray; #endregion #region GO CRAZY with creating objects Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enter how many more actors you want to create (and SO's):"); string more = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; int howManyMore = int.Parse(more); for (int j = 0; j < howManyMore; j++) { // generate account number string accountNumber = r.Next(0, 50000000).ToString("00000000"); // generate name Person p = session.Single <Person>().Get(); string accountOwner = p.FirstName + " " + p.LastName; // generate starting balance int startingBalance = r.Next(0, 10000); // 'create' the actor ActorId newActorId = new ActorId(accountNumber); IBankAccount newBankAccount = ActorProxy.Create <IBankAccount>(newActorId, "fabric:/SFActors.BankAccounts"); newBankAccount.InitializeState(accountOwner, startingBalance).GetAwaiter().GetResult(); Console.Write("A"); _accounts.Add(accountNumber); } for (int j = 0; j < howManyMore; j++) { int posSource = r.Next(0, _accounts.Count); int posTarget = r.Next(0, _accounts.Count); if (posSource == posTarget) { // one less transfer... continue; } ActorId sourceAccountId = new ActorId(_accounts[posSource]); IBankAccount sourceAccountProxy = ActorProxy.Create <IBankAccount>(sourceAccountId, "fabric:/SFActors.BankAccounts"); double howMuch = r.NextDouble() * 500; short onMinute = (short)r.Next(0, 60); sourceAccountProxy.AddStandingOrder(_accounts[posTarget], howMuch, onMinute); Console.Write("S"); } #endregion Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Done! Press any key to exit this tool."); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Gray; }