private void ObserveSymbol(SymbolViewModel symbol) { var symbolObservable = Observable.FromEventPattern <SymbolEventArgs>( eventHandler => symbol.OnSymbolNotification += eventHandler, eventHandler => symbol.OnSymbolNotification -= eventHandler) .Select(eventPattern => eventPattern.EventArgs); symbolObservable.Subscribe(args => { if (args.HasException) { TradeViewModelException(args); } }); }
private void ObserveSymbols() { var symbolsObservable = Observable.FromEventPattern <SymbolsEventArgs>( eventHandler => SymbolsViewModel.OnSymbolsNotification += eventHandler, eventHandler => SymbolsViewModel.OnSymbolsNotification -= eventHandler) .Select(eventPattern => eventPattern.EventArgs); 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); symbol.Dispatcher = ViewModelContext.UiDispatcher; ObserveSymbol(symbol); Symbols.Add(symbol); SelectedSymbol = symbol; await symbol.SetSymbol(args.Value); } } else if (args.Symbols != null) { TradeViewModel.SetSymbols(args.Symbols); } }); }