private void DispatchMarketChanged(MarketChangedEventArgs args) { try { MarketChanged.Invoke(this, args); } catch (Exception e) { Trace.TraceError("Error dispatching event: {0}", e); } }
public void OnMarketChange(ChangeMessage <MarketChange> changeMessage) { if (changeMessage.IsStartOfNewSubscription) { //clear cache _markets.Clear(); } if (changeMessage.Items != null) { //lazy build events List <MarketChangedEventArgs> batch = BatchMarketsChanged == null ? null : new List <MarketChangedEventArgs>(changeMessage.Items.Count); foreach (MarketChange marketChange in changeMessage.Items) { Market market = OnMarketChange(marketChange); if (IsMarketRemovedOnClose && market.IsClosed) { //remove on close Market removed; _markets.TryRemove(market.MarketId, out removed); } //lazy build events if (batch != null || MarketChanged != null) { MarketChangedEventArgs arg = new MarketChangedEventArgs() { Change = marketChange, Market = market }; if (MarketChanged != null) { DispatchMarketChanged(arg); } if (batch != null) { batch.Add(arg); } } } if (batch != null) { DispatchBatchMarketsChanged(new BatchMarketsChangedEventArgs() { Changes = batch }); } } }