public GenreCollection(GenreCollection toClone) : this(toClone.genreType)
 {
     foreach (string genre in toClone)
     {
         this.Add(genre);
     }
 }
        /// <summary>
        /// Puts a single content item through filtering
        /// </summary>
        /// <param name="content">Content to filter</param>
        /// <param name="genre">Genre content must belong to</param>
        /// <param name="yearFilter">Enable for year filter</param>
        /// <param name="minYear">Minimum for year filter</param>
        /// <param name="maxYear">Maximum for year filter</param>
        /// <param name="nameFilter">String that must be contained in content name - empty string disables filter</param>
        /// <returns></returns>
        public bool ApplyContentFilter(Content content, bool genreEnable, GenreCollection genre, bool yearFilter, int minYear, int maxYear, string nameFilter)
        {
            // Apply genre filter
            bool genreMatch = !genreEnable;

            if (content.DatabaseGenres != null && !genreMatch)
            {
                foreach (string contentGenre in content.DatabaseGenres)
                {
                    if (genre.Contains(contentGenre))
                    {
                        genreMatch = true;
                        break;
                    }
                }
            }

            // Apply year filter
            bool yearMatch = !yearFilter || (content.DatabaseYear >= minYear && content.DatabaseYear <= maxYear);

            // Apply text filter
            bool nameMatch = string.IsNullOrEmpty(nameFilter) || content.DatabaseName.ToLower().Contains(nameFilter.ToLower());

            bool test = genreMatch && yearMatch && nameMatch;

            if (!test)
            {
                test = true;
            }

            // Check if movie is in the folder
            return(genreMatch && yearMatch && nameMatch);
        }
        /// <summary>
        /// Builds a list of content matching filter that is contained within a root folder
        /// </summary>
        /// <param name="genre">Filter for genre type - use "All" to disable filter</param>
        /// <param name="contents">List to add content to</param>
        /// <param name="yearFilter">Enables year filtering</param>
        /// <param name="minYear">Minimum for year filter</param>
        /// <param name="maxYear">Maximum for year filter</param>
        /// <param name="nameFilter">String that must be contained in content name - empty string disables filter</param>
        public void GetContent(bool recursive, bool genreEnable, GenreCollection genre, List <Content> contents, bool yearFilter, int minYear, int maxYear, string nameFilter)
        {
            // Go through all movies
            ContentCollection contentCollection = GetContentCollection();

            lock (contentCollection.ContentLock)
            {
                //Console.WriteLine(contentCollection.ToString() + " lock get");
                foreach (Content content in contentCollection)
                {
                    // Apply genre filter
                    bool genreMatch = false;
                    if (content.DatabaseGenres != null && !genreMatch)
                    {
                        foreach (string contentGenre in content.DatabaseGenres)
                        {
                            if (genre.Contains(contentGenre))
                            {
                                genreMatch = true;
                                break;
                            }
                        }
                    }

                    // Apply year filter
                    bool yearMatch = !yearFilter || (content.DatabaseYear >= minYear && content.DatabaseYear <= maxYear);

                    // Apply text filter
                    bool nameMatch = string.IsNullOrEmpty(nameFilter) || content.DatabaseName.ToLower().Contains(nameFilter.ToLower());

                    // Check if movie is in the folder
                    if (ContainsContent(content, recursive) && ApplyContentFilter(content, genreEnable, genre, yearFilter, minYear, maxYear, nameFilter))
                    {
                        contents.Add(content);
                    }
                }
            }
            //Console.WriteLine(contentCollection.ToString() + " release get");
        }
        public override bool Equals(object obj)
        {
            if (!(obj is GenreCollection))
            {
                return(false);
            }

            GenreCollection collObj = obj as GenreCollection;

            if (this.Count != collObj.Count)
            {
                return(false);
            }

            for (int i = 0; i < this.Count; i++)
            {
                if (this[i] != collObj[i])
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Get available genres from content
        /// </summary>
        /// <param name="contents"></param>
        /// <returns></returns>
        public GenreCollection GetGenres()
        {
            GenreCollection genres = new GenreCollection(this.ContentType);

            switch (this.ContentType)
            {
            case ContentType.Movie:
                for (int i = 0; i < Organization.Movies.Count; i++)
                {
                    foreach (string genre in Organization.Movies[i].DatabaseGenres)
                    {
                        if (!genres.Contains(genre))
                        {
                            genres.Add(genre);
                        }
                    }
                }
                break;

            case ContentType.TvShow:
                for (int i = 0; i < Organization.Shows.Count; i++)
                {
                    foreach (string genre in Organization.Shows[i].DatabaseGenres)
                    {
                        if (!genres.Contains(genre))
                        {
                            genres.Add(genre);
                        }
                    }
                }
                break;
            }


            return(genres);
        }
Example #6
0
        /// <summary>
        /// Gets the list of content matching a set of filters that are contained within root folder(s)
        /// </summary>
        /// <param name="folders">Root folders to look for content</param>
        /// <param name="genreFilter">Filter for genre type of movie - use "All" to disable filter</param>
        /// <param name="yearFilter">Enables year filtering</param>
        /// <param name="minYear">Minimum for year filter</param>
        /// <param name="maxYear">Maximum for year filter</param>
        /// <param name="nameFilter">String that must be contained in movie name - empty string disables filter</param>
        /// <returns>List of movies from root folder that match filters</returns>
        public static List <Content> GetContentFromRootFolders(List <ContentRootFolder> folders, bool recursive, bool genreEnable, GenreCollection genreFilter, bool yearFilter, int minYear, int maxYear, string nameFilter)
        {
            // Initialize movies list
            List <Content> folderMovies = new List <Content>();

            // Go through each content folder and get movie from folders that match name
            foreach (ContentRootFolder folder in folders)
            {
                folder.GetContent(recursive, genreEnable, genreFilter, folderMovies, yearFilter, minYear, maxYear, nameFilter);
            }

            // Returns list of movies
            return(folderMovies);
        }