public PersonAvatarsQueryResult Load_persons_avatars()
        {
            _logger.LogInformation($"person avatars query");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new PersonAvtarsQueryContextManager(_es);
                var message_processor = new PersonAvtarsQueryProcessor();
                msgpump.Register <PersonAvatarsQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new PersonAvatarsQuery()) as PersonAvatarsQueryResult;
                return(result);
            }
        }
Example #2
0
        public CompetitorsQueryResult Get_competitors()
        {
            _logger.LogInformation("competitors query");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new CompetitorsQueryContextManager(_es);
                var message_processor = new CompetitorsQueryProcessor();
                msgpump.Register <CompetitorsQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new CompetitorsQuery()) as CompetitorsQueryResult;
                return(result);
            }
        }
        public TournamentStockQueryResult Get_tournaments_infos()
        {
            _logger.LogInformation("tournaments stock query");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new TournamentStockQueryContextManager(_es);
                var message_processor = new TournamentStockQueryProcessor();
                msgpump.Register <TournamentStockQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new TournamentStockQuery()) as TournamentStockQueryResult;
                return(result);
            }
        }
Example #4
0
        public PersonTemplateQueryResult Get_person_template()
        {
            _logger.LogInformation("person template query");

            using (var msgpump = new MessagePump())
            {
                var id_provider = new IdProvider();

                var context_manager   = new PersonTemplateQueryContextManager();
                var message_processor = new PersonTemplateQueryProcessor(id_provider);
                msgpump.Register <PersonTemplateQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new PersonTemplateQuery()) as PersonTemplateQueryResult;
                return(result);
            }
        }
        public TournamentRoundQueryResult Get_tournament_round(string tournamentId)
        {
            _logger.LogInformation($"tournament round query, tournament: {tournamentId}");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new TournamentRoundQueryContextManager(_es);
                var message_processor = new TournamentRoundQueryProcessor();
                msgpump.Register <TournamentRoundQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new TournamentRoundQuery()
                {
                    TournamentId = tournamentId
                }) as TournamentRoundQueryResult;
                return(result);
            }
        }
Example #6
0
        public TournamentCompetitorsQueryResult Load_tournament_competitors(string tournamentId)
        {
            _logger.LogInformation($"tournament competitors query, tournament: { tournamentId }");

            using (var msgpump = new MessagePump())
            {
                var context_manager   = new TournamentCompetitorsQueryContextManager(_es);
                var message_processor = new TournamentCompetitorsQueryContextProcessor();
                msgpump.Register <TournamentCompetitorsQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new TournamentCompetitorsQuery()
                {
                    TournamentId = tournamentId
                }) as TournamentCompetitorsQueryResult;
                return(result);
            }
        }
        public PersonStatsQueryResult Load_persons_stats(string personId)
        {
            _logger.LogInformation($"person stats query: { personId }");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new PersonStatsQueryContextManager(_es);
                var message_processor = new PersonStatsQueryProcessor();
                msgpump.Register <PersonStatsQuery>(context_manager, message_processor);

                var result = msgpump.Handle(new PersonStatsQuery()
                {
                    PersonId = personId
                }) as PersonStatsQueryResult;
                return(result);
            }
        }
Example #8
0
        public IActionResult Change_options(ChangeOptionsCommand change_options_command)
        {
            _logger.LogInformation($"change options command: { change_options_command.TournamentId }");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new ChangeOptionsCommandContextManager();
                var message_processor = new ChangeOptionsCommandProcessor();
                msgpump.Register <ChangeOptionsCommand>(context_manager, message_processor);

                var result = msgpump.Handle(change_options_command) as CommandStatus;
                if (result is Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Example #9
0
        public IActionResult Store_person(StorePersonCommand store_person_command)
        {
            _logger.LogInformation($"store person command, id: { store_person_command.Id }");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new StorePersonCommandContextManager(_es);
                var message_processor = new StorePersonCommandProcessor();
                msgpump.Register <StorePersonCommand>(context_manager, message_processor);

                var result = msgpump.Handle(store_person_command) as CommandStatus;
                if (result is Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Example #10
0
        public IActionResult Delete_tournament(DeleteTournamentCommand delete_tournament_command)
        {
            _logger.LogInformation($"delete tournament command, id: { delete_tournament_command.Id }");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new DeleteTournamentCommandContextManager(_es);
                var message_processor = new DeleteTournamentCommandProcessor();
                msgpump.Register <DeleteTournamentCommand>(context_manager, message_processor);

                var result = msgpump.Handle(delete_tournament_command) as CommandStatus;
                if (result is Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
        public IActionResult Reset_match_result(MatchResetCommand match_reset_command)
        {
            _logger.LogInformation($"reset match command: {match_reset_command.MatchId}");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new StoreMatchResetCommandContextManager(_es);
                var message_processor = new StoreMatchResetCommandContextProcessor();
                msgpump.Register <MatchResetCommand>(context_manager, message_processor);

                var result = msgpump.Handle(match_reset_command) as CommandStatus;
                if (result is Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
        public IActionResult Store_match_result(MatchResultNotificationCommand match_result_command)
        {
            var results = string.Join(" ", match_result_command.Results);

            _logger.LogInformation($"match result command, match: {match_result_command.MatchId}, result notification: { results }");

            using (var msgpump = new MessagePump(_es))
            {
                var context_manager   = new StoreMatchResultCommandContextManager(_es);
                var message_processor = new StoreMatchResultCommandProcessor();
                msgpump.Register <MatchResultNotificationCommand>(context_manager, message_processor);

                var result = msgpump.Handle(match_result_command) as CommandStatus;
                if (result is Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Example #13
0
        public IActionResult Create_round(CreateRoundCommand create_round_command)
        {
            _logger.LogInformation($"create round command: { create_round_command.TournamentId }");

            using (var msgpump = new MessagePump(_es))
            {
                var id_provider = new IdProvider();

                var context_manager   = new CreateRoundCommandContextManager(_es);
                var message_processor = new CreateRoundCommandProcessor(id_provider);
                msgpump.Register <CreateRoundCommand>(context_manager, message_processor);

                var result = msgpump.Handle(create_round_command) as CommandStatus;
                if (result is Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            var ex = new StockExchangeProvider();

            using (var es = new EventStore("eventstream.db"))
                using (var msgpump = new MessagePump(es)) {
                    IMessageContextManager mcm;
                    IMessageProcessor      mp;

                    mcm = new BuyStockCommandContextManager();
                    mp  = new BuyStockCommandProcessor();
                    msgpump.Register <BuyStockCommand>(mcm, mp);

                    mcm = new SellStockCommandManager(es);
                    mp  = new SellStockCommandProcessor();
                    msgpump.Register <SellStockCommand>(mcm, mp);

                    mcm = new UpdatePortfolioCommandContextManager(es);
                    mp  = new UpdatePortfolioCommandProcessor(ex);
                    msgpump.Register <UpdatePortfolioCommand>(mcm, mp);

                    mcm = new CandidateStocksQueryContextManager();
                    mp  = new CandidateStocksQueryProcessor(ex);
                    msgpump.Register <CandidateStocksQuery>(mcm, mp);

                    mcm = new PortfolioQueryContextManager(es);
                    mp  = new PortfolioQueryProcessor();
                    msgpump.Register <PortfolioQuery>(mcm, mp);

                    mcm = new PortfolioStockQueryContextManager(es);
                    mp  = new PortfolioStockQueryProcessor();
                    msgpump.Register <PortfolioStockQuery>(mcm, mp);

                    var frontend = new UserInterface();


                    frontend.OnPortfolioQuery += q => {
                        var result = msgpump.Handle(q) as PortfolioQueryResult;
                        frontend.Display(result);
                    };

                    frontend.OnUpdatePortfolioCommand += c => {
                        msgpump.Handle(c);
                        var result = msgpump.Handle(new PortfolioQuery()) as PortfolioQueryResult;
                        frontend.Display(result);
                    };

                    frontend.OnCandidateStocksQuery += q => {
                        var result = msgpump.Handle(q) as CandidateStocksQueryResult;
                        if (frontend.SelectStockToBuy(result, out var cmd))
                        {
                            msgpump.Handle(cmd);
                            frontend.DisplayBuyConfirmation(cmd.StockSymbol, cmd.Qty, cmd.StockPrice);
                        }
                    };

                    frontend.OnPortfolioStockQuery += q => {
                        var result = msgpump.Handle(q) as PortfolioStockQueryResult;
                        if (frontend.SelectStockToSell(result, out var cmd))
                        {
                            msgpump.Handle(cmd);
                            frontend.DisplaySellConfirmation(cmd.StockSymbol);
                        }
                    };


                    frontend.Run();
                }
        }