Exemplo n.º 1
0
        /// <summary>
        /// We received a message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msg"></param>
        private void XmppCon_OnMessage(object sender, agsXMPP.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
                BeginInvoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // check for xData Message
            Element e = msg.SelectSingleElement(typeof(Data));

            if (e != null)
            {
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    // This is not supported by the WM5 MiniClient sample
                }
            }
            else
            {
                if (msg.Type == MessageType.chat)
                {
                    if (!Util.Forms.ContainsKey(msg.From.Bare))
                    {
                        ListViewItem itm  = FindRosterListViewItem(msg.From);
                        string       nick = itm == null ? msg.From.Bare : itm.Text;

                        frmChat f = new frmChat(msg.From, XmppCon, nick);
                        f.Show();
                        f.IncomingMessage(msg);
                    }
                }
                else if (msg.Type == MessageType.normal)
                {
                    frmMsg fMsg = new frmMsg(msg);
                    fMsg.Show();
                }
                else if (msg.Type == MessageType.headline)
                {
                    // not handeled in this example
                }
            }
        }
Exemplo n.º 2
0
 private void _connection_OnMessage(object sender, Message msg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new OnMessageDelegate(_connection_OnMessage), new[] { sender, msg });
         return;
     }
     if (msg.Type == MessageType.groupchat)
     {
         return;
     }
     if (msg.Type == MessageType.error)
     {
         return;
     }
     if (msg.HasTag(typeof(Data)))
     {
         Element e     = msg.SelectSingleElement(typeof(Data));
         Data    xdata = e as Data;
         if (xdata != null && xdata.Type == XDataFormType.form)
         {
             //TODO:xdata
         }
     }
     else if (msg.HasTag(typeof(agsXMPP.protocol.extensions.ibb.Data)))
     {
     }
     else
     {
         if (msg.Body != null)
         {
             RibbonFormChat formChat = null;
             if (Util.ChatFormHashtable.Contains(msg.From.Bare))
             {
                 formChat = (RibbonFormChat)Util.ChatFormHashtable[msg.From.Bare];
             }
             else
             {
                 formChat = new RibbonFormChat(_connection, msg.From, msg.From.User);
             }
             formChat.Show();
             formChat.IncomingMessage(msg);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// We received a message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msg"></param>
        private void XmppCon_OnMessage(object sender, agsXMPP.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
                BeginInvoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // check for xData Message
            Element e = msg.SelectSingleElement(typeof(Data));

            if (e != null)
            {
                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 (!Util.Forms.ContainsKey(msg.From.Bare))
                {
                    ListViewItem itm  = FindRosterListViewItem(msg.From);
                    string       nick = itm == null ? msg.From.Bare : itm.Text;

                    frmChat f = new frmChat(msg.From, XmppCon, nick);
                    f.Show();
                    f.IncomingMessage(msg);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Handle incomming messages
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="message"></param>
 private void OnMessage(object sender, Message message)
 {
     if (!message.HasTag("event"))
     {
         return;
     }
     // Check for the activity changed data, see here: https://github.com/swissmanu/harmonyhubjs-client/blob/master/docs/protocol/startActivityFinished.md
     var eventElement = message.SelectSingleElement("event");
     var eventData = eventElement.GetData();
     if (eventData == null)
     {
         return;
     }
     foreach (var pair in eventData.Split(':'))
     {
         if (!pair.StartsWith("activityId"))
         {
             continue;
         }
         var activityId = pair.Split('=')[1];
         OnActivityChanged?.Invoke(this, activityId);
     }
 }
Exemplo n.º 5
0
    static void Xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
    {
        if (msg.HasTag(typeof(AgIXML)))
        {
            AgIXML agiMsg = msg.SelectSingleElement(typeof(AgIXML)) as AgIXML;
            agiMsg newMsg = new agiMsg();
            newMsg.ID         = agiMsg.ID;
            newMsg.Type       = agiMsg.Type;
            newMsg.Path       = agiMsg.Path;
            newMsg.SessionID  = agiMsg.SessionID;
            newMsg.SessionKey = agiMsg.SessionKey;
            newMsg.Data       = agiMsg.Data;
            newMsg.Flags      = agiMsg.Flags;

            switch (newMsg.Type)
            {
            case "tput":
                xmppManager.world.agi.tput(newMsg);
                break;

            case "rput":
                xmppManager.world.agi.rput(newMsg);
                break;

            case "tget":
                xmppManager.world.agi.tget(newMsg);
                break;

            case "rget":
                xmppManager.world.agi.rget(newMsg);
                break;

            case "tattach":
                xmppManager.world.agi.tattach(newMsg);
                break;

            case "rattach":
                xmppManager.world.agi.rattach(newMsg);
                break;

            case "tremove":
                xmppManager.world.agi.tremove(newMsg);
                break;

            case "rremove":
                xmppManager.world.agi.rremove(newMsg);
                break;

            case "tflush":
                xmppManager.world.agi.tflush(newMsg);
                break;

            case "rflush":
                xmppManager.world.agi.rflush(newMsg);
                break;
            }
        }

        if (msg.Body != null)
        {
            messages newMsg = new messages();
            newMsg.body = msg.Body;
            newMsg.from = msg.From.User;

            int count = 0;

            while (chats.Count != 0 && count < chats.Count)
            {
                if (chats.ElementAt(count).chatWith.userID == msg.From.User)
                {
                    chats.ElementAt(count).msgChain.Add(newMsg);
                    return;
                }
                count++;
            }

            chat newchat = new chat();
            newchat.msgChain.Add(newMsg);
            newchat.chatWith.userID = msg.From.User.ToString();
            chats.Add(newchat);
            Console.WriteLine(newMsg.body.ToString());
        }
    }