void QcMessagner_ReciveCmd(object sender, QcMessagerCmdEventArg e)
        {
            switch (e.cmd.CmdType)
            {
            case QcProtocol.QcCommand.QcUpdateMsg:
                if (ReciveUpdateMsg != null)
                {
                    var msg = QcMsg.GetMsg(e.cmd.tokens(4));
                    ReciveUpdateMsg(this, new QcMessagerUpdateMsgEventArg(msg));
                }
                break;

            case QcProtocol.QcCommand.QcDataUpdate:
                string index = e.cmd.tokens(2) + "|" + e.cmd.tokens(1);

                //收到数据更新消息,进行更新
                //  QcLog.LogString(e.cmd.ToString());
                NodeChangeType type = NodeChangeType.Create;
                if (Enum.TryParse <NodeChangeType>(e.cmd.tokens(3), out type))
                {
                    switch (type)
                    {
                    case NodeChangeType.Create:

                        break;

                    case NodeChangeType.Update:
                        if (QcNode.lstNode.ContainsKey(index))
                        {
                            QcNode.lstNode[index].Refresh();
                        }
                        break;

                    case NodeChangeType.Delete:
                        if (QcNode.lstNode.ContainsKey(index))
                        {
                            QcNode.lstNode[index].RiseDelete();
                        }
                        break;
                    }
                    if (DataUpdate != null)
                    {
                        if (QcNode.lstNode.ContainsKey(index))
                        {
                            DataUpdate(this, new QcMessagerDataUpdateEventArg(QcNode.lstNode[index], type));
                        }
                        else
                        {
                            string tablename = e.cmd.tokens(2);
                            string code      = e.cmd.tokens(1);
                            string codefield = e.cmd.tokens(4);
                            QcNode node      = new QcNewNode(tablename, code, codefield);
                            node.InitFromString(e.cmd.tokens(5));
                            DataUpdate(this, new QcMessagerDataUpdateEventArg(node, type));
                        }
                    }
                }
                break;
            }
        }
Exemple #2
0
        void QcMessagner_ReciveCmd(object sender, QcCmdEventArgs e)
        {
            try
            {
                if (e.Cmd.CmdType == QcProtocol.QcCommand.Undefine)
                {
                    return;
                }
                QcMsgUser userfrom = null;
                if (lstUser.ContainsKey(e.Cmd.From))
                {
                    userfrom = lstUser[e.Cmd.From];
                }
                if (this.ReciveCmd != null)
                {
                    var cmdevt = new QcMessagerCmdEventArg()
                    {
                        cmd  = e.Cmd,
                        user = userfrom
                    };
                    this.ReciveCmd(this, cmdevt);
                }

                switch (e.Cmd.CmdType)
                {
                case QcProtocol.QcCommand.QcLoginReplay:
                    client.Send(QcCmd.MakeCmd(QcProtocol.QcCommand.QcListUser));
                    break;

                case QcProtocol.QcCommand.QcLoginOut:
                    if (userfrom != null)
                    {
                        userfrom.Chanel   = null;
                        userfrom.IsLinked = false;
                    }
                    if (this.Loginout != null)
                    {
                        if (userfrom != null)
                        {
                            this.Loginout(this, new QcMessagerLoginEventArg(userfrom));
                        }
                    }

                    break;

                case QcProtocol.QcCommand.QcMsg:
                    if (this.ReciveMsg != null)
                    {
                        var msgevt = new QcMessagerMsgEventArg(userfrom.Name, e.Cmd.tokens(3), e.Cmd.tokens(4));
                        this.ReciveMsg(this, msgevt);
                    }
                    break;

                case QcProtocol.QcCommand.QcSystemMsg:
                    if (this.ReciveSystemMsg != null)
                    {
                        var systemevt = new QcSystemMsgEventArg(e.Cmd.tokens(5), e.Cmd.From, e.Cmd.tokens(3), e.Cmd.tokens(4));
                        this.ReciveSystemMsg(this, systemevt);
                    }
                    break;

                case QcProtocol.QcCommand.QcUserLogin:
                    foreach (QcMsgUser u in lstUser.Values)
                    {
                        if (u.Name == userfrom.Name)
                        {
                            u.IsLinked = true;
                            break;
                        }
                    }


                    if (this.Logined != null)
                    {
                        this.Logined(this, new QcMessagerLoginEventArg(userfrom));
                    }
                    break;

                case QcProtocol.QcCommand.QcListUser:
                    var v = e.Cmd.tokens(1).Split(',');
                    foreach (var u in v)
                    {
                        if (lstUser.ContainsKey(u))
                        {
                            lstUser[u].Chanel = new QcChanel();
                        }
                    }
                    break;

                case QcProtocol.QcCommand.QcUpdateMsg:
                    if (ReciveUpdateMsg != null)
                    {
                        var msg = QcMsg.GetMsg(e.Cmd.tokens(4));
                        ReciveUpdateMsg(this, new QcMessagerUpdateMsgEventArg(msg));
                    }
                    break;

                case QcProtocol.QcCommand.QcDataUpdate:
                    string index = e.Cmd.tokens(2) + "|" + e.Cmd.tokens(1);

                    //收到数据更新消息,进行更新
                    //   QcLog.LogString(e.Cmd.ToString());
                    NodeChangeType type = NodeChangeType.Create;
                    if (Enum.TryParse <NodeChangeType>(e.Cmd.tokens(3), out type))
                    {
                        switch (type)
                        {
                        case NodeChangeType.Create:

                            break;

                        case NodeChangeType.Update:
                            if (QcNode.lstNode.ContainsKey(index))
                            {
                                QcNode.lstNode[index].Refresh();
                            }
                            break;

                        case NodeChangeType.Delete:
                            if (QcNode.lstNode.ContainsKey(index))
                            {
                                QcNode.lstNode[index].RiseDelete();
                            }
                            break;
                        }
                        if (DataUpdate != null)
                        {
                            if (QcNode.lstNode.ContainsKey(index))
                            {
                                DataUpdate(this, new QcMessagerDataUpdateEventArg(QcNode.lstNode[index], type));
                            }
                            else
                            {
                                string tablename = e.Cmd.tokens(2);
                                string code      = e.Cmd.tokens(1);
                                string codefield = e.Cmd.tokens(4);
                                QcNode node      = new QcNewNode(tablename, code, codefield);
                                node.InitFromString(e.Cmd.tokens(5));
                                DataUpdate(this, new QcMessagerDataUpdateEventArg(node, type));
                            }
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                QcLog.LogException("QcMessagner:", ex);
            }
        }