Esempio n. 1
0
        private static Conversation HandleStockPriceUpdate(Envelope e)
        {
            Conversation conv = null;

            StockPriceUpdate m = e.Contents as StockPriceUpdate;
            var sigServ        = new SignatureService();
            var bits           = Convert.FromBase64String(m.SerializedStockList);
            var StocksList     = sigServ.Deserialize <MarketDay>(bits);

            if (!sigServ.VerifySignature(StocksList, m.StockListSignature))
            {
                Log.Error("Stock Price Update signature validation failed. Ignoring message.");
            }
            else
            {
                LeaderboardManager.Market = StocksList;

                conv = new StockUpdateConversation(m.ConversationID);
                conv.SetInitialState(new ProcessStockUpdateState(e, conv));

                //Send updated leaderboard to clients.
                Task.Run(() =>
                {
                    foreach (var clientIp in ClientManager.Clients.Keys)
                    {
                        var stockUpdateConv = new LeaderBoardUpdateRequestConversation(Config.GetInt(Config.BROKER_PROCESS_NUM));
                        stockUpdateConv.SetInitialState(new LeaderboardSendUpdateState(clientIp, stockUpdateConv, null));
                        ConversationManager.AddConversation(stockUpdateConv);
                    }
                });
            }
            return(conv);
        }
Esempio n. 2
0
        public Conversation ConversationBuilder(Envelope env)
        {
            Conversation conv = null;

            switch (env.Contents)
            {
            case StockPriceUpdate m:
                conv = new StockUpdateConversation(m.ConversationID);

                //setup response message as mock
                mock = new Mock <ProcessStockUpdateState>(env, conv)
                {
                    CallBase = true
                };
                conv.SetInitialState(mock.Object as ProcessStockUpdateState);

                break;
            }

            return(conv);
        }