public PingStoringBlock(Func <string[], Task> storeFunc) { _source = new BatchBlock <string>(25); var storageBlock = new ActionBlock <string[]>(storeFunc, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded }); _source.LinkTo(storageBlock, new DataflowLinkOptions { PropagateCompletion = true }); _target = new ActionBlock <string>(async(message) => { await((BatchBlock <string>)_source).SendAsync(message); }); _target.Completion.ContinueWith(t => { if (t.IsFaulted) { _source.Fault(t.Exception); } else { _source.Complete(); } }); }
private Action WrapStart(Action start, ISourceBlock <TOutput> output) { return(() => { try { start(); } catch (Exception ex) { output.Fault(ex); } }); }
public PingParsingBlock(params BasePingParser[] parsers) { _deadLetter = new BufferBlock <string>(); _source = new BufferBlock <Ping>(); _buffer = new BufferBlock <string>(); _target = new ActionBlock <string>(async(s) => { await((BufferBlock <string>)_buffer).SendAsync(s); }, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded }); for (int i = 0; i < parsers.Length; i++) { var parser = parsers[i]; _buffer.LinkTo(parser, new DataflowLinkOptions { PropagateCompletion = true }, parser.Filter); parser.LinkTo(_source, new DataflowLinkOptions { PropagateCompletion = true }); _pendingTasks.Add(parser.Completion); } _buffer.LinkTo(_deadLetter, new DataflowLinkOptions { PropagateCompletion = true }); _target.Completion.ContinueWith((t) => { if (t.IsFaulted) { _buffer.Fault(t.Exception); } else { _buffer.Complete(); } }); _pendingTasks.Add(_source.Completion); _pendingTasks.Add(_target.Completion); _pendingTasks.Add(_buffer.Completion); }
public BasePingParser(Func <string, Ping> parse) { _source = new BufferBlock <Ping>(); _target = new ActionBlock <string>(async msg => await((BufferBlock <Ping>)_source).SendAsync(parse(msg)), new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = DataflowBlockOptions.Unbounded }); _target.Completion.ContinueWith((t) => { if (t.IsFaulted) { _source.Fault(t.Exception); } else { _source.Complete(); } }); }
#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void public static async void BidirectionalLinkTo <T>(this ISourceBlock <T> source, ITargetBlock <T> target) #pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void { source.LinkTo(target, new DataflowLinkOptions { PropagateCompletion = true }); try { await target.Completion.ConfigureAwait(false); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body { // we do not want to change the stacktrace of the exception. } if (target.Completion.IsFaulted && target.Completion.Exception != null) { source.Fault(target.Completion.Exception.Flatten()); } }
public void Fault(Exception exception) { _batchBlock.Fault(exception); }
public void Fault(Exception ex) { compHelper.Fault(ex); source.Fault(ex); target.Fault(ex); }
void IDataflowBlock.Fault(Exception exception) { orderCapturer.Fault(exception); }
public void Fault(Exception exception) { actualSource.Fault(exception); }
public void Fault(Exception exception) { _source.Fault(exception); }