Пример #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");
        }
Пример #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;
            }
        }
Пример #3
0
        /// <author>Kenneth Søhrmann</author>
        /// <summary>
        /// Convenience method for uploading a book to the server.
        /// The methods blocks during upload.
        /// </summary>
        /// <param name="credentials">
        /// The credentials of the publisher who is to upload the book.
        /// </param>
        /// <param name="bookInfo">
        /// The metadata of the book to be uploaded.
        /// </param>
        /// <exception cref="WebException">
        /// Is thrown if the upload of the mediafile or media thumbnail failed.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Is thrown if the credentials are not authorized.
        /// </exception>
        public static void UploadBook(Credentials credentials, BookInfoUpload bookInfo)
        {
            if (!string.IsNullOrEmpty(bookInfo.FilePath))
            {
                if (!File.Exists(bookInfo.FilePath))
                {
                    throw new ArgumentException("The specified file does not exist.");
                }
                if (!new FileInfo(bookInfo.FilePath).Extension.Equals(".mp4"))
                {
                    throw new ArgumentException("The specified file does not have the supported extension, pdf.");
                }
            }

            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 bookMedia = new BookInfo()
            {
                Title = bookInfo.Title,
                Type = MediaType.Book,
                Genre = bookInfo.Genre,
                Price = bookInfo.Price,
                Publisher = bookInfo.Publisher,
                ReleaseDate = bookInfo.ReleaseDate,

                Author = bookInfo.Author,
                Pages = bookInfo.Pages,
                Summary = bookInfo.Summary
            };

            int bookMediaId = serviceClient.PublishMedia(bookMedia, accountCredentials);

            try
            {
                if (!string.IsNullOrEmpty(bookInfo.FilePath))
                {
                    UploadMediaFile(bookInfo.FilePath, bookMediaId, credentials);
                }

                UploadThumbnail(bookMediaId, bookInfo, credentials);
            }
            catch (Exception e)
            {
                // Upload failed, clean up database.

                serviceClient.DeleteMedia(bookMediaId, accountCredentials);
                throw new WebException("Upload failed, please try again: " + e.Message);
            }
        }