public void Subscribe(IDataProvider provider, InstrumentList instruments) { if (provider.Status != ProviderStatus.Connected) { provider.Connect(); } InstrumentList instrumentList = new InstrumentList(); for (int i = 0; i < instruments.Count; i++) { Instrument byIndex = instruments.GetByIndex(i); if (!this.subscriptions.ContainsKey((int)provider.Id)) { this.subscriptions[(int)provider.Id] = new Dictionary <Instrument, int>(); } if (!this.subscriptions[(int)provider.Id].ContainsKey(byIndex) || this.subscriptions[(int)provider.Id][byIndex] == 0) { this.subscriptions[(int)provider.Id][byIndex] = 0; instrumentList.Add(byIndex); } Dictionary <Instrument, int> dictionary; Instrument key; (dictionary = this.subscriptions[(int)provider.Id])[key = byIndex] = dictionary[key] + 1; } if (instrumentList.Count > 0) { provider.Subscribe(instrumentList); } }
public void Unsubscribe(IDataProvider provider, InstrumentList instruments) { InstrumentList instrumentList = new InstrumentList(); for (int i = 0; i < instruments.Count; i++) { Instrument byIndex = instruments.GetByIndex(i); Dictionary <Instrument, int> dictionary; Instrument key; (dictionary = this.subscriptions[(int)provider.Id])[key = byIndex] = dictionary[key] - 1; if (this.subscriptions[(int)provider.Id][byIndex] == 0) { instrumentList.Add(byIndex); } } provider.Unsubscribe(instrumentList); }