Exemple #1
0
        public async Task ReceiveMessage(WebSocketMessage msg)
        {
            if (onMessageReceived != null)
            {
                await onMessageReceived(msg);
            }

            if (MethodCalls != null)
            {
                var method = MethodCalls.SingleOrDefault(m => m.GetCustomAttribute <WebSocketCallAttribute>().Name == msg.Method);
                if (method != null)
                {
                    try
                    {
                        var instance = CallInstances.FirstOrDefault(c =>
                        {
                            return(c.GetType() == method.DeclaringType);
                        });
                        await(Task) method.Invoke(instance, new object[] { msg });
                    }
                    catch (Exception e)
                    {
                        if (logger != null)
                        {
                            await logger.LogError(e, $"An error occurated when trying to invoke {method.Name} WebSocketCall");
                        }
                    }
                }
            }
        }