/// <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"); }
/// <author>Kenneth Søhrmann</author> /// <summary> /// Convenience method for uploading a movie to the server. /// The methods blocks during upload. /// </summary> /// <param name="credentials"> /// The credentials of the publisher who is to upload the specified /// movie. /// </param> /// <param name="movieInfo"> /// The metadata of the movie to be uploaded. /// </param> /// <exception cref="WebException"> /// Is thrown if the upload of the movie failed. /// </exception> /// <exception cref="ArgumentException"> /// Is thrown if the credentials are not authorized. /// </exception> public static void UploadMovie(Credentials credentials, MovieInfoUpload movieInfo) { if (!string.IsNullOrEmpty(movieInfo.FilePath)) { if (!File.Exists(movieInfo.FilePath)) { throw new ArgumentException("The specified file does not exist."); } if (!new FileInfo(movieInfo.FilePath).Extension.Equals(".mp4")) { throw new ArgumentException("The specified file does not have the supported extension, mp4."); } } 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 mInfo = new MovieInfo() { Title = movieInfo.Title, Type = MediaType.Movie, Genre = movieInfo.Genre, Price = movieInfo.Price, Publisher = movieInfo.Publisher, ReleaseDate = movieInfo.ReleaseDate, Director = movieInfo.Director, Duration = movieInfo.Duration, Summary = movieInfo.Summary, }; int movieId; try { movieId = serviceClient.PublishMedia(mInfo, accountCredentials); } catch (Exception e) { throw new Exception("Something went wrong: " + e.Message); } try { if (!string.IsNullOrEmpty(movieInfo.FilePath)) { UploadMediaFile(movieInfo.FilePath, movieId, credentials); } UploadThumbnail(movieId, movieInfo, credentials); } catch (Exception) { // Clean up server database if the upload failed. serviceClient.DeleteMedia(movieId, accountCredentials); throw new WebException("Upload of media failed."); } }
/// <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; } }
/// <summary> /// Used for initial testing. /// </summary> public static void Main() { // Set up the credentials of the publisher account. var credentials = new Credentials("publishCorp", "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220"); // Load the thumbnail to be uploaded into the memory. Image thumbnail = System.Drawing.Image.FromFile(@"C:\Users\Kenneth88\Desktop\gta\GtaThumb.jpg"); // Construct the MovieInfo-object holding the metadata of the movie to be uploaded. var movieInfo = new MovieInfoUpload { FilePath = @"C:\Users\Kenneth88\Desktop\gta\GTA V - Debut Trailer.mp4", Title = "GTA V - Debut Trailer", Genre = "Trailer", Price = 0, ReleaseDate = DateTime.Now, Publisher = "Publish Corp. International", Thumbnail = thumbnail, Director = "Rockstar", Summary = "The very first trailer of the Grand Theft Auto V-game. Oh so sweet it is!", Duration = TimeSpan.FromSeconds(41D) }; // Upload the movie by calling the UploadMovie method. Console.WriteLine("Started upload"); UploadMovie(credentials, movieInfo); Console.WriteLine("Done uploading!"); }