Ejemplo n.º 1
0
        private static void MsgQ_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            MessageQueue mq      = (MessageQueue)sender;
            Message      message = mq.EndReceive(e.AsyncResult);

            message.Formatter = new XmlMessageFormatter(new [] { typeof(CreateMarketCommand) });

            CreateMarketCommand command = (CreateMarketCommand)message.Body;

            Debug.Assert(command.MatchId == 4, $"Match Id expected 4 but was {command.MatchId}");
            Debug.Assert(command.Market != null, "Market expected but was null");

            Market market = command.Market;

            Console.WriteLine($"Message: {market.Id} {market.Name} {market.TradingStatus} || {market.MarketType.Id} {market.MarketType.Name} || {market.Selections[0].Kef} {market.Selections[0].Name}");
            Thread.Sleep(1500);
            mq.BeginReceive();
        }
Ejemplo n.º 2
0
        public string Manage(MarketFeedModel feedModel, string matchId)
        {
            IEnumerable <int> keys = new List <int>()
            {
                feedModel.Key
            };
            EntitiesByKeyQuery <Market> query = new EntitiesByKeyQuery <Market>(keys);
            Market market = queryDispatcher.Dispatch <EntitiesByKeyQuery <Market>, IEnumerable <Market> >(query).FirstOrDefault();

            if (market != null)
            {
                return(market.Id);
            }

            CreateMarketCommand command = Mapper.Map <CreateMarketCommand>(feedModel);

            command.MatchId = matchId;

            return(commandDispatcher.Dispatch <CreateMarketCommand, string>(command));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateMarket([FromBody] CreateMarketCommand command)
        {
            try
            {
                var market = await Market.FromAccessService(this._exchangeAccessService, command.ExchangeId, command.BaseCurrency.ToUpper(), command.QuoteCurrency.ToUpper());

                if (market != null)
                {
                    this._marketRepository.Add(market);

                    await _context.SaveEntitiesAsync();
                }

                return(Ok(market.MarketId));
                //return CreatedAtAction("GetMarket", new { marketId = market.MarketId }, market);
            }
            catch (Exception ex)
            {
                return(NotFound(ex.Message));
            }
        }
Ejemplo n.º 4
0
 public async Task <ActionResult <Market> > Create([FromBody] CreateMarketCommand command)
 {
     return(await Mediator.Send(command));
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            const string QUEUE_NAME = ".\\SimpleTestQueue";
            MessageQueue msgQ;

            if (!MessageQueue.Exists(QUEUE_NAME))
            {
                msgQ = MessageQueue.Create(QUEUE_NAME);
            }
            else
            {
                msgQ = new MessageQueue(QUEUE_NAME);
            }

            string input = Console.ReadLine();

            while (!string.IsNullOrEmpty(input))
            {
                Market market = new Market
                {
                    Id            = 1,
                    Name          = "Market",
                    TradingStatus = MarketStatus.Trading,
                    MarketType    = new MarketType {
                        Id = 2, Name = "Market Type"
                    },
                    Selections = new List <Selection>(),
                };

                market.Selections.Add(new Selection {
                    Id = 3, Name = "Home", Kef = 1.9m
                });

                CreateMarketCommand command = new CreateMarketCommand
                {
                    Market  = market,
                    MatchId = 4,
                };

                MessageQueueTransaction tran = new MessageQueueTransaction();
                tran.Begin();
                try
                {
                    for (int i = 0; i < 4; i++)
                    {
                        msgQ.Send(command, tran);
                    }
                    tran.Commit();
                }
                catch
                {
                    tran.Abort();
                    throw;
                }
                finally
                {
                    tran?.Dispose();
                }
                input = Console.ReadLine();
            }
        }