コード例 #1
0
        public async void SendChat()
        {
            await staticData.Xmpp.sendChatMsgAsync(MW.MessageTx, staticData.Username, MW.ReceiverTx);

            var msgW = staticData.ChatHeads.Find(x => x.receiver == MW.ReceiverTx);

            if (msgW == null)
            {
                msgW          = new MsgWindow();
                msgW.Text     = "Chat - " + MW.ReceiverTx;
                msgW.receiver = MW.ReceiverTx;
                msgW.sender   = staticData.Username;
                staticData.ChatHeads.Add(msgW);
                msgW.Show();
            }
            msgW.MsgB = "You:    " + MW.MessageTx;
            msgW.MsgB = Environment.NewLine;
            if (msgW.Visible == false)
            {
                msgW.Show();
            }
        }
コード例 #2
0
        public void deserializeXml(string str)
        {
            str = "<nesting>" + str + "</nesting>";
            XmlSerializer ser    = new XmlSerializer(typeof(nesting));
            TextReader    reader = new StringReader(str);
            var           Reads  = XmlReader.Create(reader);

            try
            {
                nesting chal = (nesting)ser.Deserialize(Reads);
                if (chal.message != null)
                {
                    foreach (var chall in chal.message)
                    {
                        MW.Invoke(new MethodInvoker(() =>
                        {
                            if (chall.type == "error")
                            {
                                staticData.ChatHeads.Find(x => x.receiver == chall.from.Substring(0, chall.from.LastIndexOf('@'))).Close();
                                MessageBox.Show("The user does not excist", "No user", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            if (chall.delay != null)
                            {
                                chall.body = "(Delayed " + (Int32)((DateTime.Now - chall.delay.stamp).TotalMinutes - 180) + " minutes ago)   " + chall.body;
                            }
                            var msgW = staticData.ChatHeads.Find(x => x.receiver == chall.from.Substring(0, chall.from.LastIndexOf('@')));
                            if (msgW == null)
                            {
                                msgW          = new MsgWindow();
                                msgW.Text     = "Chat - " + chall.from.Substring(0, chall.from.LastIndexOf('@'));
                                msgW.receiver = chall.from.Substring(0, chall.from.LastIndexOf('@'));
                                msgW.sender   = staticData.Username;
                                staticData.ChatHeads.Add(msgW);
                                msgW.Show();
                            }
                            msgW.MsgB = msgW.receiver + ":    " + chall.body;
                            msgW.MsgB = Environment.NewLine;
                            if (msgW.Visible == false)
                            {
                                msgW.Show();
                            }
                        }));
                    }
                }
                if (chal.iq != null)
                {
                    foreach (var chall in chal.iq)
                    {
                        MW.Invoke(new MethodInvoker(() =>
                        {
                            if (chall.error != null)
                            {
                                return;
                            }
                            if (chall.query != null && chall.id == "roster-1")
                            {
                                friends.Clear();
                                MW.list.Items.Clear();
                                if (chall.query.item != null)
                                {
                                    foreach (var item in chall.query.item)
                                    {
                                        var name = item.jid.Substring(0, item.jid.LastIndexOf('@'));
                                        friends.Add(name);
                                        MW.list.Items.Add(name);
                                        MW.list.Refresh();
                                    }
                                }
                            }
                        }));
                    }
                }
            }
            catch
            {
                Console.WriteLine("Unrecognized XML stanza");
            }
        }
コード例 #3
0
 public MessagePresenter(MsgWindow MW)
 {
     this.MW = MW;
 }