public void ResetTest()
        {
            var sc  = new SmartCollection <TestItem, object>(new object());
            var si1 = new TestItem();
            var si2 = new TestItem();
            var si3 = new TestItem();

            sc.Add(si1);
            si2.Collection = sc;
            sc.Add(si3);

            Assert.AreEqual(sc, si1.Collection);
            Assert.AreEqual(sc, si2.Collection);
            Assert.AreEqual(sc, si3.Collection);

            Assert.IsTrue(sc.Contains(si1));
            Assert.IsTrue(sc.Contains(si2));
            Assert.IsTrue(sc.Contains(si3));

            sc.Clear();

            Assert.AreEqual(null, si1.Collection);
            Assert.AreEqual(null, si2.Collection);
            Assert.AreEqual(null, si3.Collection);

            Assert.IsFalse(sc.Contains(si1));
            Assert.IsFalse(sc.Contains(si2));
            Assert.IsFalse(sc.Contains(si3));
        }
示例#2
0
 private void clear()
 {
     BackgroundTrackRepository.Clear();
     _playlist.Clear();
     _nonShuffledPlaylist?.Clear();
     _index      = 0;
     _isShuffled = false;
 }
示例#3
0
        private void clear()
        {
#if !Windows10
            BackgroundTrackRepository.Clear();
#endif
            _playlist.Clear();
            _nonShuffledPlaylist?.Clear();
            _index      = 0;
            _isShuffled = false;
        }
示例#4
0
        public async Task ResetCollection()
        {
            await Locator.MediaPlaybackViewModel.PlaybackService.BackgroundTrackRepository.Clear();

            Playlist.Clear();
            CurrentMedia = -1;
            NonShuffledPlaylist?.Clear();
            IsShuffled = false;
            Playback_MediaSet(null);
            IsRunning = false;
        }
示例#5
0
        private void ReadRawMessage(string rawMessage)
        {
            if (String.IsNullOrWhiteSpace(rawMessage))
            {
                return;
            }

            lock ( lockRawMessage )
            {
                const string jsonArgsRe = @".*args"":\[""(.*?)""\]}$";

                if (rawMessage.Equals("1::"))
                {
                    Chat.Status.IsConnected = true;
                }
                else if (rawMessage.Equals("2::"))
                {
                    Thread.Sleep(random.Next(100, 1000));
                    webSocket.Send("2::");
                    return;
                }

                if (rawMessage.Contains(@":""message"))
                {
                    var json = Re.GetSubString(rawMessage, jsonArgsRe);
                    if (json == null)
                    {
                        return;
                    }

                    dynamic msg = this.With(x => JToken.Parse(json.Replace(@"\""", @"""").Replace(@"\\", @"\")))
                                  .With(x => x.Value <dynamic>("params"));

                    if (msg == null)
                    {
                        return;
                    }

                    if (rawMessage.Contains(@":\""loginMsg"))
                    {
                        timerEveryMinute.Change(500, 60000);

                        var role = (string)msg.role;
                        switch (role.ToLower())
                        {
                        case "guest":
                            if (!Chat.IsAnonymous)
                            {
                                Chat.Status.IsLoggedIn = false;
                                if (!Chat.Status.IsLoginFailed)
                                {
                                    Chat.Status.IsConnected   = false;
                                    Chat.Status.IsLoggedIn    = false;
                                    Chat.Status.IsLoginFailed = true;
                                    Chat.Status.IsStarting    = false;
                                    Chat.Config.SetParameterValue("AuthToken", String.Empty);
                                    Chat.Restart();
                                }
                            }
                            else
                            {
                                Chat.Status.IsLoginFailed = false;
                            }

                            break;

                        case "admin":
                        {
                            Chat.Status.IsLoggedIn    = true;
                            Chat.Status.IsLoginFailed = false;
                        }
                        break;

                        case "anon":
                        {
                            Chat.Status.IsLoggedIn    = true;
                            Chat.Status.IsLoginFailed = false;
                        }
                        break;

                        default:
                            break;
                        }
                        var authToken = Chat.Config.GetParameterValue("AuthToken") as string;
                        SendCredentials(Chat.NickName, ChannelName, authToken);
                    }
                    else if (rawMessage.Contains(@":\""chatMsg"))
                    {
                        var nickName = (string)msg.name;
                        var text     = (string)msg.text;

                        if (String.IsNullOrWhiteSpace(nickName) || String.IsNullOrWhiteSpace(text))
                        {
                            return;
                        }

                        if (ReadMessage != null)
                        {
                            ReadMessage(new ChatMessage()
                            {
                                Channel         = ChannelName,
                                ChatIconURL     = Chat.IconURL,
                                ChatName        = Chat.ChatName,
                                FromUserName    = nickName,
                                HighlyImportant = false,
                                IsSentByMe      = false,
                                Text            = text
                            });
                        }
                    }
                    else if (rawMessage.Contains(@":\""userList"))
                    {
                        var data         = msg.data;
                        var guestsNumber = this.With(x => data.Guests as JArray).With(x => x.ToObject <string[]>());
                        var admins       = this.With(x => data.admin as JArray).With(x => x.ToObject <string[]>());
                        var moderators   = this.With(x => data.user as JArray).With(x => x.ToObject <string[]>());
                        var users        = this.With(x => data.anon as JArray).With(x => x.ToObject <string[]>());
                        var followers    = this.With(x => data.isFollower as JArray).With(x => x.ToObject <string[]>());
                        var subscribers  = this.With(x => data.isSubscriber as JArray).With(x => x.ToObject <string[]>());
                        var staff        = this.With(x => data.isStaff as JArray).With(x => x.ToObject <string[]>());

                        currentUserList.Clear();
                        foreach (var pair in new Dictionary <string, string[]> {
                            { "Staff", staff },
                            { "Admins", admins },
                            { "Moderators", moderators },
                            { "Subscribers", subscribers },
                            { "Followers", followers },
                            { "Users", users }
                        })
                        {
                            if (pair.Value == null)
                            {
                                continue;
                            }

                            foreach (string userNickname in pair.Value)
                            {
                                currentUserList.Add(new ChatUser()
                                {
                                    Channel   = ChannelName,
                                    ChatName  = Chat.ChatName,
                                    GroupName = pair.Key,
                                    NickName  = userNickname,
                                    Badges    = null,
                                });
                            }
                        }
                        var oldUserList = (Chat as IChatUserList).ChatUsers;

                        //Delete disconnected users
                        UI.Dispatch(() => {
                            oldUserList.ToList().Where(item => item.Channel.Equals(ChannelName) && item.ChatName.Equals(Chat.ChatName))
                            .Except(currentUserList, new LambdaComparer <ChatUser>((x, y) => x.NickName.Equals(y.NickName)))
                            .ToList()
                            .ForEach(item => oldUserList.Remove(item));
                        });
                        var newUserList = currentUserList
                                          .Where(item => item.Channel.Equals(ChannelName) && item.ChatName.Equals(Chat.ChatName))
                                          .Except(oldUserList, new LambdaComparer <ChatUser>((x, y) => x.NickName.Equals(y.NickName)))
                                          .ToList();

                        lock (chatUsersLock)
                            (Chat as IChatUserList).ChatUsers.AddRange(newUserList);
                        newUserList = null;
                    }
                }
            }
        }
示例#6
0
 public void Load(IEnumerable <SmileItem> smiles)
 {
     _items.Clear();
     _items.AddRange(smiles);
 }