Exemplo n.º 1
0
 public void ShowMessageBox(object obj)
 {
     if ((obj is RequestRich))
     {
         RequestRich dedicationRequest = obj as RequestRich;
         MessageBox.Show(dedicationRequest.Dedication);
     }
 }
Exemplo n.º 2
0
        public async Task StartServer()
        {
            if (VdjDirectory == "")
            {
                ServerStatus = "Paste directory first!";
            }
            else
            {
                VdjDirectory.Trim();
                SongFirstId            = 1;
                PlaylistLinePosition   = 0;
                SongInPlaylistId       = 1;
                ChatLines              = 0;
                LastRequestId          = 0;
                LastChatId             = 0;
                HistoryLinePosition    = 0;
                PreviousSongToDeleteId = -1;
                PlaylistFirstLoad      = false;
                ChatText              = "Today's chat";
                SongList              = new List <Song>();
                PlaylistSongList      = new List <Playlist>();
                ChatObservable        = new ObservableCollection <string>();
                RichRequestObservable = new ObservableCollection <RequestRich>();
                object lockObj = new object();
                BindingOperations.EnableCollectionSynchronization(RichRequestObservable, lockObj);
                RequestSelected = new RequestRich();

                IsServerStartButtonEnabled = false;
                ServerStatus = "Server is starting!";
                try
                {
                    LoadSongDatabase();
                }
                catch
                {
                    MessageBox.Show("Incorrect VDJ path!");
                }
                await FirstLoadPlaylist();
                await FirstRequestDatabase();
                await FirstCurrentSongsDatabase();
                await FirstChatDatabase();
                await AddSongsToDatabase();

                GetCurrentSong();
                await AddDJToDatabase(ServerPassword);

                GetRequestsandTop5();
                if (ServerStatus == "Server is starting!")
                {
                    ServerStatus               = "Server is running!";
                    IsUpdateButtonEnabled      = true;
                    IsServerCloseButtonEnabled = true;
                    MessageBox.Show("Server started successfully!");
                }
            }
        }
Exemplo n.º 3
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);
             }
         }
     }
 }
Exemplo n.º 4
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));
                }
            });
        }