Exemplo n.º 1
0
        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();
                }
            });
        }
Exemplo n.º 2
0
 private Action WrapStart(Action start, ISourceBlock <TOutput> output)
 {
     return(() =>
     {
         try
         {
             start();
         }
         catch (Exception ex)
         {
             output.Fault(ex);
         }
     });
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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();
                }
            });
        }
Exemplo n.º 5
0
#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());
            }
        }
Exemplo n.º 6
0
 public void Fault(Exception exception)
 {
     _batchBlock.Fault(exception);
 }
Exemplo n.º 7
0
 public void Fault(Exception ex)
 {
     compHelper.Fault(ex);
     source.Fault(ex);
     target.Fault(ex);
 }
Exemplo n.º 8
0
 void IDataflowBlock.Fault(Exception exception)
 {
     orderCapturer.Fault(exception);
 }
Exemplo n.º 9
0
 public void Fault(Exception exception)
 {
     actualSource.Fault(exception);
 }
Exemplo n.º 10
0
 public void Fault(Exception exception)
 {
     _source.Fault(exception);
 }