Beispiel #1
0
        public void XmppCon_OnIq(object sender, IQ iq)
        {
            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
                BeginInvoke(new IqHandler(XmppCon_OnIq), new object[] { sender, iq });
                return;
            }

            if (iq != null)
            {
                if (iq.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        CSS.IM.XMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)) as CSS.IM.XMPP.protocol.extensions.si.SI;

                        CSS.IM.XMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            if (!Util.ChatForms.ContainsKey(iq.From.Bare))//查看聊天窗口是否已经打开了
                            {
                                try
                                {
                                    Friend flfriend = listView_fd.Rosters[iq.From.Bare];
                                    string nickName = listView_fd.GetFriendNickName(iq.From.Bare);
                                    ChatFromMsg chatForm = new ChatFromMsg(iq.From, XmppCon, nickName);
                                    chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                    chatForm.Show();
                                    //chatForm.FileTransfer(iq);
                                    chatForm.Activate();
                                }
                                catch (Exception)
                                {

                                }
                            }
                            else
                            {

                            }

                        }
                    }
                }
                else
                {

                }
            }
        }
Beispiel #2
0
        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;
                    }
                    else if(msg.GetTag("subject") == "homepage")
                    {
                        Msg.MqMessage mqmsg = MessageBoxForm.MarkMessage_Mq(msg);
                        CSS.IM.UI.Util.Path.DefaultURL = mqmsg.Herf + "?url=" + mqmsg.Url + "&token=" + mqmsg.Token + "&loginname=" +XmppCon.Username +"&pwd=" + Base64.EncodeBase64(XmppCon.Password);

                       return;
                    }
                    else if (msg.GetTag("subject") == "window")
                    {
                        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,XmppCon.Username, XmppCon.Password);

                            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);
                        }
                        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, XmppCon.Username,XmppCon.Password);

                            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);
                                /**
                                 * 0、普通消息
                                 * 8、ftp离线文件
                                 * 9、对方拒绝接收主线文件
                                 * 11、接收到red的视频请求
                                 * */
                                if (msg.GetTagInt("m_type") == 0 || msg.GetTagInt("m_type") == 8 || msg.GetTagInt("m_type") == 9 || msg.GetTagInt("m_type") == 11)//如果为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;
                                    }
                                }

                                //MessageBox.Show("1");
                                Friend flfriend=null;
                                if (listView_fd.Rosters.Count > 0)
                                {
                                    try
                                    {
                                        flfriend = listView_fd.Rosters[msg.From.Bare];
                                    }
                                    catch (Exception)
                                    {
                                        flfriend = null;
                                    }

                                }
                                //MessageBox.Show("2");
                                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;

                                    //MessageBox.Show("3");
                                    string nickName = "";
                                    if (flfriend == null)
                                        nickName = msg.From.User;
                                    else
                                        nickName = listView_fd.GetFriendNickName(msg.From.Bare);

                                    //MessageBox.Show(nickName);

                                    ChatFromMsg chatForm = new ChatFromMsg(msg.From, XmppCon, nickName);
                                    try
                                    {
                                        chatForm.UpdateFriendOnline(flfriend==null?false: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);
                                        listView_fd.flickerFriend(new Jid(msg.From.Bare));

                                    }
                                    else
                                    {
                                        if (listView_fd.Rosters.ContainsKey(msg.From.Bare))
                                        {
                                            List<CSS.IM.XMPP.protocol.client.Message> msgs = new List<XMPP.protocol.client.Message>();
                                            msgs.Add(msg);
                                            msgBox.Add(msg.From.Bare.ToString(), msgs);
                                            listView_fd.flickerFriend(new Jid(msg.From.Bare));
                                            ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                            timer_MessageAlert.Enabled = true;
                                        }
                                        else
                                        {
                                            string nickName = listView_fd.GetFriendNickName(msg.From.Bare);
                                            ChatFromMsg chatForm = new ChatFromMsg(msg.From, XmppCon, nickName);
                                            try
                                            {
                                                chatForm.UpdateFriendOnline(flfriend.IsOnline==null?false: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 ex)
                            {
                                MessageBox.Show("系统错误,打开消息窗体失败,原因:"+ex.Message+"请联系软件开发商。");
                            }

                        }
                    }
                //}
            }
        }