Esempio n. 1
0
        public bool DeleteSong(Song song)
        {
            try
            {
                SongTable.DeleteOnSubmit(song);
                SongTable.Context.SubmitChanges();

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Esempio n. 2
0
        public int SaveSong(Song song)
        {
            try
            {
                if (song.SongId == 0)
                {
                    SongTable.InsertOnSubmit(song);
                }
                else
                {
                    SongTable.Context.Refresh(RefreshMode.KeepCurrentValues, song);
                }

                SongTable.Context.SubmitChanges();

                return song.SongId;
            }
            catch (Exception)
            {
                return -1;
            }
        }
Esempio n. 3
0
        private void btnSaveSong_Click(object sender, EventArgs e)
        {
            var util = new Utilities();
            var songGenreCollection = (from ListItem listItem in lbSongGenres.SelectedItems select WCFWebServiceJson.GetGenre(listItem.SelectedValue())).ToList();
            var albumCollection = (from ListItem listItem in lbSongAlbums.SelectedItems select WCFWebServiceJson.GetArtistAlbumDetails(listItem.SelectedValue())).ToList();

            var song = new Song()
            {
                AlbumCollection = albumCollection,
                CreatedDate = DateTime.Now,
                GenreCollection = songGenreCollection,
                SongComposer = txtSongComposer.Text,
                SongReleaseDate = Convert.ToDateTime(dtpSongReleaseDate.Text),
                SongTitle = txtSongTitle.Text
            };

            foreach (var album in albumCollection)
            {
                if (WCFWebServiceJson.UploadSong(song, lblSelectedFile.Text, "mp3", txtSongWordpressId.Text + "/" + util.RemoveSpaces(album.AlbumTitle) + "/"))
                {
                    txtSongsResults.Text = song.SongTitle + @" has been saved successfully!";
                }
                else
                {
                    txtSongsResults.Text = @"There was a problem saving the song: " + song.SongTitle;
                }
            }
        }
        private bool UploadSongToAlbumFolder(Song song, string filePath, string folderName, string ext)
        {
            if (song.AlbumCollection.Any())
            {
                DestinationFile = String.Format("{0}{1}", ReplaceIllegalCharacters(song.SongTitle.ToUpper()), Path.GetExtension(filePath));

                try
                {
                    // save the file locally and create the aac version for streaming then upload it to the S3 bucket album folder
                    return SaveUploadedAudioFileLocally(filePath, ext) && UploadFileToS3(DestinationFile, folderName, "stream");
                }
                catch (Exception ex)
                {
                    util.ErrorNotification(ex);
                }
            }

            return false;
        }
 public bool DeleteSong(Song song, Album album)
 {
     using (var tranScope = new TransactionScope())
     {
         try
         {
             if (DeleteAlbumSong(song, album))
             {
                 var songMediaAsset = SqlSongMediaAssetRepository.SongMediaAsset.FirstOrDefault(x => x.SongId == song.SongId);
                 if (SqlSongMediaAssetRepository.DeleteSongMediaAsset(songMediaAsset))
                 {
                     if (SqlMediaAssetRepository.DeleteMediaAsset(SqlMediaAssetRepository.MediaAsset.FirstOrDefault(x => x.MediaAssetId == songMediaAsset.MediaAssetId)))
                     {
                         if (SqlSongRepository.DeleteSong(song))
                         {
                             tranScope.Complete();
                             return true;
                         }
                         else
                         {
                             return false;
                         }
                     }
                     else
                     {
                         return false;
                     }
                 }
                 else
                 {
                     return false;
                 }
             }
             else
             {
                 return false;
             }
         }
         catch
         {
             return false;
         }
     }
 }
        private bool SaveSongAlbums(Song song)
        {
            var isSaved = false;

            foreach (var album in song.AlbumCollection)
            {
                isSaved = SqlAlbumSongRepository.SaveAlbumSong(new AlbumSong()
                    {
                        AlbumId = album.AlbumId,
                        SongId = song.SongId
                    });

                if (!isSaved)
                {
                    return false;
                }
            }

            return isSaved;
        }
        private bool SaveMasterFile(Song song, string filePath, string folderName)
        {
            if (song.AlbumCollection.Any())
            {
                string ext = Path.GetExtension(filePath);
                DestinationFile = Path.Combine(Path.GetDirectoryName(filePath), String.Format("{0}{1}", ReplaceIllegalCharacters(song.SongTitle.ToUpper()), ext));
                try
                {
                    if (!File.Exists(DestinationFile))
                    {
                        File.Copy(filePath, DestinationFile);
                    }

                    using (var tranScope = new TransactionScope())
                    {

                        // create the required media assets entries
                        var mediaAssetFormat = SqlMediaAssetFormatRepository.MediaAssetFormat.FirstOrDefault(x => x.MediaAssetFormatName.Equals(ext.Remove(0, 1)));
                        if (mediaAssetFormat != null)
                        {
                            var mediaAssetId = SaveMediaAsset(mediaAssetFormat);

                            if (mediaAssetId > 0)
                            {
                                // save the location of the media asset in S3
                                if (SaveMediaAssetLocation(mediaAssetId, folderName))
                                {
                                    // now link the song and the media file
                                    if (SaveSongMediaAsset(song.SongId, mediaAssetId))
                                    {
                                        // upload the file to the S3 bucket album folder
                                        if (UploadFileToS3(DestinationFile, folderName, "master"))
                                        {
                                            tranScope.Complete();
                                            return true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            var ex = new InvalidDataException("The file extension {} is invalid. Allowed file extensions: mp3, aac, mp4, m4a, wav, aiff");
                            util.ErrorNotification(ex);
                        }
                    }

                }
                catch (Exception ex)
                {
                    util.ErrorNotification(ex);
                }
            }

            return false;
        }
        public bool DeleteAlbumSong(Song song, Album album)
        {
            var albumSong =
                SqlAlbumSongRepository.AlbumSong.FirstOrDefault(
                    x => x.SongId == song.SongId && x.AlbumId == album.AlbumId);

            return SqlAlbumSongRepository.DeleteAlbumSong(albumSong);
        }
        private Album GetSongAlbum(Song song)
        {
            var albumSong = SqlAlbumSongRepository.AlbumSong.FirstOrDefault(x => x.SongId == song.SongId);

            return (albumSong != null) ? SqlAlbumRepository.GetAlbumById(albumSong.AlbumId) : null;
        }
        public bool UploadSong(Song song, string filePath, string ext, string folderName)
        {
            var isUploaded = false;

            // save the file locally and create the aac version for streaming then upload it to the S3 bucket
            if (UploadSongToAlbumFolder(song, filePath, folderName, ext))
            {
                using (var tranScope = new TransactionScope())
                {
                    try
                    {
                        //create the song entry
                        var songId = SqlSongRepository.SaveSong(song);

                        if (songId > 0)
                        {
                            // link the song and the albums
                            if (SaveSongAlbums(song))
                            {
                                // save the song genre collection
                                if (SaveSongGenreCollection(songId, song.GenreCollection))
                                {
                                    // create the media asset entry
                                    var mediaAssetFormat = SqlMediaAssetFormatRepository.MediaAssetFormat.FirstOrDefault(x => x.MediaAssetFormatName.Equals(ext));
                                    if (mediaAssetFormat != null)
                                    {
                                        var mediaAssetId = SaveMediaAsset(mediaAssetFormat);

                                        if (mediaAssetId > 0)
                                        {
                                            // save the location of the media asset in S3
                                            if (SaveMediaAssetLocation(mediaAssetId, folderName))
                                            {
                                                // now link the song and the media file
                                                if (SaveSongMediaAsset(songId, mediaAssetId))
                                                {
                                                    tranScope.Complete();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        util.ErrorNotification(ex);
                        isUploaded = false;
                    }
                }

                // save the master file
                isUploaded = SaveMasterFile(song, filePath, folderName);
            }

            return isUploaded;
        }