コード例 #1
0
ファイル: SearchResultsControl.cs プロジェクト: ltj/rentit
        /// <summary>
        /// Changes the window content to display details about a media item.
        /// </summary>
        /// <param name="media">The item to display details of.</param>
        private void DisplayMediaItem(MediaInfo media)
        {
            RentItUserControl mediaDetails;
            string title;
            switch (media.Type)
            {
                case MediaType.Album:
                    mediaDetails = new AlbumDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            AlbumInfo = (AlbumInfo)media
                        };
                    title = "Album details";
                    break;
                case MediaType.Book:
                    mediaDetails = new BookMovieDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            BookInfo = (BookInfo)media
                        };
                    title = "Book details";
                    break;
                case MediaType.Movie:
                    mediaDetails = new BookMovieDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            MovieInfo = (MovieInfo)media
                        };
                    title = "Movie details";
                    break;
                case MediaType.Song:
                    mediaDetails = new AlbumDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            AlbumInfo = RentItProxy.GetAlbumInfo(((SongInfo)media).AlbumId)
                        };
                    title = "Album details";
                    break;
                default:
                    return;
            }

            FireContentChangeEvent(mediaDetails, title);
        }
コード例 #2
0
ファイル: MainScreen.cs プロジェクト: ltj/rentit
        /// <summary>
        /// Switches to a media details screen, depending on the type
        /// of media selected.
        /// </summary>
        /// <param name="media">The media to open a details page for.</param>
        private void DisplayMediaItem(MediaInfo media)
        {
            Cursor.Current = Cursors.WaitCursor;

            RentItUserControl mediaDetails;
            string title;
            switch (media.Type)
            {
                case MediaType.Album:
                    mediaDetails = new AlbumDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            AlbumInfo = (AlbumInfo)media
                        };
                    title = MainForm.Titles.MediaDetailsAlbum;
                    break;
                case MediaType.Book:
                    mediaDetails = new BookMovieDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            BookInfo = (BookInfo)media
                        };
                    title = MainForm.Titles.MediaDetailsBook;
                    break;
                case MediaType.Movie:
                    mediaDetails = new BookMovieDetails
                        {
                            RentItProxy = RentItProxy,
                            Credentials = Credentials,
                            MovieInfo = (MovieInfo)media
                        };
                    title = MainForm.Titles.MediaDetailsMovie;
                    break;
                default:
                    return;
            }

            FireContentChangeEvent(mediaDetails, title);

            Cursor.Current = Cursors.Default;
        }
コード例 #3
0
ファイル: MediaRatings.cs プロジェクト: ltj/rentit
 /// <summary>
 /// Reload the media to list newly submitted review
 /// and update the average rating.
 /// </summary>
 private void ReloadList()
 {
     try {
         switch(Media.Type) {
             case MediaType.Book:
                 Media = RentItProxy.GetBookInfo(media.Id);
                 break;
             case MediaType.Movie:
                 Media = RentItProxy.GetMovieInfo(media.Id);
                 break;
             case MediaType.Album:
                 Media = RentItProxy.GetAlbumInfo(media.Id);
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     } catch(FaultException) {
         RentItMessageBox.ServerCommunicationError();
         return;
     }
 }
コード例 #4
0
ファイル: RentItService.svc.cs プロジェクト: ltj/rentit
        /// <author>Lars Toft Jacobsen</author>
        /// <summary>
        /// Publish new media
        /// </summary>
        /// <param name="info"></param>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public int PublishMedia(MediaInfo info, AccountCredentials credentials)
        {
            Account account = ValidateCredentials(credentials);
            if (account == null)
            {
                throw new FaultException<InvalidCredentialsException>(
                    new InvalidCredentialsException("Invalid credentials submitted.")); ;
            }

            if (!Util.IsPublisher(account))
                throw new FaultException<InvalidCredentialsException>(
                    new InvalidCredentialsException("This user is not a publisher."));

            if (info.Price < 0)
            {
                throw new FaultException<InvalidCredentialsException>(
                    new InvalidCredentialsException("The price of the media cannot be negative."));
            }

            var db = new DatabaseDataContext();
            Genre genre;

            // fetch mediatype and genre id's
            if (!db.Media_types.Exists(t => t.name.Equals(info.Type)))
            {
                throw new FaultException<ArgumentException>(
                    new ArgumentException("Invalid media type parameter"));
            }
            Media_type mtype = (from t in db.Media_types
                                where t.name.Equals(info.Type)
                                select t).Single();

            // Add the genre if it doesn't already exist.
            int genreId = Util.AddGenre(info.Genre, info.Type);

            genre = (from g in db.Genres
                     where g.id == genreId
                     select g).Single();

            // Check if the specified publisher exists.
            if (!db.Publishers.Exists(p => p.title.Equals(info.Publisher)))
            {
                throw new FaultException<ArgumentException>(
                    new ArgumentException("Invalid publisher parameter"));
            }

            Publisher publisher = (from p in db.Publishers
                                   where p.title.Equals(info.Publisher)
                                   select p).Single();

            try
            {
                var newMedia = new RentItDatabase.Media
                {
                    title = info.Title,
                    genre_id = genre.id,
                    type_id = mtype.id,
                    price = info.Price,
                    release_date = info.ReleaseDate,
                    publisher_id = publisher.id,
                    active = true
                };

                switch (info.Type)
                {
                    case MediaType.Album:
                        AlbumInfo albumInfo = (AlbumInfo)info;
                        RentItDatabase.Album newAlbum = new Album()
                        {
                            Media = newMedia,
                            album_artist = albumInfo.AlbumArtist,
                            description = albumInfo.Description
                        };
                        db.Albums.InsertOnSubmit(newAlbum);
                        break;
                    case MediaType.Book:
                        BookInfo bookInfo = (BookInfo)info;
                        RentItDatabase.Book newBook = new Book()
                        {
                            Media = newMedia,
                            author = bookInfo.Author,
                            pages = bookInfo.Pages,
                            summary = bookInfo.Summary
                        };
                        db.Books.InsertOnSubmit(newBook);
                        break;
                    case MediaType.Movie:
                        MovieInfo movieInfo = (MovieInfo)info;
                        RentItDatabase.Movie newMovie = new Movie()
                        {
                            Media = newMedia,
                            director = movieInfo.Director,
                            length = (int)movieInfo.Duration.TotalSeconds,
                            summary = movieInfo.Summary
                        };
                        db.Movies.InsertOnSubmit(newMovie);
                        break;
                    case MediaType.Song:
                        SongInfo songInfo = (SongInfo)info;
                        RentItDatabase.Song newSong = new Song()
                        {
                            Media = newMedia,
                            artist = songInfo.Artist,
                            length = (int)songInfo.Duration.TotalSeconds
                        };

                        db.Songs.InsertOnSubmit(newSong);

                        RentItDatabase.Album_song albumSong = new Album_song()
                        {
                            album_id = songInfo.AlbumId,
                            Song = newSong
                        };

                        db.Album_songs.InsertOnSubmit(albumSong);
                        break;
                }

                db.Medias.InsertOnSubmit(newMedia);
                db.SubmitChanges();

                var newRating = new RentItDatabase.Rating
                {
                    media_id = newMedia.id,
                    avg_rating = 0.0,
                    ratings_count = 0
                };
                db.Ratings.InsertOnSubmit(newRating);
                db.SubmitChanges();

                return newMedia.id;
            }
            catch (Exception e)
            {
                throw new FaultException<Exception>(
                    new Exception("An internal error has occured. This is not related to the input: " + e.Message));
            }
        }
コード例 #5
0
ファイル: RentItService.svc.cs プロジェクト: ltj/rentit
        /// <author>Per Mortensen</author>
        public bool UpdateMediaMetadata(MediaInfo newData, AccountCredentials credentials)
        {
            ValidateCredentials(credentials);

            DatabaseDataContext db;
            try
            {
                db = new DatabaseDataContext();
            }
            catch (Exception)
            {
                throw new FaultException<Exception>(
                    new Exception("An internal error has occured. This is not related to the input."));
            }

            // Is publisher authorized for this media?
            if (!Util.IsPublisherAuthorized(newData.Id, credentials, db, this))
                throw new FaultException<InvalidCredentialsException>(
                    new InvalidCredentialsException("This user is not authorized to update this media."));

            if (newData.Price < 0)
            {
                throw new FaultException<InvalidCredentialsException>(
                    new InvalidCredentialsException("The price cannot be negative."));
            }

            try
            {
                // find media based on id
                if (!db.Medias.Exists(m => m.id == newData.Id && m.active))
                    return false;
                Media media = (from m in db.Medias
                               where m.id == newData.Id && m.active
                               select m).Single();

                // add genre to database if it doesn't exist and get its genre id
                int genreId = Util.AddGenre(newData.Genre, newData.Type);

                // update general metadata
                media.genre_id = genreId;
                media.price = newData.Price;
                media.release_date = newData.ReleaseDate;
                media.title = newData.Title;

                // update type-specific metadata
                switch (newData.Type)
                {
                    case MediaType.Album:
                        var newAlbumData = (AlbumInfo)newData;
                        Album album = media.Album;
                        album.album_artist = newAlbumData.AlbumArtist;
                        album.description = newAlbumData.Description;
                        break;
                    case MediaType.Book:
                        var newBookData = (BookInfo)newData;
                        Book book = media.Book;
                        book.author = newBookData.Author;
                        book.pages = newBookData.Pages;
                        book.summary = newBookData.Summary;
                        break;
                    case MediaType.Movie:
                        var newMovieData = (MovieInfo)newData;
                        Movie movie = media.Movie;
                        movie.director = newMovieData.Director;
                        movie.length = (int)newMovieData.Duration.TotalSeconds;
                        movie.summary = newMovieData.Summary;
                        break;
                    case MediaType.Song:
                        var newSongData = (SongInfo)newData;
                        Song song = media.Song;
                        song.artist = newSongData.Artist;
                        song.length = (int)newSongData.Duration.TotalSeconds;
                        break;
                }

                db.SubmitChanges();
            }
            catch (Exception)
            {
                throw new FaultException<Exception>(
                    new Exception("An internal error has occured. This is not related to the input."));
            }

            return true;
        }
コード例 #6
0
ファイル: MediaFrontpage.cs プロジェクト: ltj/rentit
        /// <summary>
        /// Get newest media and publish to "new and hot" area
        /// </summary>
        private void GetNewest()
        {
            // we need valid prerequisites to query the webservice
            if (mtype == RentIt.MediaType.Any || RentItProxy == null) return;

            // build search criteria
            var mc = new RentIt.MediaCriteria
            {
                Type = mtype,
                Limit = 10, // ten results (previously one result)
                Order = RentIt.MediaOrder.ReleaseDateDesc,
                Genre = "",
                SearchText = ""
            };

            newMediaGrid.MediaCriteria = mc;

            try
            {
                RentIt.MediaItems result = RentItProxy.GetMediaItems(mc);
                RentIt.MediaInfo[] subresult = ExtractTypeList(result);

                newAndHotMedia = subresult[0];
                lblNewTitle.Text = subresult[0].Title;
                lblNewGenre.Text = subresult[0].Genre;
                lblNewRelease.Text = subresult[0].ReleaseDate.ToShortDateString();
                lblNewPublisher.Text = subresult[0].Publisher;
                lblNewPrice.Text = subresult[0].Price.ToString();

                picNewThumb.Image = BinaryCommuncator.GetThumbnail(subresult[0].Id);
            }
            catch
            {
                lblNewTitle.Text = "Oh snap! Something went wrong :(";
            }
        }
コード例 #7
0
ファイル: AlsoRentedList.cs プロジェクト: ltj/rentit
        /// <summary>
        /// Updates the list with the given media id and prioritized media type property. 
        /// </summary>
        private void UpdateList()
        {
            Cursor.Current = Cursors.WaitCursor;
            MediaItems medias;
            //Gets all relevant medias from the database.
            try{ medias = this.RentItProxy.GetAlsoRentedItems(MediaId);}
            catch {return;}
            //The lists containing media of varying relevance. The elements in the primaryList will be displayed at the top.
            MediaInfo[] primaryList;
            MediaInfo[] secondaryList;
            MediaInfo[] tertiaryList;

            //Each media type is assigned a list depending on the relevance of the media type compared to the prioritized media type.
            switch (PrioritizedMediaType)
            {
                case MediaType.Album:
                    primaryList = medias.Albums;
                    secondaryList = medias.Movies;
                    tertiaryList = medias.Books;
                    break;
                case MediaType.Book:
                    primaryList = medias.Books;
                    secondaryList = medias.Movies;
                    tertiaryList = medias.Albums;
                    break;
                case MediaType.Movie:
                    primaryList = medias.Movies;
                    secondaryList = medias.Books;
                    tertiaryList = medias.Albums;
                    break;
                default:
                    primaryList = new MediaInfo[0];
                    secondaryList = new MediaInfo[0];
                    tertiaryList = new MediaInfo[0];
                    break;
            }

            this.mediaList = new List<MediaInfo>();
            mediaList.AddRange(primaryList);
            mediaList.AddRange(secondaryList);
            mediaList.AddRange(tertiaryList);

            //Adds the medias to the list view.
            foreach (var mi in mediaList)
                mediaListView.Items.Add(mi.Type.ToString() + ", " + mi.Title);

            Cursor.Current = Cursors.Default;
        }
コード例 #8
0
ファイル: TestSuite2.cs プロジェクト: ltj/rentit
        /// <summary>
        /// Helper method to determine if MediaItems are sorted, asc.
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private bool isSortedAsc(MediaInfo[] list)
        {
            MediaInfo first = list[0];

            for (int i = 1; i < list.Length; i++)
            {
                if (string.Compare(first.Title, list[i].Title) > 0)
                {
                    return false;
                }

                first = list[i];
            }
            return true;
        }