Ejemplo n.º 1
0
        public override string ParseLine(string msg)
        {
            if (!string.IsNullOrEmpty(msg))
            {
                try
                {
                    Regex           rg      = new Regex(pattern, RegexOptions.Compiled);
                    MatchCollection matches = rg.Matches(msg);

                    if (matches.Count > 0)
                    {
                        string code = matches[0].Groups["code"].Value;

                        if (StreamConstants.NEW_MESSAGE.Equals(code))
                        {
                            return(matches[0].Groups["msg"].Value);
                        }
                        else if (StreamConstants.HEAT_BEAT.Equals(code))
                        {
                            msgListener.OnHeartBeat();
                        }
                        else if (StreamConstants.CONNECT_REACH_MAX_TIME.Equals(code))
                        {
                            msgListener.OnConnectReachMaxTime();
                            WakeUp(code);
                        }
                        else if (StreamConstants.DISCARD_MESSAGE.Equals(code))
                        {
                            msgListener.OnDiscardMsg(matches[0].Groups["msg"].Value.ToString());
                        }
                        else if (StreamConstants.SERVER_DEPLOY.Equals(code))
                        {
                            msgListener.OnServerUpgrade(matches[0].Groups["msg"].Value.ToString());
                            WakeUp(code);
                        }
                        else if (StreamConstants.SERVER_REHASH.Equals(code))
                        {
                            msgListener.OnServerRehash();
                            WakeUp(code);
                        }
                        else if (StreamConstants.CLIENT_KICKOFF.Equals(code))
                        {
                            msgListener.OnClientKickOff();
                            WakeUp(code);
                        }
                        else if (StreamConstants.SERVER_KICKOFF.Equals(code))
                        {
                            msgListener.OnServerKickOff();
                            WakeUp(code);
                        }
                        else if (StreamConstants.CONNECT_SUCCESS.Equals(code))
                        {
                            msgListener.OnConnectMsg(matches[0].Groups["msg"].Value);
                        }
                        else
                        {
                            msgListener.OnOtherMsg(matches[0].Groups["msg"].Value);
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.Error("Message is invalid:" + msg + e.Message);
                    msgListener.OnException(e);
                    return(null);
                }
            }
            return(null);
        }