示例#1
0
        private async void refreshRoom()
        {
            ParticipantList.Items.Clear();
            foreach (RoomParticipant par in newRoom.Participants)
            {
                GroupChatPlayer player = new GroupChatPlayer();
                player.SName.Content = par.Nick;
                PublicSummoner summoner = await Client.PVPNet.GetSummonerByName(par.Nick);

                var uriSource = System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", summoner.ProfileIconId + ".png");
                player.sIcon.Source = Client.GetImage(uriSource);
                ParticipantList.Items.Add(player);
                //add to ParticipantList
            }
            ParticipantList.Items.Refresh();
        }
示例#2
0
 private async void GroupChatClient_OnParticipantJoin(Room room, RoomParticipant participant)
 {
     await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() =>
     {
         TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd);
         tr.Text = participant.Nick + " joined the room." + Environment.NewLine;
         tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
         ChatText.ScrollToEnd();
         var x = new GroupChatPlayer();
         x.SName.Content = participant.Nick;
         PublicSummoner summoner = await Client.PVPNet.GetSummonerByName(participant.Nick);
         var uriSource = System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", summoner.ProfileIconId + ".png");
         x.sIcon.Source = Client.GetImage(uriSource);
         ParticipantList.Items.Add(x);
         ParticipantList.Items.Refresh();
     }));
 }
        async void XmppConnection_OnPresence(object sender, Presence pres)
        {
            if (pres.From.Bare != roomName)
                return;
                        
            if (pres.Type != PresenceType.available)
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    using (XmlReader reader = XmlReader.Create(new StringReader(pres.InnerXml)))
                    {
                        try
                        {
                            string jid = string.Empty;
                            while (reader.Read())
                            {
                                if (!reader.IsStartElement() || reader.IsEmptyElement)
                                    continue;

                                #region Parse Presence

                                switch (reader.Name)
                                {
                                    case "jid":
                                        reader.Read();
                                        jid = reader.Value;
                                        break;
                                }

                                #endregion Parse Presence
                            }
                            var user = Client.GetUserFromJid(jid);

                            var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                            {
                                Text = user + " left the room." + Environment.NewLine
                            };
                            tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
                           
                        }
                        catch (Exception e)
                        {
                            Client.Log(e.Message + " - remember to fix this later instead of avoiding the problem.");
                        }
                    }

                    ChatText.ScrollToEnd();
                    foreach (
                        var x in
                            from GroupChatPlayer x in ParticipantList.Items
                            where pres.From.User == (string)x.SName.Content
                            select x)
                    {
                        ParticipantList.Items.Remove(x);
                        ParticipantList.Items.Refresh();
                        break;
                    }
                }));
            }
            else
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                {
                    //ugly hack
                    var user = pres.From.Resource;
                    

                    int ProfileIcon = 0;
                    var x = new GroupChatPlayer();
                    bool exists = false;
                    foreach (var m in from GroupChatPlayer m in ParticipantList.Items where (m).SName.Content.ToString() == user select m)
                    {
                        x = m;
                        exists = true;
                    }
                    x.SName.Content = user;
                    if (pres.Status == null)
                        pres.Status = "<profileIcon>3</profileIcon>";
                    ProfileIcon = Regex.Split(pres.Status, "<profileIcon>")[1].Split(new[] { "</profileIcon>" }, StringSplitOptions.None)[0].ToInt();
                    
                    var UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon",
                        ProfileIcon + ".png");
                    x.SIcon.Source = Client.GetImage(UriSource);
                    if (!exists)
                    {
                        ParticipantList.Items.Add(x);
                        var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                        {
                            Text = user + " joined the room." + Environment.NewLine
                        };
                        tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
                    }

                    ParticipantList.Items.Refresh();
                }));
            }
            
        }
示例#4
0
        async void XmppConnection_OnPresence(object sender, Presence pres)
        {
            if (pres.From.Bare != roomName)
            {
                return;
            }

            if (pres.Type != PresenceType.available)
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    using (XmlReader reader = XmlReader.Create(new StringReader(pres.InnerXml)))
                    {
                        try
                        {
                            string jid = string.Empty;
                            while (reader.Read())
                            {
                                if (!reader.IsStartElement() || reader.IsEmptyElement)
                                {
                                    continue;
                                }

                                #region Parse Presence

                                switch (reader.Name)
                                {
                                case "jid":
                                    reader.Read();
                                    jid = reader.Value;
                                    break;
                                }

                                #endregion Parse Presence
                            }
                            var user = Client.GetUserFromJid(jid);

                            var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                            {
                                Text = user + " left the room." + Environment.NewLine
                            };
                            tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
                        }
                        catch (Exception e)
                        {
                            Client.Log(e.Message + " - remember to fix this later instead of avoiding the problem.");
                        }
                    }

                    ChatText.ScrollToEnd();
                    foreach (
                        var x in
                        from GroupChatPlayer x in ParticipantList.Items
                        where pres.From.User == (string)x.SName.Content
                        select x)
                    {
                        ParticipantList.Items.Remove(x);
                        ParticipantList.Items.Refresh();
                        break;
                    }
                }));
            }
            else
            {
                await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() =>
                {
                    //ugly hack
                    var user = pres.From.Resource;


                    int ProfileIcon = 0;
                    var x = new GroupChatPlayer();
                    bool exists = false;
                    foreach (var m in from GroupChatPlayer m in ParticipantList.Items where (m).SName.Content.ToString() == user select m)
                    {
                        x = m;
                        exists = true;
                    }
                    x.SName.Content = user;
                    if (pres.Status == null)
                    {
                        pres.Status = "<profileIcon>3</profileIcon>";
                    }
                    ProfileIcon = Regex.Split(pres.Status, "<profileIcon>")[1].Split(new[] { "</profileIcon>" }, StringSplitOptions.None)[0].ToInt();

                    var UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon",
                                                 ProfileIcon + ".png");
                    x.SIcon.Source = Client.GetImage(UriSource);
                    if (!exists)
                    {
                        ParticipantList.Items.Add(x);
                        var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd)
                        {
                            Text = user + " joined the room." + Environment.NewLine
                        };
                        tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
                    }

                    ParticipantList.Items.Refresh();
                }));
            }
        }