private void ObserveSymbol(SymbolViewModel symbol) { var symbolObservable = Observable.FromEventPattern <SymbolEventArgs>( eventHandler => symbol.OnSymbolNotification += eventHandler, eventHandler => symbol.OnSymbolNotification -= eventHandler) .Select(eventPattern => eventPattern.EventArgs); var symbolObservableSubscription = symbolObservable.Subscribe(args => { if (args.HasException) { TradeViewModelException(args); } }); symbolObservableSubscriptions.Add(symbol.Symbol.Name, symbolObservableSubscription); }
private void ObserveSymbols() { var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>( eventHandler => SymbolsViewModel.OnSymbolsNotification += eventHandler, eventHandler => SymbolsViewModel.OnSymbolsNotification -= eventHandler) .Select(eventPattern => eventPattern.EventArgs); symbolsObservableSubscription = symbolsObservable.Subscribe(async(args) => { if (args.HasException) { TradeViewModelException(args); } else if (args.Value != null) { var symbol = Symbols.FirstOrDefault(s => s.Symbol.Name.Equals(args.Value.Name)); if (symbol != null) { SelectedSymbol = symbol; } else { symbol = new SymbolViewModel(exchangeService, chartHelper, userAccount.Preferences, Logger); symbol.Dispatcher = ViewModelContext.UiDispatcher; Symbols.Add(symbol); SelectedSymbol = symbol; try { await symbol.SetSymbol(args.Value); ObserveSymbol(symbol); } catch (Exception ex) { TradeViewModelException(ex.ToString(), ex); } } } else if (args.Symbols != null) { TradeViewModel.SetSymbols(args.Symbols); } }); }