public async Task ProcessStreamItem(StreamInstrument instrument) { StreamInstrument currentInstrument = null; bool found = _instruments.TryGetValue(instrument.Id, out currentInstrument); switch (instrument.Operation) { case StreamOperation.Insert: case StreamOperation.Update: if (!found || currentInstrument.Compare(instrument) != 0) { if (_persistenceLayer != null) { await _persistenceLayer.ProcessStreamItem(instrument); } } _instruments[instrument.Id] = instrument; break; case StreamOperation.Delete: if (found) { if (_persistenceLayer != null) { await _persistenceLayer.ProcessStreamItem(instrument); } _instruments.TryRemove(instrument.Id, out currentInstrument); } break; default: break; } }
private async Task InsertInstrument(StreamInstrument instrument) { var CallSPCmd = new SqlCommand(); await DoSqlCmd(CallSPCmd, () => { var InstrumentIdTmp = instrument.Id.Split(':')[1]; var InstrumentIdSplit = InstrumentIdTmp.Split('-'); var MarketId = int.Parse(InstrumentIdSplit[0]); var SubmarketId = int.Parse(InstrumentIdSplit[1]); var Id = int.Parse(InstrumentIdSplit[2]); CallSPCmd.CommandText = "exec InsertInstrument @Id, @SubmarketId, @Name, @Timestamp"; CallSPCmd.Parameters.Add("@Id", SqlDbType.Int).Value = (MarketId * 10 + SubmarketId) * 1000000 + Id; CallSPCmd.Parameters.Add("@SubmarketId", SqlDbType.Int).Value = SubmarketId; CallSPCmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = instrument.Name; CallSPCmd.Parameters.Add("@Timestamp", SqlDbType.DateTime).Value = instrument.Date; }); }
public virtual Task InstrumentUpdated(StreamInstrument streamItem) { return(Task.CompletedTask); }
public override Task InstrumentUpdated(StreamInstrument streamItem) { return(_dataLayer.ProcessStreamItem(streamItem)); }