public OutgoingRequest MergeWith(OutgoingRequest other)
 {
     return(new OutgoingRequest()
     {
         Content = Merger <TodoList, Guid>
                   .GroupByIdAndMerge(Content.Concat(other.Content), (x) => x.Id, TodoList.Merge)
     });
 }
 public RequestBuilder(
     Func <T, OutgoingRequest> getRequest,
     Action <T, OutgoingRequest> setRequest,
     int maxTodoListsPerRequest
     )
 {
     RequestBeingBuilt       = new OutgoingRequest();
     _getRequest             = getRequest;
     _setRequest             = setRequest;
     _maxTodoListsPerRequest = maxTodoListsPerRequest;
 }
        public void OnNext(T @event, long sequence, bool isEndOfBatch)
        {
            var newRequest = _getRequest(@event);

            if (isEndOfBatch)
            {
                _setRequest(@event, RequestBeingBuilt.MergeWith(newRequest));
                RequestBeingBuilt = new OutgoingRequest();
            }
            else if (newRequest.Content.Count() + RequestBeingBuilt.Content.Count() > _maxTodoListsPerRequest)
            {
                _setRequest(@event, RequestBeingBuilt);
                RequestBeingBuilt = newRequest;
            }
            else
            {
                RequestBeingBuilt = RequestBeingBuilt.MergeWith(newRequest);
            }
        }
        private void LogRequest(string prefix, OutgoingRequest request)
        {
            var idsAndVersions = String.Join(",\n", request.Content.Select(list => "    " + list.Id + "  Version: " + list.Version));

            _resultLog.Add(prefix + ":\n" + idsAndVersions);
        }