Exemple #1
0
            public async Task Execute(IContext ctx, TRequest request)
            {
                IContext  responseCtx;
                TResponse response;

                try
                {
                    (responseCtx, response) = await _rpc.Call <TRequest, TResponse>(ctx, request, _options);
                }
                catch (TException ex)
                {
                    if (_onException == null)
                    {
                        throw;
                    }

                    await _onException.Execute(ctx, ex);

                    return;
                }

                // don't call the response pipe inside the try/catch,
                // onException is only fo handling rpc exceptions,
                // and should not be used to process
                // exceptions thrown while handling the response
                await _onResponse.Execute(responseCtx, response);
            }
Exemple #2
0
 public async Task Execute(IContext ctx, T value)
 {
     if (_condition(ctx, value))
     {
         await _trueBranch.Execute(ctx, value).ConfigureAwait(false);
     }
     else
     {
         await _falseBranch.Execute(ctx, value).ConfigureAwait(false);
     }
 }
Exemple #3
0
 public async Task Execute(IContext ctx, T value)
 {
     if (_policyRegistry.TryGet(_policyKey, out AsyncPolicy policy))
     {
         await policy.ExecuteAsync(Execute, new Params(ctx, value, _next));
     }
     else
     {
         await _next.Execute(ctx, value);
     }
 }
Exemple #4
0
 public async Task Execute(IContext ctx, T value)
 {
     try
     {
         await _next.Execute(ctx, value);
     }
     catch (Exception ex) when(Filter(ex))
     {
         // ignore exceptions when the filter returns true;
     }
 }
Exemple #5
0
            public async Task Execute(IContext ctx, T value)
            {
                var result = _policy.Evaluate(ctx, value);

                if (Decision.Permit == result.Decision)
                {
                    await _accept.Execute(ctx, value);
                }
                else
                {
                    await _deny.Execute(ctx, value);
                }
            }
Exemple #6
0
            public async Task Execute(IContext ctx, T value)
            {
                await _semaphore.WaitAsync(ctx.Token);

                try
                {
                    await _next.Execute(ctx, value);
                }
                finally
                {
                    _semaphore.Release();
                }
            }
Exemple #7
0
            public async Task Execute(IContext ctx, T value)
            {
                var key = _getKey(ctx, value);

                if (_cases.TryGetValue(key, out var selectedCase))
                {
                    await selectedCase.Execute(ctx, value).ConfigureAwait(false);
                }
                else
                {
                    await _defaultCase.Execute(ctx, value).ConfigureAwait(false);
                }
            }
Exemple #8
0
            ///<summary>Fires the Received event.</summary>
            public override async Task HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory <byte> body)
            {
                // No need to call base, it's empty.
                var background = Context.Background;
                var receive    = new Receive(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);

                using var basicDeliver = ActivitySources.Default.StartActivity("basic_deliver".WithRmqInitPrefix());
                try
                {
                    await _next.Execute(background, receive);
                }
                catch (Exception ex)
                {
                    basicDeliver?.RecordException(ex);
                    throw;
                }
            }
Exemple #9
0
            public async Task Execute(IContext ctx, T value)
            {
                ctx.TryGetActivityContext(out ActivityContext parentContext);
                var tags = _getTags?.Invoke(ctx, value);

                using var activity = _source.StartActivity(_name, _kind, parentContext, tags);

                try
                {
                    if (activity != null)
                    {
                        ctx = ctx.WithActivityContext(activity.Context);
                    }

                    await _next.Execute(ctx, value);
                }
                catch (Exception ex)
                {
                    activity?.RecordException(ex);
                    throw;
                }
            }
Exemple #10
0
            public async Task Execute(IContext ctx, TIn value)
            {
                var(ctx1, value1) = await _transform(ctx, value).ConfigureAwait(false);

                await _next.Execute(ctx1, value1).ConfigureAwait(false);
            }
Exemple #11
0
            public async Task Execute(IContext ctx, T value)
            {
                await _executeAsync(ctx, value).ConfigureAwait(false);

                await _next.Execute(ctx, value).ConfigureAwait(false);
            }
Exemple #12
0
 public async Task Execute(IContext ctx, T value)
 {
     await _retryPolicy.ExecuteAsync(async (c) => await _next.Execute(ctx, value), ctx.Token);
 }
Exemple #13
0
 /// <summary> Execute the pipe with the Background context </summary>
 public static Task Execute <T>(this IPipe <T> pipe, T value)
 {
     return(pipe.Execute(Context.Background, value));
 }
Exemple #14
0
            public async Task Execute(IContext ctx, T value)
            {
                var p = await _principalProvider.Provide(ctx, value);

                await _next.Execute(ctx.WithPrincipal(p), value);
            }
Exemple #15
0
            public async Task Execute(IContext ctx, T value)
            {
                await Console.Out.WriteLineAsync($"Print: {value}");

                await _next.Execute(ctx, value);
            }