Exemplo n.º 1
0
        public void Start()
        {
            Stop();

            IsVisible = true;

            MyPushEventProvider eventProvider = new MyPushEventProvider();
            int selectedStockCount            = Convert.ToInt32(showAmazon) + Convert.ToInt32(showApple) + Convert.ToInt32(showGoogle) + Convert.ToInt32(showMicrosoft);

            subscription = eventProvider.Stocks.Where(s =>
                                                      (showAmazon && s.Name == "AMZN") ||
                                                      (showApple && s.Name == "AAPL") ||
                                                      (showGoogle && s.Name == "GOOG") ||
                                                      (showMicrosoft && s.Name == "MSFT"))
                           .AsObservable()
                           .Buffer(selectedStockCount) // Wait till we have a value for all stocks for the day and collate them into a list of trading summaries
                           .ObserveOnDispatcher().Subscribe(group => {
                if (group.Count == 0)
                {
                    return;
                }

                var daySummary = new TradingDayClosingSummary {
                    Date      = group.First().Date,
                    Amazon    = group.Where(s => s.Name == "AMZN").Select(s => s.Close).FirstOrDefault(),
                    Apple     = group.Where(s => s.Name == "AAPL").Select(s => s.Close).FirstOrDefault(),
                    Google    = group.Where(s => s.Name == "GOOG").Select(s => s.Close).FirstOrDefault(),
                    Microsoft = group.Where(s => s.Name == "MSFT").Select(s => s.Close).FirstOrDefault()
                };


                stocks.Add(daySummary);
            });
        }
Exemplo n.º 2
0
        public void Start()
        {
            Stop();

            IsVisible = true;

            MyPushEventProvider eventProvider = new MyPushEventProvider();
            int selectedStockCount = Convert.ToInt32(showAmazon) + Convert.ToInt32(showApple) + Convert.ToInt32(showGoogle) + Convert.ToInt32(showMicrosoft);

            subscription = eventProvider.Stocks.Where(s =>
                (showAmazon && s.Name == "AMZN") ||
                (showApple && s.Name == "AAPL") ||
                (showGoogle && s.Name == "GOOG") ||
                (showMicrosoft && s.Name == "MSFT"))
                .AsObservable()
                .Buffer(selectedStockCount) // Wait till we have a value for all stocks for the day and collate them into a list of trading summaries
                .ObserveOnDispatcher().Subscribe(group => {
                if (group.Count == 0) {
                    return;
                }

                var daySummary = new TradingDayClosingSummary {
                    Date = group.First().Date,
                    Amazon = group.Where(s => s.Name == "AMZN").Select(s => s.Close).FirstOrDefault(),
                    Apple = group.Where(s => s.Name == "AAPL").Select(s => s.Close).FirstOrDefault(),
                    Google = group.Where(s => s.Name == "GOOG").Select(s => s.Close).FirstOrDefault(),
                    Microsoft = group.Where(s => s.Name == "MSFT").Select(s => s.Close).FirstOrDefault()
                };

                stocks.Add(daySummary);
            });
        }