コード例 #1
0
ファイル: OrderService.cs プロジェクト: adchang/demo_exchange
        private OrderTransactionResponseBL SaveOrderTransaction(IOrderContext context,
                                                                ISubscriber subscriber, OrderTransactionBL data)
        {
            data.Orders.ForEach(order => {
                context.Orders.Add((OrderEntity)order);
                context.Entry(order).State = EntityState.Modified;
            });
            data.Transactions.ForEach(transaction => {
                context.Transactions.Add((TransactionEntity)transaction);
            });

            try {
                context.SaveChanges();
            } catch (Exception e) {
                // QUESTION: What to do here in terms of transaction integrity?
                Logger.Here().Warning("SaveOrderTransaction failed", e);
                return(new OrderTransactionResponseBL(Constants.Response.INTERNAL_SERVER_ERROR,
                                                      data, new Error {
                    Description = e.Message
                }));
            }

            data.Transactions.ForEach(transaction => {
                TransactionProcessed message = new TransactionProcessed {
                    TransactionId    = transaction.TransactionId,
                    CreatedTimestamp = transaction.CreatedTimestamp,
                    Ticker           = transaction.Ticker,
                    Last             = Convert.ToDouble(transaction.Price),
                    Volume           = transaction.Quantity,
                    Level2           = Level2
                };
                Logger.Here().Debug("Publishing to " + Constants.PubSub.TOPIC_TRANSACTION_PROCESSED);
                subscriber.Publish(Constants.PubSub.TOPIC_TRANSACTION_PROCESSED,
                                   message.ToByteArray());
            });

            return(new OrderTransactionResponseBL(data));
        }