public override void Invoke(TypedHyperSocket socket, ILetter letter, Metadata metadata, Type concreteType, IReceivedEventArgs receivedEventArgs)
        {
            var message    = _serializer.Deserialize <TMessage>(letter.Parts[1], concreteType);
            var answerable = new Answerable <TMessage>(_socket, message, receivedEventArgs.RemoteNodeId, metadata.ConversationId);
            ITypedHandler <TMessage> handler = _handlerFactory.CreateHandler <THandler, TMessage>(message);

            handler.Execute(_socket, answerable);
        }
Exemple #2
0
        public TypedHandlerRegister WithHandler(ITypedHandler handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if (_handlerInstances.Contains(handler))
            {
                throw new InvalidOperationException(SR.HanderAlreadyExistsError);
            }

            _handlerInstances.Add(handler);

            WithAsyncSendingHandler <object, object>(handler.GetPriority(HandlerType.Sending), async ctx =>
            {
                if (handler.Enabled)
                {
                    await handler.OnSending(ctx);
                }
            });

            WithAsyncSentHandler <object>(handler.GetPriority(HandlerType.Sent), async ctx =>
            {
                if (handler.Enabled)
                {
                    await handler.OnSent(ctx);
                }
            });

            WithAsyncResultHandler <object>(handler.GetPriority(HandlerType.Result), async ctx =>
            {
                if (handler.Enabled)
                {
                    await handler.OnResult(ctx);
                }
            });

            WithAsyncErrorHandler <object>(handler.GetPriority(HandlerType.Error), async ctx =>
            {
                if (handler.Enabled)
                {
                    await handler.OnError(ctx);
                }
            });

            WithAsyncExceptionHandler(handler.GetPriority(HandlerType.Exception), async ctx =>
            {
                if (handler.Enabled)
                {
                    await handler.OnException(ctx);
                }
            });

            return(this);
        }
        public static IAdvancedHalBuilder WithHandler(this IAdvancedHalBuilder builder, ITypedHandler handler)
        {
            builder.WithConfiguration(b => b.WithHandler(handler));

            return(builder);
        }
        public static IAdvancedTypedBuilder WithHandler(this IAdvancedTypedBuilder builder, ITypedHandler handler)
        {
            builder.WithConfiguration(s => s.HandlerRegister.WithHandler(handler));

            return(builder);
        }