コード例 #1
0
        //button click for adding music files to the dB
        private async void OnUploadFolderToDbClick(object sender, RoutedEventArgs e)
        {
            // Add method call to upload to database
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri("http://welistenmusic.com/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            // Set targetDirectory string
            string targetDiredctory = new DirButton().selectDirectory();

            // Set master List
            List<SongData> songList = new List<SongData>();
            List<SongData> files;

            try
            {
                // Return from directory dialog
                files = await dirHandler.dirDiag(targetDiredctory, songList);
            }
            catch
            {
                files = null;
            }

            if (files != null)
            {
                var processCount = 0;
                var addedCount = 0;
                var notAddedCount = 0;
                lblProgressCount.Content = processCount;
                lblAddedCount.Content = addedCount;
                lblRejectedCount.Content = notAddedCount;

                foreach (SongData song in files)
                {
                    // Assign path to variable
                    var path = song.FilePath;

                    processCount++;
                    lblProgressCount.Content = processCount;
                    ProcessEvent();
                    // Get full request
                    SongData amazonSong = await amazonAccesser.getAmazonInfo(song);

                    // Set location / user ID
                    amazonSong.UserID = 3;
                    amazonSong.LocationID = 3;

                    // Set and adjust file paths for DB storage
                    amazonSong.FilePath = path;

                    var response = client.PostAsJsonAsync("api/song", amazonSong).Result;
                    

                    if (response.IsSuccessStatusCode)
                    {
                        //MessageBox.Show("Song Added");
                        addedCount++;
                        lblAddedCount.Content = addedCount;
                        ProcessEvent();
                    }
                    else
                    {
                        notAddedCount++;
                        lblRejectedCount.Content = notAddedCount;
                        ProcessEvent();
                        //MessageBox.Show("Error Code" + response.StatusCode + " : Message - " + response.ReasonPhrase);
                    }
                }
                MessageBox.Show("Songs Added:  " + addedCount + "  Songs Rejected:  " + notAddedCount);
            }
        }
コード例 #2
0
        private async void dirSelector(object sender, RoutedEventArgs e)
        {
            // Set targetDirectory string
            string targetDiredctory = new DirButton().selectDirectory();

            // Set master List
            List<SongData> songList = new List<SongData>();

            try
            {
                // Return from directory dialog
                var files = await dirHandler.dirDiag(targetDiredctory, songList);

                // Get songs in playlist
                var playlistSongs = getPlaylistSongs();

                if (files != null)
                {
                    foreach (SongData song in files)
                    {
                        // Assign path to variable
                        var path = song.FilePath;

                        // Get full request
                        SongData amazonSong = await Task.Run(() => amazonAccesser.getAmazonInfo(song));

                        // Set amazonSong Path
                        amazonSong.FilePath = path;

                        // Check for duplicate values
                        bool isDup = dupCheck.checkDup(playlistSongs, amazonSong);

                        if (!isDup)
                        {
                            // Add AmazonSong to playlist
                            dgvPlayList.Items.Add(amazonSong);
                        }
                    }
                    QueueNextSong();
                }
                else
                {
                    MessageBox.Show("There was a problem getting the folder path.");
                }
            }
            catch
            {
                MessageBox.Show("There was a problem getting the folder path.");
            }
        }