コード例 #1
0
        public TradePriceUpdateJob(ITradeService tradeService, IMarketDataService marketDataService)
        {
            tradeService.All
            .Grouping(t => t.CurrencyPair)
            .CollectionItemProcessing(
                (newTradeGroup, _) =>
            {
                IReadScalar <MarketData> observableMarketData =
                    marketDataService.Get(newTradeGroup.Key);

                OcConsumer consumer1 = new OcConsumer();

                //DataHasChanged
                newTradeGroup.CollectionItemProcessing(
                    (newTrade, __) =>
                    newTrade.MarketPrice = observableMarketData.Value.Bid)
                .For(consumer1);

                observableMarketData.Binding((newMarketData, __) =>
                {
                    decimal bid = observableMarketData.Value.Bid;

                    newTradeGroup.ForEach(trade =>
                                          trade.MarketPrice = bid);
                }).For(consumer1);

                return(consumer1);
            })
            .CollectionDisposing()
            .For(_consumer);
        }
コード例 #2
0
        public TradePriceUpdateJob(ITradeService tradeService, IMarketDataService marketDataService, Dispatcher dispatcher, OcDispatcher backgroundOcDispatcher)
        {
            _backgroundOcDispatcher = backgroundOcDispatcher;

            tradeService.All
            .Grouping(t => t.CurrencyPair)
            .CollectionItemProcessing(
                (newTradeGroup, _) =>
            {
                IReadScalar <MarketData> observableMarketData =
                    marketDataService.Get(newTradeGroup.Key);

                OcConsumer consumer1 = new OcConsumer();

                //DataHasChanged
                newTradeGroup.CollectionItemsProcessing(
                    (newTrades, __) =>
                {
                    Trade[] newTradesCopy = newTrades.ToArray();

                    dispatcher.Invoke(() =>
                    {
                        foreach (Trade trade in newTradesCopy)
                        {
                            trade.MarketPrice = observableMarketData.Value.Bid;
                        }
                    }, DispatcherPriority.Background);
                })
                .For(consumer1);

                observableMarketData.Binding((newMarketData, __) =>
                {
                    decimal bid             = observableMarketData.Value.Bid;
                    Trade[] tradesGroupCopy = newTradeGroup.ToArray();
                    dispatcher.Invoke(() =>
                    {
                        tradesGroupCopy.ForEach(trade =>
                                                trade.MarketPrice = bid);
                    }, DispatcherPriority.Background);
                }).For(consumer1);

                return(consumer1);
            })
            .CollectionDisposing()
            .For(_consumer);
        }