public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            IEnumerable mediaItems = values[0] as IEnumerable;

            if (mediaItems != null)
            {
                if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue))
                {
                    IntelligentString viewAllText = (IntelligentString)values[1];

                    MediaItemFilter filter = values[2] as MediaItemFilter;

                    List <MediaItem> lstMediaItems = new List <MediaItem>();

                    foreach (MediaItem mediaItem in mediaItems)
                    {
                        lstMediaItems.Add(mediaItem);
                    }

                    List <IntelligentString> genres = new List <IntelligentString>(
                        (from mediaItem in lstMediaItems
                         where PassGenre(mediaItem, filter)
                         select mediaItem.Genre).Distinct());

                    genres.Sort();
                    genres.Insert(0, viewAllText);

                    return(new ObservableCollection <IntelligentString>(genres));
                }
            }

            return(new ObservableCollection <IntelligentString>());
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection <Video> videos = values[0] as ObservableCollection <Video>;

            if (videos != null)
            {
                if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue))
                {
                    IntelligentString viewAllText = (IntelligentString)values[1];

                    MediaItemFilter filter = values[2] as MediaItemFilter;

                    ObservableCollection <IntelligentString> selectedGenres = values[3] as ObservableCollection <IntelligentString>;

                    if (selectedGenres != null)
                    {
                        List <IntelligentString> programs = new List <IntelligentString>(
                            (from video in videos
                             where PassProgram(video, viewAllText, filter, selectedGenres.ToArray())
                             select video.Program).Distinct());

                        programs.Sort();
                        programs.Insert(0, viewAllText);

                        return(new ObservableCollection <IntelligentString>(programs));
                    }
                }
            }

            return(new ObservableCollection <IntelligentString>());
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection <Song> songs = values[0] as ObservableCollection <Song>;

            if (songs != null)
            {
                if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue))
                {
                    IntelligentString viewAllText = (IntelligentString)values[1];

                    MediaItemFilter filter = values[2] as MediaItemFilter;

                    ObservableCollection <IntelligentString> selectedGenres = values[3] as ObservableCollection <IntelligentString>;

                    if (selectedGenres != null)
                    {
                        List <IntelligentString> artists = new List <IntelligentString>(
                            (from song in songs
                             where PassArtist(song, viewAllText, filter, selectedGenres.ToArray())
                             select song.Artist).Distinct());

                        artists.Sort();
                        artists.Insert(0, viewAllText);

                        return(new ObservableCollection <IntelligentString>(artists));
                    }
                }
            }

            return(new ObservableCollection <IntelligentString>());
        }
        /// <summary>
        /// Determines whether or not the genre of the specified media item passes throught the filter and should be displayed
        /// </summary>
        /// <param name="mediaItem">Media item being checked</param>
        /// <param name="filter">Filter used to filter media items</param>
        /// <returns>True if the genre of the specified media item passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassGenre(MediaItem mediaItem, MediaItemFilter filter)
        {
            if (IntelligentString.IsNullOrEmpty(mediaItem.Genre))
            {
                return(false);
            }

            if (!filter.PassMediaItem(mediaItem))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Determines whether or not the artist of the specified song passes throught the filter and should be displayed
        /// </summary>
        /// <param name="song">Song being checked</param>
        /// <param name="viewAllText">Text used to view all songs</param>
        /// <param name="filter">Filter used to filter songs</param>
        /// <param name="selectedGenres">Genres selected in the filter</param>
        /// <returns>True if the artist of the specified song passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassArtist(Song song, IntelligentString viewAllText, MediaItemFilter filter, IntelligentString[] selectedGenres)
        {
            if (IntelligentString.IsNullOrEmpty(song.Artist))
            {
                return(false);
            }

            if ((!selectedGenres.Contains(viewAllText)) && (!selectedGenres.Contains(song.Genre)))
            {
                return(false);
            }

            if (!filter.PassMediaItem(song))
            {
                return(false);
            }

            return(true);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection <Song> allSongs = values[0] as ObservableCollection <Song>;

            if (allSongs != null)
            {
                if (allSongs.Count > 0)
                {
                    if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue))
                    {
                        IntelligentString viewAllText = (IntelligentString)values[1];

                        MediaItemFilter filter = values[2] as MediaItemFilter;

                        ObservableCollection <IntelligentString> selectedGenres = values[3] as ObservableCollection <IntelligentString>;

                        if (selectedGenres != null)
                        {
                            ObservableCollection <IntelligentString> selectedArtists = values[4] as ObservableCollection <IntelligentString>;

                            if (selectedArtists != null)
                            {
                                ObservableCollection <IntelligentString> selectedAlbum = values[5] as ObservableCollection <IntelligentString>;

                                if (selectedAlbum != null)
                                {
                                    ObservableCollection <MediaItem> filteredSongs = new ObservableCollection <MediaItem>(
                                        (from song in allSongs
                                         where PassSong(song, viewAllText, filter, selectedGenres.ToArray(), selectedArtists.ToArray(), selectedAlbum.ToArray())
                                         select song));

                                    return(filteredSongs);
                                }
                            }
                        }
                    }
                }
            }

            return(new ObservableCollection <MediaItem>());
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection <Video> allVideos = values[0] as ObservableCollection <Video>;

            if (allVideos != null)
            {
                if ((values[1] != null) && (values[1] != DependencyProperty.UnsetValue))
                {
                    IntelligentString viewAllText = (IntelligentString)values[1];

                    MediaItemFilter filter = values[2] as MediaItemFilter;

                    ObservableCollection <IntelligentString> selectedGenres = values[3] as ObservableCollection <IntelligentString>;

                    if (selectedGenres != null)
                    {
                        ObservableCollection <IntelligentString> selectedPrograms = values[4] as ObservableCollection <IntelligentString>;

                        if (selectedPrograms != null)
                        {
                            ObservableCollection <IntelligentString> selectedSeries = values[5] as ObservableCollection <IntelligentString>;

                            if (selectedSeries != null)
                            {
                                ObservableCollection <MediaItem> filteredVideos = new ObservableCollection <MediaItem>(
                                    (from video in allVideos
                                     where PassVideo(video, viewAllText, filter, selectedGenres.ToArray(), selectedPrograms.ToArray(), selectedSeries.ToArray())
                                     select video));

                                return(filteredVideos);
                            }
                        }
                    }
                }
            }

            return(new ObservableCollection <MediaItem>());
        }
        /// <summary>
        /// Determines whether or not the specified video passes throught the filter and should be displayed
        /// </summary>
        /// <param name="video">Video being checked</param>
        /// <param name="viewAllText">Text used to view all media items</param>
        /// <param name="filter">Filter used to filter videos</param>
        /// <param name="selectedGenres">Genres selected in the filter</param>
        /// <param name="selectedPrograms">Programs selected in the filter</param>
        /// <param name="selectedSeries">Series selected in the filter</param>
        /// <returns>True if the specified video passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassVideo(Video video, IntelligentString viewAllText, MediaItemFilter filter, IntelligentString[] selectedGenres, IntelligentString[] selectedPrograms, IntelligentString[] selectedSeries)
        {
            if ((!selectedGenres.Contains(viewAllText)) && (!selectedGenres.Contains(video.Genre)))
            {
                return(false);
            }

            if ((!selectedPrograms.Contains(viewAllText)) && (!selectedPrograms.Contains(video.Program)))
            {
                return(false);
            }

            if ((!selectedSeries.Contains(viewAllText)) && (!selectedSeries.Contains(video.Series.ToString())))
            {
                return(false);
            }

            if (!filter.PassMediaItem(video))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Determines whether or not the specified song passes throught the filter and should be displayed
        /// </summary>
        /// <param name="song">Song being checked</param>
        /// <param name="viewAllText">Text used to view all media items</param>
        /// <param name="filter">Filter used to filter songs</param>
        /// <param name="selectedGenres">Genres selected in the filter</param>
        /// <param name="selectedArtists">Artists selected in the filter</param>
        /// <param name="selectedAlbum">Album selected in the filter</param>
        /// <returns>True if the specified song passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassSong(Song song, IntelligentString viewAllText, MediaItemFilter filter, IntelligentString[] selectedGenres, IntelligentString[] selectedArtists, IntelligentString[] selectedAlbum)
        {
            if ((!selectedGenres.Contains(viewAllText)) && (!selectedGenres.Contains(song.Genre)))
            {
                return(false);
            }

            if ((!selectedArtists.Contains(viewAllText)) && (!selectedArtists.Contains(song.Artist)))
            {
                return(false);
            }

            if ((!selectedAlbum.Contains(viewAllText)) && (!selectedAlbum.Contains(song.Album)))
            {
                return(false);
            }

            if (!filter.PassMediaItem(song))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Determines whether or not the program of the specified video passes throught the filter and should be displayed
        /// </summary>
        /// <param name="video">Video being checked</param>
        /// <param name="viewAllText">Text used to view all videos</param>
        /// <param name="filter">Filter used to filter videos</param>
        /// <param name="selectedGenres">Genres selected in the filter</param>
        /// <returns>True if the program of the specified video passes throught the filter and should be displayed, false if not</returns>
        private static Boolean PassProgram(Video video, IntelligentString viewAllText, MediaItemFilter filter, IntelligentString[] selectedGenres)
        {
            if (IntelligentString.IsNullOrEmpty(video.Program))
            {
                return(false);
            }

            if ((!selectedGenres.Contains(viewAllText)) && (!selectedGenres.Contains(video.Genre)))
            {
                return(false);
            }

            if (!filter.PassMediaItem(video))
            {
                return(false);
            }

            return(true);
        }