public void XmppCon_OnMessage(object sender, CSS.IM.XMPP.protocol.client.Message msg)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                Invoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // Dont handle GroupChat Messages here, they have their own callbacks in the
            // GroupChat Form
            if (msg.Type == MessageType.groupchat)
            {
                //Debug.WriteLine("创建聊天室发送了消息:"+msg.Body);
                return;
            }
            if (msg.Type == MessageType.error)
            {
                //Handle errors here
                // we dont handle them in this example
                return;
            }
            //if (msg.Type == MessageType.normal)
            //{
            //    filename = msg.Body;
            //    Debug.WriteLine(msg.ToString());
            //    return;
            //}

            // check for xData Message

            if (msg.HasTag(typeof(Data)))//如果是文件
            {
                Element e = msg.SelectSingleElement(typeof(Data));
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    //frmXData fXData = new frmXData(xdata);
                    //fXData.Text = "xData Form from " + msg.From.ToString();
                    //fXData.Show();
                }
            }
            else if (msg.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.ibb.Data)))
            {
                // ignore IBB messages
                return;
            }
            else
            {
                if (msg.Body != null)
                {
                    if (msg.GetTag("subject") == "notify")//xu
                    {
                        filename = msg.Body;
                        return;
                    }
                    if (msg.From.ToString() == msg.From.Server)
                    {
                        if (CSS.IM.UI.Util.Path.ReveiveSystemNotification)//是否接收服务器消息
                        {
                            if (CSS.IM.UI.Util.Path.SystemSwitch)
                                SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.SystemPath);

                            MessageBoxForm sBox = new MessageBoxForm("系统通知", msg);
                            try
                            {
                                sBox.TopMost = true;
                                sBox.Show();
                            }
                            catch (Exception)
                            {

                            }

                            string sqlstr = "insert into MessageLog (Belong,MessageType,MessageLog,[DateNow]) values ({0},{1},{2},{3})";
                            sqlstr = String.Format(sqlstr,
                                "'" + XmppCon.MyJID.Bare.ToString() + "'",
                                "'0'",
                                "'" + msg.ToString() + "'",
                                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);
                        }
                    }
                    else
                    {
                        if (!Util.ChatForms.ContainsKey(msg.From.Bare))//查看聊天窗口是否已经打开了
                        {

                            //RosterNode rn = rosterControl.GetRosterItem(msg.From);
                            //string nick = msg.From.Bare;
                            //if (rn != null)
                            //    nick = rn.Text;
                            try
                            {
                                //string sqlstr = "insert into ChatMessageLog (Jid,[MessageLog],[DateNow])values ({0},{1},{2})";
                                //sqlstr = String.Format(sqlstr,
                                //    "'" + msg.From.Bare.ToString() + "'",
                                //    "'" + msg.ToString() + "'",
                                //     "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                                //CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

                                if (msg.GetTagInt("m_type") == 0)//如果为0就是正常消息,就播放声音
                                {
                                    if (CSS.IM.UI.Util.Path.MsgSwitch)
                                        SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);
                                }
                                else//代码进入到这里,说明,聊天的窗口已经关闭,接收到属于聊天窗口里面的业务不做处理
                                {
                                    //6发图片
                                    //1接收视频

                                    if (!(msg.GetTagInt("m_type")==6||msg.GetTagInt("m_type")==1))
                                    {
                                        return;
                                    }
                                }

                                Friend flfriend = friendListView.Rosters[msg.From.User];

                                if (CSS.IM.UI.Util.Path.ChatOpen)
                                {
                                    //friendListView.flickerFriend(new Jid(msg.From.Bare));
                                    //ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                    //timer_notifyIco.Enabled = true;

                                    ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                    try
                                    {
                                        chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                        chatForm.Show();
                                        chatForm.Activate();
                                        chatForm.IncomingMessage(msg);
                                    }
                                    catch (Exception)
                                    {

                                    }

                                }
                                else
                                {
                                    if (msgBox.ContainsKey(msg.From.Bare.ToString()))
                                    {
                                        List<CSS.IM.XMPP.protocol.client.Message> msgs = msgBox[msg.From.Bare.ToString()];
                                        msgs.Add(msg);
                                        msgBox.Remove(msg.From.Bare.ToString());
                                        msgBox.Add(msg.From.Bare.ToString(), msgs);
                                        friendListView.flickerFriend(new Jid(msg.From.Bare));

                                    }
                                    else
                                    {
                                        if (friendListView.Rosters.ContainsKey(msg.From.User))
                                        {
                                            List<CSS.IM.XMPP.protocol.client.Message> msgs = new List<XMPP.protocol.client.Message>();
                                            msgs.Add(msg);
                                            msgBox.Add(msg.From.Bare.ToString(), msgs);
                                            friendListView.flickerFriend(new Jid(msg.From.Bare));
                                            ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                            timer_notifyIco.Enabled = true;
                                        }
                                        else
                                        {
                                            ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                            try
                                            {
                                                chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                                chatForm.Show();
                                                chatForm.Activate();
                                                chatForm.IncomingMessage(msg);
                                            }
                                            catch (Exception)
                                            {

                                            }

                                        }

                                        //Friend item=friendListView.Rosters[msg.From.Bare.ToString()];
                                    }
                                }

                                //ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                //chatForm.Show();
                                //chatForm.IncomingMessage(msg);
                            }
                            catch (Exception)
                            {
                                //MessageBox.Show(ex.Message);
                            }

                        }
                    }
                }
            }
        }