public static MovieConfiguration?FindBestMatchingShow(string filename, [NotNull] IEnumerable <MovieConfiguration> shows) { IEnumerable <MovieConfiguration> showItems = shows as MovieConfiguration[] ?? shows.ToArray(); IEnumerable <MovieConfiguration> showsMatchAtStart = showItems .Where(item => FileHelper.SimplifyAndCheckFilenameAtStart(filename, item.ShowName)); IEnumerable <MovieConfiguration> matchAtStart = showsMatchAtStart as MovieConfiguration[] ?? showsMatchAtStart.ToArray(); if (matchAtStart.Any()) { return(matchAtStart.OrderByDescending(s => s.ShowName.Length).First()); } IEnumerable <MovieConfiguration> otherMatchingShows = FindMatchingShows(filename, showItems); return(otherMatchingShows.OrderByDescending(s => s.ShowName.Length).FirstOrDefault()); }
public static ShowItem FindBestMatchingShow(FileInfo fi, [NotNull] IEnumerable <ShowItem> shows) { IEnumerable <ShowItem> showItems = shows as ShowItem[] ?? shows.ToArray(); IEnumerable <ShowItem> showsMatchAtStart = showItems .Where(item => FileHelper.SimplifyAndCheckFilenameAtStart(fi.Name, item.ShowName)); IEnumerable <ShowItem> matchAtStart = showsMatchAtStart as ShowItem[] ?? showsMatchAtStart.ToArray(); if (matchAtStart.Any()) { return(matchAtStart.OrderByDescending(s => s.ShowName.Length).First()); } IEnumerable <ShowItem> otherMatchingShows = FindMatchingShows(fi, showItems); return(otherMatchingShows.OrderByDescending(s => s.ShowName.Length).FirstOrDefault()); }