/// <summary> /// Use the given data source to push the data after the given checkpoint to the Bing for Commerce endpoint. /// </summary> /// <param name="data">the data source to use to poll the data from.</param> public void Push(IDataReader data) { log.Debug($"Starting a data push, starting from the checkpoint: {this.checkpointAcceptor.Checkpoint.GetValue()}."); this.tracker.Start(); var requestList = new RequestList <IDictionary <string, object> >(this.config.MaxBatchCount, this.config.MaxRequestSize, this.Serializer); string latestCheckpoint = null; foreach (var record in data.ReadNext(this.checkpointAcceptor.Checkpoint)) { if (record.OperationType == DataOperation.Update) { var updates = requestList.Add(record.Record); if (updates != null) { string localCheckpoint = latestCheckpoint; this.checkpointAcceptor.Pending(localCheckpoint); this.taskManager.Add(() => this.SendRequestAsync(updates, () => this.checkpointAcceptor.Accept(localCheckpoint))); } latestCheckpoint = record.Checkpoint; } else { throw new NotSupportedException($"Operation is not supported: {record.OperationType}"); } } var updatedRecords = requestList.ResetList(); if (updatedRecords.Count > 0) { this.checkpointAcceptor.Pending(latestCheckpoint); this.taskManager.Add(() => this.SendRequestAsync(updatedRecords, () => this.checkpointAcceptor.Accept(latestCheckpoint))); } log.Debug($"Ending a data push. Current checkpoint: {this.checkpointAcceptor.Checkpoint.GetValue()}."); }