Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the MediaUploadControl class.
        /// </summary>
        public MediaUploadControl()
        {
            InitializeComponent();

            // Initialize upload media
            this.bookInfo = new BookInfoUpload();
            this.movieInfo = new MovieInfoUpload();
            this.albumInfo = new AlbumInfoUpload();

            // Initialize selection.
            comboBox1.SelectedIndex = 0;
            mediaPropertyGrid.SelectedObject = bookInfo;
            songsGroupBox.Enabled = false;

            // Add the event handlers
            songListView.SelectedIndexChanged += this.ListViewSelectionChanged;
            songPropertyGrid.PropertyValueChanged += this.SongPropertyGrid_PropertyValueChanged;
            comboBox1.SelectedValueChanged += this.ComboBox1_SelectedValueChanged;

            BinaryCommuncator.FileUploadedEvent += this.UploadLabel_FileUploaded;

            this.publisherCredentials = new Credentials("publishCorp", "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220");
        }
Exemple #2
0
        /// <author>Kenneth Søhrmann</author>
        /// <summary>
        /// This method is invoked whenever the "Discard"-button on the form i clicked.
        /// It resets the currently displayed media object.
        /// </summary>
        private void discardButton_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.ToString().Equals("Album"))
            {
                this.albumInfo = new AlbumInfoUpload();
                this.albumInfo.Publisher = this.PublisherAccount.PublisherName;

                this.mediaPropertyGrid.SelectedObject = this.albumInfo;

                songPropertyGrid.SelectedObject = null;
                songListView.Items.Clear();
            }
            if (comboBox1.SelectedItem.ToString().Equals("Book"))
            {
                this.bookInfo = new BookInfoUpload();
                this.bookInfo.Publisher = this.PublisherAccount.PublisherName;
                this.mediaPropertyGrid.SelectedObject = this.bookInfo;
            }
            if (comboBox1.SelectedItem.ToString().Equals("Movie"))
            {
                this.movieInfo = new MovieInfoUpload();
                this.movieInfo.Publisher = this.PublisherAccount.PublisherName;
                this.mediaPropertyGrid.SelectedObject = this.movieInfo;
            }
        }
Exemple #3
0
        /// <author>Kenneth Søhrmann</author>
        /// <summary>
        /// Convenience method for uploading an album and its songs to the 
        /// server. 
        /// The methods blocks during upload.
        /// </summary>
        /// <param name="credentials">
        /// The credentials of the publisher who is uploading the specified album.
        /// </param>
        /// <param name="songs">
        /// A list of SongInfoUpload-objects each representing the metadata of the songs
        /// that is a part of the album.
        /// </param>
        /// <param name="albumInfo">
        /// Instance holding the metadata of the album to be uploaded.
        /// </param>
        /// <exception cref="WebException">
        /// Is thrown if the upload of one of the songs or the thumbnail failed.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Is thrown if the credentials are not authorized.
        /// </exception>
        public static void UploadAlbum(Credentials credentials, List<SongInfoUpload> songs, AlbumInfoUpload albumInfo)
        {
            // Check specified song files
            foreach (SongInfoUpload song in songs)
            {
                // If the filepath has not been stated, it is okay.
                if (string.IsNullOrEmpty(song.FilePath))
                {
                    continue;
                }

                if (!File.Exists(song.FilePath))
                {
                    throw new ArgumentException("The file, " + song.FilePath + ", does not exist.");
                }
                if (!new FileInfo(song.FilePath).Extension.Equals(".mp3"))
                {
                    throw new ArgumentException("The file, " + song.FilePath + ", does not have the supported extension, mp3.");
                }
            }

            var serviceClient = GetServiceClient();
            var accountCredentials = new AccountCredentials
            {
                UserName = credentials.UserName,
                HashedPassword = credentials.HashedPassword
            };

            try
            {
                serviceClient.ValidateCredentials(accountCredentials);
            }
            catch (Exception)
            {
                throw new ArgumentException("Invalid credentials submitted.");
            }

            var albumMedia = new AlbumInfo()
                {
                    Title = albumInfo.Title,
                    Type = MediaType.Album,
                    Genre = albumInfo.Genre,
                    Price = albumInfo.Price,
                    Publisher = albumInfo.Publisher,
                    ReleaseDate = albumInfo.ReleaseDate,

                    AlbumArtist = albumInfo.AlbumArtist,
                    Description = albumInfo.Description,
                };

            int albumMediaId = serviceClient.PublishMedia(albumMedia, accountCredentials);

            // Upload the thumbnail of the album.
            try
            {
                UploadThumbnail(albumMediaId, albumInfo, credentials);
            }
            catch (Exception e)
            {
                serviceClient.DeleteMedia(albumMediaId, accountCredentials);
                throw new WebException("Upload failed: " + e.Message);
            }

            // For database clean up if upload fails.
            var publishedSongs = new List<int>();

            // Process each song file; upload data to database, and upload song files to
            // server.
            foreach (SongInfoUpload songInfo in songs)
            {
                var songMedia = new SongInfo()
                {
                    Title = songInfo.Title,
                    Type = MediaType.Song,
                    Genre = songInfo.Genre,
                    Price = songInfo.Price,
                    Publisher = songInfo.Publisher,
                    ReleaseDate = songInfo.ReleaseDate,

                    AlbumId = albumMediaId, // Set the album media id to the one received when publishing the album metadata.
                    Artist = songInfo.Artist,
                    Duration = songInfo.Duration
                };

                // publish the metadata of the song to the server.
                int songMediaId = serviceClient.PublishMedia(songMedia, accountCredentials);

                // For rollback if upload of binary data fails.
                publishedSongs.Add(songMediaId);

                try
                {
                    if (!string.IsNullOrEmpty(songInfo.FilePath))
                    {
                        UploadMediaFile(songInfo.FilePath, songMediaId, credentials);
                    }

                    if (songInfo.Thumbnail != null)
                    {
                        UploadThumbnail(songMediaId, songInfo, credentials);
                    }
                }
                catch (Exception e)
                {
                    // Clean up server database upon upload failure.
                    foreach (int songId in publishedSongs)
                    {
                        serviceClient.DeleteMedia(songId, accountCredentials);
                    }

                    serviceClient.DeleteMedia(albumMediaId, accountCredentials);
                    throw new WebException("Upload failed: " + e.Message);
                }
            }
        }