/// <summary> /// Notifies that <paramref name="item" /> was processed. /// Note that this method is not thread safe. /// </summary> public bool Completed <TParent> ([NotNull] SplitJoinItem <TParent, TItem> item) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (this.completedItemsCount >= this.totalItemsCount) { throw new InvalidOperationException("Completed items count already equal to total items count."); } if (item.Result == null) { throw new InvalidOperationException("Item has not been completed."); } switch (item.Result) { case SplitJoinItemResult.Success: { this.succeffullyCompletedItems.Add(item.Item); break; } case SplitJoinItemResult.Failure: { this.failedItems.Add(new SplitJoinFailedItem <TItem> (item.Item, item.Exception)); break; } default: throw new NotSupportedException("item.Result: " + item.Result); } this.completedItemsCount++; return(this.completedItemsCount == this.totalItemsCount); }
CreateTransformBlock <TParent, TInputItem, TOutputItem> ([NotNull] Func <TParent, TInputItem, TOutputItem> process, ExecutionDataflowBlockOptions options = null, Action <Exception, SplitJoinItem <TParent, TInputItem> > defaultExceptionLogger = null) { if (process == null) { throw new ArgumentNullException(nameof(process)); } var block = new TransformBlock <SplitJoinItem <TParent, TInputItem>, SplitJoinItem <TParent, TOutputItem> > (splitJoinItem => { if (splitJoinItem == null) { throw new ArgumentNullException(nameof(splitJoinItem)); } if (splitJoinItem.Result == SplitJoinItemResult.Failure) { var new_split_join_item = new SplitJoinItem <TParent, TOutputItem> (splitJoinItem.Parent, default(TOutputItem), splitJoinItem.TotalItemsCount); new_split_join_item.Failed(splitJoinItem.Exception); return(new_split_join_item); } try { var item = process(splitJoinItem.Parent, splitJoinItem.Item); var new_split_join_item = new SplitJoinItem <TParent, TOutputItem> (splitJoinItem.Parent, item, splitJoinItem.TotalItemsCount); new_split_join_item.CompletedSuccessfully(); return(new_split_join_item); } catch (Exception ex) { var logger = splitJoinItem.Item as IDataflowErrorLogger; if (logger != null) { logger.OnException(ex); } else if (defaultExceptionLogger != null) { defaultExceptionLogger(ex, splitJoinItem); } var new_split_join_item = new SplitJoinItem <TParent, TOutputItem> (splitJoinItem.Parent, default(TOutputItem), splitJoinItem.TotalItemsCount); new_split_join_item.Failed(ex); return(new_split_join_item); } }, options ?? new ExecutionDataflowBlockOptions()); return(block); }