public void Start()
        {
            // Setup the event stream subscription
            MyPushEventProvider eventProvider = new MyPushEventProvider();

            collectionView = CollectionViewSource.GetDefaultView(processes);
            collectionView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            subscription = (from processInfo in eventProvider.ProcessInformation
                            select processInfo)
                            .AsObservable()
                            .OnErrorResumeNext(eventProvider.ProcessInformation.AsObservable())
                            .ObserveOnDispatcher()
                            .Subscribe(message => {
                                // Update the process if it exists
                                if (processes.Any(p => p.ProcessId == message.ProcessId)) {
                                    processes.Where(p => p.ProcessId == message.ProcessId).ToList().ForEach(
                                        x => x.Update(message));
                                }
                                else {
                                    // Otherwise add it
                                    processes.Add(message);
                                }
                            },
                            () => processes.Clear()); // Clear the table when complete
        }
예제 #2
0
        public void Start()
        {
            // Setup the event stream subscription
            MyPushEventProvider eventProvider = new MyPushEventProvider();

            collectionView = CollectionViewSource.GetDefaultView(processes);
            collectionView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));

            subscription = (from processInfo in eventProvider.ProcessInformation
                            select processInfo)
                           .AsObservable()
                           .OnErrorResumeNext(eventProvider.ProcessInformation.AsObservable())
                           .ObserveOnDispatcher()
                           .Subscribe(message => {
                // Update the process if it exists
                if (processes.Any(p => p.ProcessId == message.ProcessId))
                {
                    processes.Where(p => p.ProcessId == message.ProcessId).ToList().ForEach(
                        x => x.Update(message));
                }
                else
                {
                    // Otherwise add it
                    processes.Add(message);
                }
            },
                                      () => processes.Clear()); // Clear the table when complete
        }
예제 #3
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);
            });
        }
 public void Start()
 {
     Stop();
     // Setup the event stream subscription
     MyPushEventProvider eventProvider = new MyPushEventProvider();
     subscription = (from myEvent in eventProvider.OneSecondTimer
                     where myEvent.MessageId % 2 == 0    // Only log every 2nd message
                     select myEvent)
                     .Take(5)   // Only take 5 messages in total, then complete
                     .AsObservable()
                     .ObserveOnDispatcher()
                     .Catch<MyMessage, Exception>(e => Observable.Return(new MyMessage { Description = e.Message }))
                     .Subscribe(
                         message => messages.Add(message), // Append each new message
                         () => Messages.Add(new MyMessage { Description = "Complete" }) // Write out "Complete" when there are no more messages
                     );
 }
예제 #5
0
        public void Start()
        {
            Stop();
            // Setup the event stream subscription
            MyPushEventProvider eventProvider = new MyPushEventProvider();

            subscription = (from myEvent in eventProvider.OneSecondTimer
                            where myEvent.MessageId % 2 == 0 // Only log every 2nd message
                            select myEvent)
                           .Take(5)                          // Only take 5 messages in total, then complete
                           .AsObservable()
                           .ObserveOnDispatcher()
                           .Catch <MyMessage, Exception>(e => Observable.Return(new MyMessage {
                Description = e.Message
            }))
                           .Subscribe(
                message => messages.Add(message),                 // Append each new message
                () => Messages.Add(new MyMessage {
                Description = "Complete"
            })                                                                                 // Write out "Complete" when there are no more messages
                );
        }
예제 #6
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);
            });
        }