Beispiel #1
0
        private void CallHandler(Type ctrl, MethodInfo handler, Socket sock, DecodedMessage <byte[]> decoded)
        {
            var ctrlInstance = Activator.CreateInstance(ctrl);

            ctrl.GetMethod("SetContext").Invoke(ctrlInstance, new object[] { sock, decoded.Code });
            var castTo = handler.GetParameters().ElementAt(0).ParameterType;

            if (castTo != typeof(string))
            {
                var decodedPayload = MessageDecoder.DecodePayload(decoded.Payload, castTo);
                handler.Invoke(ctrlInstance, new object[] { decodedPayload, decoded.Auth });
            }
            else
            {
                var decodedPayload = MessageDecoder.DecodePayload(decoded.Payload);
                handler.Invoke(ctrlInstance, new object[] { decodedPayload, decoded.Auth });
            }
        }
Beispiel #2
0
        private void RouteRequest(Socket sock, DecodedMessage <byte[]> decoded)
        {
            var controllers = Assembly
                              .GetEntryAssembly()
                              .GetTypes()
                              .Where(t => !t.IsAbstract && !t.IsInterface && typeof(Controller).IsAssignableFrom(t));

            foreach (var ctrl in controllers)
            {
                var handler = ctrl
                              .GetMethods()
                              .Where(m => m.GetCustomAttribute <Handler>() != null)
                              .Where(m => m.GetCustomAttribute <Handler>().OperationId == decoded.Code)
                              .FirstOrDefault();

                if (handler == null)
                {
                    continue;
                }

                CallHandler(ctrl, handler, sock, decoded);
                break;
            }
        }
Beispiel #3
0
        public string Receive()
        {
            DecodedMessage <byte[]> response = Receiver.ReceiveMessage(Socket);

            return(MessageDecoder.DecodePayload(response.Payload));
        }
Beispiel #4
0
        public T Receive <T>() where T : class
        {
            DecodedMessage <byte[]> response = Receiver.ReceiveMessage(Socket);

            return(MessageDecoder.DecodePayload <T>(response.Payload));
        }