public TraderModel() { if (Current == null) { Current = this; } else { throw new Exception("Only one Trader model should be used."); } Current = this; var getStockHistConv = new StockHistoryRequestConversation(); getStockHistConv.SetInitialState(new StockHistoryRequestState(getStockHistConv)); ConversationManager.AddConversation(getStockHistConv); var stockStreamConv = new StockStreamRequestConversation(Config.GetClientProcessNumber()); stockStreamConv.SetInitialState(new StockStreamRequestState(Config.GetClientProcessNumber(), stockStreamConv)); ConversationManager.AddConversation(stockStreamConv); StockUpdateEventHandler += HandleStockUpdate; }
public override ConversationState HandleMessage(Envelope incomingMessage) { Log.Debug($"{nameof(HandleMessage)} (enter)"); ConversationState nextState = null; switch (incomingMessage.Contents) { case StockHistoryResponseMessage m: var stockHistory = m.RecentHistory; Log.Info($"Received stock stream response with {stockHistory.Count} days of recent trading."); nextState = new ConversationDoneState(Conversation, this); var streamConv = new StockStreamRequestConversation(Config.GetInt(Config.BROKER_PROCESS_NUM)); streamConv.SetInitialState(new StockStreamRequestState(Config.GetInt(Config.BROKER_PROCESS_NUM), streamConv)); ConversationManager.AddConversation(streamConv); break; case ErrorMessage m: Log.Error($"Received error message as reply...\n{m.ErrorText}"); nextState = new ConversationDoneState(Conversation, this); break; default: Log.Error($"No logic to process incoming message of type {incomingMessage.Contents?.GetType()}."); Log.Error($"Ending conversation {Conversation.Id}."); nextState = new ConversationDoneState(Conversation, this); break; } Log.Debug($"{nameof(HandleMessage)} (exit)"); return(nextState); }