Esempio n. 1
0
        public async Task Execute(JsonGameSyncPackage package, WebSocketConnection connection)
        {
            var controller = Get(package, connection);

            if (null == controller)
            {
                throw new NullReferenceException(string.Format("Controller with type {0} not found"));
            }

            var methodInfo = controller.GetType().GetTypeInfo().DeclaredMethods
                             .Where(method => method.IsPublic && method.ReturnType == typeof(Task) && method.Name == package.Action)
                             .Select(method => new { method, parameters = method.GetParameters() })
                             .SingleOrDefault(p => p.parameters.Count() == 1);

            if (null == methodInfo)
            {
                throw new InvalidOperationException(string.Format("No suitable action {0} found in controller {1}. The method must be public and return Task.", package.Action, controller.GetType().Name));
            }
            var param = package.Payload.ToObject(methodInfo.parameters[0].ParameterType);

            await(Task) methodInfo.method.Invoke(controller, new object[] { param });
        }
Esempio n. 2
0
 public ConnectionService(WebSocketConnection connection)
 {
     _connection = connection;
 }