Esempio n. 1
0
        private static object InvokeWithStreamEnumerable(
            IMessageStreamProvider messageStreamProvider,
            SubscribedMethod subscribedMethod,
            object?[] arguments,
            IStreamEnumerableMessageArgumentResolver streamEnumerableResolver,
            IServiceProvider serviceProvider)
        {
            var target = subscribedMethod.ResolveTargetType(serviceProvider);

            var lazyStream = streamEnumerableResolver.GetValue(
                messageStreamProvider,
                subscribedMethod.MessageType,
                subscribedMethod.Filters);

            return(Task.Run(
                       async() =>
            {
                try
                {
                    await lazyStream.WaitUntilCreatedAsync().ConfigureAwait(false);

                    arguments[0] = lazyStream.Value;
                }
                catch (OperationCanceledException)
                {
                    return;
                }

                await subscribedMethod.MethodInfo.InvokeWithActivityWithoutBlockingAsync(
                    target,
                    arguments)
                .ConfigureAwait(false);
            }));
        }
        InvokeWithStreamEnumerable(
            IReadOnlyCollection <object> messages,
            SubscribedMethod subscribedMethod,
            object?[] arguments,
            IStreamEnumerableMessageArgumentResolver streamEnumerableResolver)
        {
            var streamProviders = FilterMessageStreamEnumerableMessages(messages, subscribedMethod).ToArray();

            if (streamProviders.Length == 0)
            {
                return(streamProviders, null);
            }

            var target = subscribedMethod.ResolveTargetType(_serviceProvider);

            var resultTasks = streamProviders
                              .Select(
                streamProvider =>
            {
                var lazyStream = streamEnumerableResolver.GetValue(
                    streamProvider,
                    subscribedMethod.MessageType);

                return(Task.Run(
                           async() =>
                {
                    try
                    {
                        await lazyStream.WaitUntilCreated().ConfigureAwait(false);

                        arguments[0] = lazyStream.Value;
                    }
                    catch (OperationCanceledException)
                    {
                        return;
                    }

                    await InvokeWithoutBlockingAsync(target, subscribedMethod.MethodInfo, arguments)
                    .ConfigureAwait(false);
                }));
            });

            return(messages, resultTasks.ToArray());
        }