コード例 #1
0
        private void OnMessage(object data)
        {
            Debug.WriteLine("Message");

            string packedMessage = data as string;

            if (packedMessage != null)
            {
                try
                {
                    bool    handled = false;
                    Message message = MessageUtils.GetMessage(packedMessage);

                    MessageKey messageKey = MessageUtils.GetMessageKey(packedMessage);
                    if (messageKey != null)
                    {
                        lock (this.handlersLock)
                        {
                            EventHandler <MessageEventArgs> handler;
                            if (this.handlers.TryGetValue(messageKey, out handler))
                            {
                                handler(this, new MessageEventArgs((Message)message.Clone()));
                                handled = true;
                            }
                        }
                    }

                    if (!handled)
                    {
                        this.OnNonHandledMessage(new MessageEventArgs((Message)message.Clone()));
                        Debug.WriteLine(message);
                    }
                }
                catch (MalformedMessageException ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }