Example #1
0
        /// <summary>
        /// Updates the list with media items fullfilling the given criteria.
        /// </summary>
        /// <param name="criteria">The criteria used to filter the media.</param>
        internal void UpdateList(MediaCriteria criteria)
        {
            Cursor.Current = Cursors.WaitCursor;
            //Gets the relevant media from the database.
            MediaItems medias;
            try{ medias = RentItProxy.GetMediaItems(criteria);}
            catch {return;}
            //Concatenates the lists contained in the object returned from the database in a new list.
            mediaList = new List<MediaInfo>();
            mediaList.AddRange(medias.Albums);
            mediaList.AddRange(medias.Books);
            mediaList.AddRange(medias.Movies);

            //Adds the items to the list in the user control.
            if (mediaList.Count() > 0 && !Numbering)
                for (int i = 0; i < mediaList.Count() - 1; i++)
                    listBox1.Items.Add(mediaList[i].Title);

            //Same as above but including numbering of media items.
            if (mediaList.Count() > 0 && Numbering)
                for (int i = 0; i < mediaList.Count() - 1; i++)
                    listBox1.Items.Add((i + 1) + ". " + mediaList[i].Title);

            Cursor.Current = Cursors.Default;
        }
Example #2
0
        public SearchResultsControl()
        {
            InitializeComponent();
            rentIt = new RentItClient();

            criteria = new MediaCriteria {
                SearchText = "",
                Genre = "",
                Type = MediaType.Any,
                Limit = -1,
                Offset = 0,
                Order = MediaOrder.AlphabeticalAsc
            };

            TypeFilter.SelectedIndex = 0;
        }
Example #3
0
        /// <author>Kenneth Søhrmann</author>
        /// <summary>
        /// See the interface specification of the method in IRentIt.cs for documentation
        /// of this method.
        /// </summary>
        public MediaItems GetMediaItems(MediaCriteria criteria)
        {
            // If the criteria is a null reference, return null.
            if (criteria == null)
            {
                throw new FaultException<ArgumentException>(
                   new ArgumentException("Null-value submittet as input."));
            }

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

            // The MediaItems-instance to be compiled and returned to the client.
            RentIt.MediaItems mediaItems;
            try
            {
                // Get medias based on the media type.
                IQueryable<RentItDatabase.Media> medias;

                // Determine if the MediaType-value is MediaType.Any (null-value indicates MediaType.Any)
                bool mediaTypeAny = true;
                mediaTypeAny = criteria.Type == MediaType.Any;

                // If the value is specified to "any", all medias of the database is retrieved.
                if (mediaTypeAny)
                {
                    medias = from media in db.Medias
                             where media.active
                             select media;
                }
                else
                {
                    medias = from media in db.Medias
                             where media.Media_type.name.Equals(Util.StringValueOfMediaType(criteria.Type)) && media.active
                             select media;
                }

                // Sort the above medias as requested in the criterias.
                IQueryable<Media> orderedMedias = Util.OrderMedia(db, medias, criteria);

                // Filter the above medias after the genre if specified in the criteria.
                if (!string.IsNullOrEmpty(criteria.Genre))
                {
                    orderedMedias = from media in orderedMedias
                                    where media.Genre.name.Equals(criteria.Genre)
                                    select media;
                }

                if (!string.IsNullOrEmpty(criteria.SearchText))
                {
                    List<Media> list = new List<Media>();
                    foreach (Media m in orderedMedias)
                    {
                        if (Util.ContainsIgnoreCase(Util.GetMediaMetadataAsString(m), criteria.SearchText))
                        {
                            list.Add(m);
                        }
                    }

                    orderedMedias = list.AsQueryable();

                    /*
                    This was the original code, but it could not be translated to SQL statements by LINQ to SQL:
                    orderedMedias =
                        orderedMedias.Where(
                        media => Util.ContainsIgnoreCase(Util.GetMediaMetadataAsString(media), criteria.SearchText));
                    */
                }

                // Apply the offset and limit of the number of medias to return as specified.
                IQueryable<Media> finalMediaList;
                if (criteria.Limit < 0)
                    finalMediaList = orderedMedias.Skip(criteria.Offset);
                else
                    finalMediaList = orderedMedias.Skip(criteria.Offset).Take(criteria.Limit);

                mediaItems = Util.CompileMedias(finalMediaList, this);
            }
            catch (Exception e)
            {
                // Might be thrown if the service cannot communicate with the database properly.
                throw new FaultException<Exception>(
                    new Exception("An internal error has occured. This is not related to the input: " + e.Message));
            }

            return mediaItems;
        }
Example #4
0
        private void GetRandomGenreMedias()
        {
            string[] genres = RentItProxy.GetAllGenres(Mtype);

            var random = new Random();
            string randomGenre = genres[random.Next(genres.Length)];

            var mc = new MediaCriteria
            {
                Genre = randomGenre,
                Limit = 10,
                SearchText = "",
                Type = mtype
            };

            RentItProxy.GetMediaItems(mc);
        }
Example #5
0
        /// <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 :(";
            }
        }
Example #6
0
        /// <summary>
        /// Get ten most popular medias
        /// </summary>
        private void GetMostPopular()
        {
            // 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, // only ten most pouplar
                Order = RentIt.MediaOrder.PopularityDesc,
                Genre = "",
                SearchText = ""
            };

            popularMediaGrid.MediaCriteria = mc;
        }
Example #7
0
        /// <summary>
        /// Get ten highest rated medias
        /// </summary>
        private void GetHighestRated()
        {
            // we need valid prerequisites to query the webservice
            if (mtype == RentIt.MediaType.Any || RentItProxy == null) return;

            // build search criteria
            var mc = new MediaCriteria
            {
                Type = mtype,
                Limit = 10, // only ten highest rated
                Order = MediaOrder.RatingDesc,
                Genre = "",
                SearchText = ""
            };

            bestMediaGrid.MediaCriteria = mc;
        }
Example #8
0
        /// <summary>
        /// Initiates a search for media, using the information entered in the
        /// text field and the selected media type in the combo box.
        /// </summary>
        private void Search()
        {
            var comboBoxType = (string)TypeComboBox.SelectedItem;

            MediaType mediaType;
            if (comboBoxType.Equals("Movies"))
                mediaType = MediaType.Movie;
            else if (comboBoxType.Equals("Music"))
                mediaType = MediaType.Album;
            else if (comboBoxType.Equals("Books"))
                mediaType = MediaType.Book;
            else
                mediaType = MediaType.Any;

            var criteria = new MediaCriteria
            {
                SearchText = SearchTextBox.Text,
                Genre = "",
                Type = mediaType,
                Limit = -1,
                Offset = 0,
                Order = MediaOrder.AlphabeticalAsc
            };

            Cursor.Current = Cursors.WaitCursor;
            // switch to search results, using criteria object
            var search = new SearchResultsControl { RentItProxy = RentItProxy, Criteria = criteria };
            //(ParentForm as MainForm).Content = search;
            FireContentChangeEvent(search, MainForm.Titles.SearchResults);
            Cursor.Current = Cursors.Default;
        }
Example #9
0
        /// <summary>
        /// Updates the 3 lists by querying the server.
        /// </summary>
        private void UpdateLists()
        {
            Cursor.Current = Cursors.WaitCursor;
            var criteria = new MediaCriteria
            {
                Genre = "",
                Limit = 10,
                Offset = 0,
                Order = MediaOrder.RatingDesc,
                SearchText = "",
                Type = MediaType.Movie
            };

            moviesList.UpdateList(criteria);

            criteria.Type = MediaType.Book;
            booksList.UpdateList(criteria);

            criteria.Type = MediaType.Album;
            musicList.UpdateList(criteria);

            Cursor.Current = Cursors.Default;
        }
Example #10
0
        /// <author>Kenneth Søhrmann</author>
        /// <summary>
        /// Orders the supplied media collection with a specific ordering.
        /// </summary>
        /// <param name="db">The database context to use.</param>
        /// <param name="mediaItems">The media items to order.</param>
        /// <param name="criteria">The criteria containing the order to use.</param>
        /// <returns>The collection of media items in the specified order.</returns>
        public static IQueryable<RentItDatabase.Media> OrderMedia(
            DatabaseDataContext db, IQueryable<RentItDatabase.Media> mediaItems, MediaCriteria criteria)
        {
            switch (criteria.Order)
            {
                case MediaOrder.AlphabeticalAsc:
                    return from media in mediaItems orderby media.title select media;

                case MediaOrder.AlphabeticalDesc:
                    return from media in mediaItems orderby media.title descending select media;

                case MediaOrder.PopularityAsc:
                    return from media in mediaItems
                           join rental in db.Rentals on media.id equals rental.media_id into mediaRentals
                           orderby mediaRentals.Count()
                           select media;

                case MediaOrder.PopularityDesc:
                    return from media in mediaItems
                           join rental in db.Rentals on media.id equals rental.media_id into mediaRentals
                           orderby mediaRentals.Count() descending
                           select media;

                case MediaOrder.RatingAsc:
                    return from media in mediaItems orderby media.Rating.avg_rating select media;

                case MediaOrder.RatingDesc:
                    return from media in mediaItems orderby media.Rating.avg_rating descending select media;

                case MediaOrder.ReleaseDateAsc:
                    return from media in mediaItems orderby media.release_date select media;

                case MediaOrder.ReleaseDateDesc:
                    return from media in mediaItems orderby media.release_date descending select media;

                case MediaOrder.PriceAsc:
                    return from media in mediaItems orderby media.price select media;

                case MediaOrder.PriceDesc:
                    return from media in mediaItems orderby media.price descending select media;

                default:
                    return mediaItems;
            }
        }
Example #11
0
        public void GetMediaItemsTest8()
        {
            RentItClient target = new RentItClient();
            MediaCriteria criteria = new MediaCriteria()
            {
                Limit = -1,
                Order = MediaOrder.AlphabeticalAsc,
            };

            MediaItems actual;
            actual = target.GetMediaItems(criteria);

            Assert.IsTrue(this.isSortedAsc(actual.Albums));
        }
Example #12
0
        public void GetMediaItemsTest7()
        {
            RentItClient target = new RentItClient();
            MediaCriteria criteria = new MediaCriteria()
            {
                Limit = -1,
                Type = MediaType.Album,
                SearchText = "The CUre"
            };

            MediaItems actual;
            actual = target.GetMediaItems(criteria);

            Assert.IsTrue(actual.Albums.Length > 0);
            Assert.IsTrue(actual.Songs.Length == 0);
            Assert.IsTrue(actual.Movies.Length == 0);
            Assert.IsTrue(actual.Books.Length == 0);
        }
Example #13
0
        public void GetMediaItemsTest6()
        {
            RentItClient target = new RentItClient();
            MediaCriteria criteria = new MediaCriteria()
            {
                Limit = -1,
            };

            MediaItems actual;
            actual = target.GetMediaItems(criteria);

            Assert.IsTrue(actual.Albums.Length > 0);
            Assert.IsTrue(actual.Songs.Length > 0);
            Assert.IsTrue(actual.Movies.Length > 0);
            Assert.IsTrue(actual.Books.Length > 0);
        }