Пример #1
0
        public override void OnDataArrival(byte[] buffer)
        {
            Message message = SSyncCore.BuildMessage(buffer);

            if (!SSyncCore.HandleMessage(message, this))
            {
                if (OnMessageHandleFailed != null)
                {
                    OnMessageHandleFailed(message);
                }
            }
        }
Пример #2
0
        void SSyncClient_OnDataArrival(byte[] datas)
        {
            Message message = SSyncCore.BuildMessage(datas);

            if (SSyncCore.HandleMessage(message, this))
            {
                if (OnMessageReceived != null)
                {
                    OnMessageReceived(message);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Try to handle a message by finding an handler linked to this messae.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="client"></param>
        /// <returns>True if the message is handled, False if its not</returns>
        public static bool HandleMessage(Message message, SSyncClient client)
        {
            if (!Initialized)
            {
                throw new LibraryNotLoadedException("SSync Library is not initialized, call the method SSyncCore.Initialize() before launch sockets");
            }

            if (message == null)
            {
                if (SSyncCore.OnUnknowDataReceived != null)
                {
                    SSyncCore.OnUnknowDataReceived(client);
                }
                return(false);
            }

            var handler = Handlers.FirstOrDefault(x => x.Key == message.MessageId);

            if (handler.Value != null)
            {
                {
                    try
                    {
                        handler.Value.DynamicInvoke(null, message, client);
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        if (OnHandleFailed != null)
                        {
                            OnHandleFailed(message, ex);
                        }
                        return(false);
                    }
                }
            }
            else
            {
                if (OnMessageWithoutHandlerReceived != null)
                {
                    OnMessageWithoutHandlerReceived(message);
                }
                return(false);
            }
        }