private static RequestHandlerDelegate ForRequest4 <T, TParams, TResult, TResponseError>(Type targetType, MethodInfo method, HandlerProvider provider)
            where TResponseError : ResponseError, new()
        {
            Type deleType = typeof(Func <T, TParams, Result <TResult, TResponseError> >);
            Func <T, TParams, Result <TResult, TResponseError> > func = (Func <T, TParams, Result <TResult, TResponseError> >)method.CreateDelegate(deleType);

            return((r, c, t) =>
            {
                RequestMessage <TParams> request = (RequestMessage <TParams>)r;
                object target = provider.CreateTargetObject(targetType, c, t);
                Result <TResult, TResponseError> result;
                try
                {
                    result = func((T)target, request.Params);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                    result = Result <TResult, TResponseError> .Error(Message.InternalError <TResponseError>());
                }

                return new ResponseMessage <TResult, TResponseError>
                {
                    Id = request.Id,
                    Result = result.SuccessValue,
                    Error = result.ErrorValue
                };
            });
        }
Beispiel #2
0
        private static RequestHandlerDelegate ForRequest2 <T, TResponseError>(Type targetType, MethodInfo method, HandlerProvider provider)
            where TResponseError : ResponseError, new()
        {
            var deleType = typeof(Func <T, VoidResult <TResponseError> >);
            var func     = (Func <T, VoidResult <TResponseError> >)method.CreateDelegate(deleType);

            return((r, c, t) =>
            {
                var request = (VoidRequestMessage)r;
                var target = provider.CreateTargetObject(targetType, c, t);
                VoidResult <TResponseError> result;
                try
                {
                    result = func((T)target);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                    result = VoidResult <TResponseError> .Error(Message.InternalError <TResponseError>());
                }
                return new VoidResponseMessage <TResponseError>
                {
                    id = request.id,
                    error = result.ErrorValue
                };
            });
        }
        private static NotificationHandlerDelegate ForNotification1 <T>(Type targetType, MethodInfo method, HandlerProvider provider)
        {
            Type       deleType = typeof(Action <T>);
            Action <T> action   = (Action <T>)method.CreateDelegate(deleType);

            return((n, c) =>
            {
                VoidNotificationMessage notification = (VoidNotificationMessage)n;
                object target = provider.CreateTargetObject(targetType, c);
                try
                {
                    action((T)target);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                }
            });
        }
Beispiel #4
0
        private static NotificationHandlerDelegate ForNotification2 <T, TParams>(Type targetType, MethodInfo method, HandlerProvider provider)
        {
            var deleType = typeof(Action <T, TParams>);
            var action   = (Action <T, TParams>)method.CreateDelegate(deleType);

            return((n, c) =>
            {
                var notification = (NotificationMessage <TParams>)n;
                var target = provider.CreateTargetObject(targetType, c);
                try
                {
                    action((T)target, notification.@params);
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                }
            });
        }