示例#1
0
 public void DeleteFromGridMethod(object obj)
 {
     if ((obj is RequestRich))
     {
         RequestRich dedicationRequest = obj as RequestRich;
         for (int z1 = 0; z1 < RichRequestObservable.Count; z1++)
         {
             if (dedicationRequest.Id == RichRequestObservable[z1].Id)
             {
                 RichRequestObservable.RemoveAt(z1);
             }
         }
     }
 }
示例#2
0
        public void GetCurrentSong()
        {
            Task.Run(async() =>
            {
                while (true)
                {
                    try
                    {
                        string playlistPath = VdjDirectory + "\\Playlists\\myplaylist.m3u";
                        DateTime lastTimeModifiedPlaylist = System.IO.File.GetLastWriteTime(playlistPath);
                        if (lastTimeModifiedPlaylist != PlaylistDate)
                        {
                            PlaylistDate = lastTimeModifiedPlaylist;
                            await UpdatePlaylist();
                        }

                        bool checkIfSongPlayed = System.IO.File.Exists(SongHistoryPath);
                        if (checkIfSongPlayed == true)
                        {
                            DateTime lastTimeModified = System.IO.File.GetLastWriteTime(SongHistoryPath);

                            if (lastTimeModified != TodaysDate)
                            {
                                TodaysDate = lastTimeModified;

                                List <string> historyAllLines = new List <string>();
                                using (var fileStream = new FileStream(SongHistoryPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                                    using (var streamReader = new StreamReader(fileStream, System.Text.Encoding.Default))
                                    {
                                        string tmpLine = null;

                                        while ((tmpLine = streamReader.ReadLine()) != null)
                                        {
                                            if (tmpLine.StartsWith("#EXT"))
                                            {
                                            }
                                            else
                                            {
                                                historyAllLines.Add(tmpLine);
                                            }
                                        }
                                    }

                                string currentSongPath = historyAllLines.Last();

                                string songInfo          = currentSongPath.Remove(0, currentSongPath.LastIndexOf('\\') + 1);
                                songInfo                 = songInfo.Remove(songInfo.Length - 4);
                                int tmpSeparator         = songInfo.IndexOf("-");
                                string leadAuthor        = songInfo.Remove(tmpSeparator - 1);
                                string[] leadAuthorArray = leadAuthor.Split(',');
                                string title             = songInfo.Remove(0, tmpSeparator + 2);

                                if (title.Contains("(feat"))
                                {
                                    int tmpFeat = title.IndexOf("(feat");
                                    title       = title.Remove(tmpFeat - 1);
                                }

                                for (int i1 = 0; i1 < SongList.Count; i1++)
                                {
                                    if (leadAuthorArray[0] == SongList[i1].LeadAuthorList[0] && title == SongList[i1].Title)
                                    {
                                        CurrentSongId = SongList[i1].Id;
                                        break;
                                    }
                                }

                                HttpResponseMessage deleteHttpResponse = await HttpClientServer.DeleteAsync("api/CurrentSongs");

                                if (deleteHttpResponse.IsSuccessStatusCode)
                                {
                                    HttpResponseMessage addSongResponse = await HttpClientServer.PostAsJsonAsync("api/CurrentSongs/add", CurrentSongId);
                                    if (addSongResponse.IsSuccessStatusCode)
                                    {
                                        if (IsCheckBoxChecked == true)
                                        {
                                            for (int z1 = 0; z1 < RichRequestObservable.Count; z1++)
                                            {
                                                if (PreviousSongToDeleteId == RichRequestObservable[z1].SongId)
                                                {
                                                    RichRequestObservable.RemoveAt(z1);
                                                }
                                            }
                                        }
                                        PreviousSongToDeleteId = CurrentSongId;
                                    }
                                    else
                                    {
                                        ServerStatus = "Server fail, try again!";
                                        MessageBox.Show("Server fail, try again!");
                                    }
                                }
                                else
                                {
                                    ServerStatus = "Server fail, try again!";
                                    MessageBox.Show("Server fail, try again!");
                                }

                                for (int i2 = 0; i2 < PlaylistSongList.Count; i2++)
                                {
                                    if (PlaylistSongList[i2].WasPlayed == false)
                                    {
                                        if (PlaylistSongList[i2].SongId == CurrentSongId)
                                        {
                                            PlaylistSongList[i2].WasPlayed = true;

                                            HttpResponseMessage updatePlaylistResponse = await HttpClientServer.PutAsJsonAsync("api/Playlists/update", i2);
                                            if (updatePlaylistResponse.IsSuccessStatusCode)
                                            {
                                            }
                                            else
                                            {
                                                ServerStatus = "Server fail, try again!";
                                                MessageBox.Show("Server fail, try again!");
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Error while loading data!");
                    }
                    await Task.Delay(TimeSpan.FromMilliseconds(3000));
                }
            });
        }
示例#3
0
        public void GetRequestsandTop5()
        {
            Task.Run(async() =>
            {
                while (true)
                {
                    try
                    {
                        List <Request> requestListToAdd = new List <Request>();

                        HttpResponseMessage requestResponse = await HttpClientServer.GetAsync($"api/Requests/{LastRequestId}");

                        if (requestResponse.IsSuccessStatusCode)
                        {
                            string jsonRequestResponse = await requestResponse.Content.ReadAsStringAsync();
                            requestListToAdd           = JsonConvert.DeserializeObject <List <Request> >(jsonRequestResponse);
                            LastRequestId = LastRequestId + requestListToAdd.Count;
                        }
                        else
                        {
                            ServerStatus = "Server fail to refresh!";
                        }

                        for (int i = 0; i < requestListToAdd.Count; i++)
                        {
                            RequestRich requestRich = new RequestRich(requestListToAdd[i]);
                            Song requestedSong      = SongList.Find(x => x.Id == requestListToAdd[i].SongId);
                            requestRich.Title       = requestedSong.Title;
                            requestRich.LeadAuthor  = requestedSong.LeadAuthor;
                            RichRequestObservable.Add(requestRich);
                        }

                        requestListToAdd.Clear();

                        List <VotedSong> votesSongList = new List <VotedSong>();

                        HttpResponseMessage votesResponse = await HttpClientServer.GetAsync("api/songs/votes");

                        if (votesResponse.IsSuccessStatusCode)
                        {
                            string jsonVotes = await votesResponse.Content.ReadAsStringAsync();
                            votesSongList    = JsonConvert.DeserializeObject <List <VotedSong> >(jsonVotes);
                        }
                        else
                        {
                            ServerStatus = "Server fail to refresh!";
                        }

                        Top5Text = "Top songs:";

                        for (int i = 0; i < 5; i++)
                        {
                            int topSongId    = votesSongList[i].SongId;
                            Song top5Song    = SongList.Find(x => x.Id == topSongId);
                            string songToAdd = "Votes: " + votesSongList[i].Votes + " " + top5Song.Title + " by " + top5Song.LeadAuthor;
                            Top5Text         = Top5Text + "\n\n" + songToAdd;
                        }

                        votesSongList.Clear();

                        List <VotedSong> moreVotesSongList = new List <VotedSong>();

                        HttpResponseMessage moreVotesResponse = await HttpClientServer.GetAsync("api/songs/morevotes");

                        if (moreVotesResponse.IsSuccessStatusCode)
                        {
                            string jsonMoreVotes = await moreVotesResponse.Content.ReadAsStringAsync();
                            moreVotesSongList    = JsonConvert.DeserializeObject <List <VotedSong> >(jsonMoreVotes);
                        }
                        else
                        {
                            ServerStatus = "Server fail to refresh!";
                        }

                        Top10Text = "Top songs:";

                        for (int i = 0; i < 10; i++)
                        {
                            int top10SongId    = moreVotesSongList[i].SongId;
                            Song top10Song     = SongList.Find(x => x.Id == top10SongId);
                            string song10ToAdd = "Votes: " + moreVotesSongList[i].Votes + " " + top10Song.Title + " by " + top10Song.LeadAuthor;
                            Top10Text          = Top10Text + "\n\n" + song10ToAdd;
                        }

                        moreVotesSongList.Clear();

                        HttpResponseMessage chatResponse = await HttpClientServer.GetAsync($"api/Chats/{LastChatId}");

                        if (chatResponse.IsSuccessStatusCode)
                        {
                            string jsonChatResponse = await chatResponse.Content.ReadAsStringAsync();
                            List <string> chatGot   = JsonConvert.DeserializeObject <List <string> >(jsonChatResponse);
                            if (chatGot.Count == 0)
                            {
                            }
                            else
                            {
                                for (int i = 0; i < chatGot.Count; i++)
                                {
                                    ChatText = ChatText + "\n\n" + chatGot[i];
                                }

                                LastChatId = LastChatId + chatGot.Count;
                            }
                        }
                        else
                        {
                            ServerStatus = "Server fail to refresh!";
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Error while loading data!");
                    }

                    await Task.Delay(TimeSpan.FromMilliseconds(5000));
                }
            });
        }