示例#1
0
        public async Task CloseServer()
        {
            IsServerCloseButtonEnabled = false;
            try
            {
                HttpResponseMessage closeServerResponse = await HttpClientServer.PutAsJsonAsync("api/Users/close", "*fQ$|4x#9d_,yP7>a@0");

                if (closeServerResponse.IsSuccessStatusCode)
                {
                    ServerPassword = "******";
                }
                else
                {
                    ServerPassword             = "******";
                    IsServerCloseButtonEnabled = true;
                }
            }
            catch
            {
                IsServerCloseButtonEnabled = true;
                ServerStatus = "Server fail, try again!";
                MessageBox.Show("Server fail, try again!");
            }
        }
示例#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));
                }
            });
        }