예제 #1
0
        public async Task FirstChatDatabase()
        {
            try
            {
                HttpResponseMessage deleteHttpResponse = await HttpClientServer.DeleteAsync("api/Chats");

                if (deleteHttpResponse.IsSuccessStatusCode)
                {
                    HttpResponseMessage firstChatResponse = await HttpClientServer.PostAsJsonAsync("api/Chats/first", "Welcome on chat");

                    if (firstChatResponse.IsSuccessStatusCode)
                    {
                    }
                    else
                    {
                        ServerStatus = "Server fail, try again!";
                        MessageBox.Show("Server fail, try again!");
                    }
                }
                else
                {
                    ServerStatus = "Server fail, try again!";
                    MessageBox.Show("Server fail, try again!");
                }
            }
            catch
            {
                IsServerStartButtonEnabled = true;
                ServerStatus = "Server fail, try again!";
                MessageBox.Show("Server fail, try again!");
            }
        }
예제 #2
0
        public async Task AddSongsToDatabase()
        {
            try
            {
                HttpResponseMessage deleteHttpResponse = await HttpClientServer.DeleteAsync("api/songs");

                if (deleteHttpResponse.IsSuccessStatusCode)
                {
                    HttpResponseMessage songDatabaseResponse = await HttpClientServer.PostAsJsonAsync("api/songs/add", SongList);

                    if (songDatabaseResponse.IsSuccessStatusCode)
                    {
                    }
                    else
                    {
                        ServerStatus = "Server fail, try again!";
                        MessageBox.Show("Server fail, try again!");
                    }
                }
                else
                {
                    ServerStatus = "Server fail, try again!";
                    MessageBox.Show("Server fail, try again!");
                }
            }
            catch
            {
                IsServerStartButtonEnabled = true;
                ServerStatus = "Server fail, try again!";
                MessageBox.Show("Server fail, try again!");
            }
        }
예제 #3
0
        public async Task AddDJToDatabase(string password)
        {
            try
            {
                HttpResponseMessage deleteHttpResponse = await HttpClientServer.DeleteAsync("api/users");

                if (deleteHttpResponse.IsSuccessStatusCode)
                {
                    HttpResponseMessage setPasswordResponse = await HttpClientServer.PostAsJsonAsync("api/Users/adddj", password);

                    if (setPasswordResponse.IsSuccessStatusCode)
                    {
                    }
                    else
                    {
                        ServerStatus = "Server fail, try again!";
                        MessageBox.Show("Server fail, try again!");
                    }
                }
                else
                {
                    ServerStatus = "Server fail, try again!";
                    MessageBox.Show("Server fail, try again!");
                }
            }
            catch
            {
                IsServerStartButtonEnabled = true;
                ServerStatus = "Server fail, try again!";
                MessageBox.Show("Server fail, try again!");
            }
        }
예제 #4
0
        public async Task AddSongsToPlaylistDatabase(int startPosition)
        {
            string[] PlaylistArray = ReadPlaylistFromLine(startPosition);

            for (int i = 0; i < PlaylistArray.Length; i++)
            {
                if (PlaylistArray[i].Substring(PlaylistArray[i].Length - 4)[0].Equals('.'))
                {
                    string songInfo = PlaylistArray[i].Remove(0, PlaylistArray[i].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)
                        {
                            Playlist playlistSong = new Playlist(SongInPlaylistId, SongList[i1].Id, false);
                            PlaylistSongList.Add(playlistSong);
                            SongInPlaylistId++;
                        }
                    }
                }
            }

            try
            {
                HttpResponseMessage playlistDatabaseResponse = await HttpClientServer.PostAsJsonAsync("api/playlists/add", PlaylistSongList);

                if (playlistDatabaseResponse.IsSuccessStatusCode)
                {
                }
                else
                {
                    ServerStatus = "Server fail, try again!";
                    MessageBox.Show("Server fail, try again!");
                }
            }
            catch
            {
                IsServerStartButtonEnabled = true;
                ServerStatus = "Server fail, try again!";
                MessageBox.Show("Server fail, try again!");
            }
        }
예제 #5
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));
                }
            });
        }