コード例 #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="WampRequestMapper{TMessage}"/>
        /// </summary>
        /// <param name="type">The type to map WAMP requests its methods.</param>
        /// <param name="formatter">A <see cref="IWampFormatter{TMessage}"/> used
        /// to check if a parameter can be binded to given type.</param>
        public WampRequestMapper(Type type, IWampFormatter <TMessage> formatter)
        {
            mFormatter = formatter;
            mMapping   = BuildMapping(type);

            mMissingMethod = FindMissingMethod(type);
        }
コード例 #2
0
        private Func <object, object[], object> BuildAction(WampMethodInfo wampMethod)
        {
            Func <object, object[], object> method =
                MethodInvokeGenerator.CreateInvokeMethod(wampMethod.Method);

            return(method);
        }
コード例 #3
0
 private bool CanBind(WampMethodInfo wampMethodInfo, TMessage[] arguments)
 {
     return(wampMethodInfo.Method.GetParameters()
            .Where(x => !x.IsDefined(typeof(WampProxyParameterAttribute), true))
            .Zip(arguments, (parameterInfo, argument) => new { parameterInfo, argument })
            .All(x => mFormatter.CanConvert(x.argument, x.parameterInfo.ParameterType)));
 }
コード例 #4
0
        private object[] ConvertArguments(WampMessage <TMessage> message, WampMethodInfo method)
        {
            ParameterInfo[] parametersList = method.ParametersToConvert;

            TMessage[] arguments = message.Arguments;

            IEnumerable <TMessage> relevantArguments = arguments;

            if (method.HasParamsArgument)
            {
                relevantArguments = relevantArguments.Take(parametersList.Length - 1);
            }

            List <object> converted =
                parametersList.Zip(relevantArguments,
                                   (parameter, argument) =>
                                   DeserializeArgument(parameter, argument))
                .ToList();

            if (method.HasParamsArgument)
            {
                IEnumerable <TMessage> otherArgumets =
                    arguments.Skip(parametersList.Length - 1);

                converted.Add(otherArgumets.ToArray());
            }

            return(converted.ToArray());
        }
コード例 #5
0
        public Action <TClient, WampMessage <TMessage> > BuildMethod(WampMethodInfo wampMethod)
        {
            Func <object, object[], object> action = BuildAction(wampMethod);

            return((client, message) =>
            {
                object[] arguments = GetArguments(client, message, wampMethod);
                object instance = GetInstance(client, message, wampMethod);
                action(instance, arguments);
            });
        }
コード例 #6
0
        private object[] InnerGetArguments(TClient client, WampMessage <TMessage> message, WampMethodInfo method)
        {
            List <object> methodArguments = new List <object>(method.TotalArgumentsCount);

            if (method.HasWampClientArgument)
            {
                methodArguments.Add(client);
            }

            if (method.IsRawMethod)
            {
                methodArguments.Add(message);
            }
            else
            {
                methodArguments.AddRange
                    (ConvertArguments(message, method));
            }

            return(methodArguments.ToArray());
        }
コード例 #7
0
 protected virtual object[] GetArguments(TClient client, WampMessage <TMessage> message, WampMethodInfo method)
 {
     return(InnerGetArguments(client, message, method));
 }
コード例 #8
0
 // Maybe these should be in a seperated interface.
 protected virtual object GetInstance(TClient client, WampMessage <TMessage> message, WampMethodInfo method)
 {
     return(mInstance);
 }