public async Task MultiplePagesAsync_PageSizeNotInOptions() { // We create the client using our user, but then access a dataset in a public data // project. We can't run a query "as" the public data project. var projectId = _fixture.ProjectId; var client = BigQueryClient.Create(projectId); var table = client.GetTable(PublicDatasetsProject, PublicDatasetsDataset, ShakespeareTable); var sql = $"SELECT corpus as title, COUNT(word) as unique_words FROM {table} GROUP BY title ORDER BY unique_words DESC LIMIT 13"; // Note that we don't specify any options. That means when we want to read a page at a time later, we'll need to perform the query again. var results = await client.ExecuteQueryAsync(sql, parameters : null); // Iterate over multiple pages automatically to get all results. The query has 13 results. var rows = await results.GetRowsAsync().ToListAsync(); Assert.Equal(13, rows.Count); // Now try getting one page at a time, in the same way we would if we were in a web application. var page1 = await results.ReadPageAsync(5); var page2 = await client.GetQueryResults(results.JobReference, new GetQueryResultsOptions { PageToken = page1.NextPageToken }).ReadPageAsync(5); var page3 = await client.GetQueryResults(results.JobReference, new GetQueryResultsOptions { PageToken = page2.NextPageToken }).ReadPageAsync(5); var titleComparer = new TitleComparer(); Assert.Equal(rows.Take(5), page1.Rows, titleComparer); Assert.Equal(rows.Skip(5).Take(5), page2.Rows, titleComparer); Assert.Equal(rows.Skip(10).Take(5), page3.Rows, titleComparer); Assert.Null(page3.NextPageToken); }
public void MultiplePagesWithStartIndex() { // We create the client using our user, but then access a dataset in a public data // project. We can't run a query "as" the public data project. var projectId = _fixture.ProjectId; var client = BigQueryClient.Create(projectId); var table = client.GetTable(PublicDatasetsProject, PublicDatasetsDataset, ShakespeareTable); var sql = $"SELECT corpus as title, COUNT(word) as unique_words FROM {table} GROUP BY title ORDER BY unique_words DESC LIMIT 20"; var results = client.ExecuteQuery(sql, parameters: null, resultsOptions: new GetQueryResultsOptions { PageSize = 5, StartIndex = 7 }); // Iterate over multiple pages automatically to get all results. The query has 20 results, but // we're asking to start at index 7, so we actually see 13. var rows = results.ToList(); Assert.Equal(13, rows.Count); // Now try getting one page at a time, in the same way we would if we were in a web application. var page1 = results.ReadPage(5); var page2 = client.GetQueryResults(results.JobReference, new GetQueryResultsOptions { PageToken = page1.NextPageToken }).ReadPage(5); var page3 = client.GetQueryResults(results.JobReference, new GetQueryResultsOptions { PageToken = page2.NextPageToken }).ReadPage(5); var titleComparer = new TitleComparer(); Assert.Equal(rows.Take(5), page1.Rows, titleComparer); Assert.Equal(rows.Skip(5).Take(5), page2.Rows, titleComparer); Assert.Equal(rows.Skip(10).Take(5), page3.Rows, titleComparer); Assert.Null(page3.NextPageToken); }
public void ExtractSeriesNameFromFilename() { TitleComparer comparer = new TitleComparer(); string fileName = @"the.chilling.adventures.of.sabrina.s01e07.720p.webrip.hevc.x265.rmteam.mkv"; string expected = "the.chilling.adventures.of.sabrina"; Assert.Equal(expected, comparer.ExtractSeriesNameFromFilename(fileName)); }
public void ExtractSeasonNumberFromFilename_ReturnsSeason() { TitleComparer comparer = new TitleComparer(); string fileName = @"the.chilling.adventures.of.sabrina.s01e07.720p.webrip.hevc.x265.rmteam.mkv"; int expected = 1; Assert.Equal(expected, comparer.ExtractSeasonNumberFromFilename(fileName)); }
public void ExtractSeasonEpisodeFromFilenameAsEpisodeObject_ContainsSeasonEpisode_ReturnsEpObject() { TitleComparer comparer = new TitleComparer(); string fileName = @"the.chilling.adventures.of.sabrina.s01e07.720p.webrip.hevc.x265.rmteam.mkv"; int expectedSeason = 1; int expectedEpisode = 7; Assert.Equal(expectedSeason, comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName).SeasonNumber); Assert.Equal(expectedEpisode, comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName).EpisodeNumberInSeason); }
public void ExtractSeasonEpisodeFromFilenameAsEpisodeObject_ContainsCapitalSeasonEpisode_ReturnsEpObject() { TitleComparer comparer = new TitleComparer(); string fileName = @"Succession.S01E03.BDRip.X264-REWARD.mkv"; int expectedSeason = 1; int expectedEpisode = 3; Assert.Equal(expectedSeason, comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName).SeasonNumber); Assert.Equal(expectedEpisode, comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName).EpisodeNumberInSeason); }
public static int CompareComic(Comic x, Comic y) { var result = string.Compare(x.Author.ToLowerInvariant(), y.Author.ToLowerInvariant(), StringComparison.OrdinalIgnoreCase); if (result != 0) { return(result); } return(TitleComparer.CompareComic(x, y)); }
public void ExtractSeasonEpisodeFromFilenameAsEpisodeObject_ContainsEpisode00_ReturnsEpObject() { TitleComparer comparer = new TitleComparer(); string fileName = @"doctor.who.2005.s12e00.resolution.720p.webrip.hevc.x265.rmteam.mkv"; int expectedSeason = 12; int expectedEpisode = 0; Assert.Equal(expectedSeason, comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName).SeasonNumber); Assert.Equal(expectedEpisode, comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName).EpisodeNumberInSeason); }
public void ExtractSeasonEpisodeFromFilenameAsEpisodeObject_DoesNotContainSeasonEpisode_ReturnsNull() { TitleComparer comparer = new TitleComparer(); string fileName = @"the.chilling.adventures.of.sabrina.mkv"; string expectedMessage = $"Filename does not contain episode number in s##e## format.\r\nParameter name:{fileName}"; // Act & Assert // Exception ex = Assert.Throws<ArgumentException>(() => comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName)); // Assert.Equal(expectedMessage.Substring(0,50), ex.Message.Substring(0,50)); Assert.Null(comparer.ExtractSeasonEpisodeFromFilenameAsEpisodeObject(fileName)); }
public FranchiseEntryTitleComparer( CultureInfo culture, NullComparison nullComparison = NullComparison.NullsFirst) : base(nullComparison) { this.titleComparer = new TitleComparer(culture); this.baseComparer = ComparerBuilder.For <FranchiseEntry>() .OrderBy(this.GetTitleName, this.titleComparer) .ThenBy(entry => entry.GetStartYear()) .ThenBy(entry => entry.GetEndYear()); }
public void FilenameContainsSeriesName_DoesNotContainSeriesName_ReturnsFalse() { TitleComparer comparer = new TitleComparer(); EpisodeForComparingDto episodeObject = new EpisodeForComparingDto() { SeriesName = "The Chilling Adventures of Sabrina", SeasonNumber = 1, EpisodeNumberInSeason = 4, EpisodeTitle = "Witch Academy" }; string fileName = @"doctor.who.2005.s11e10.the.battle.of.ranskoor.av.kolos.720p.web.dl.hevc.x265.rmteam.mkv"; Assert.False(comparer.FilenameContainsSeriesName(episodeObject, fileName)); }
public void FilenameContainsSeriesName_ContainsSeriesName_ReturnsTrue() { TitleComparer comparer = new TitleComparer(); EpisodeForComparingDto episodeObject = new EpisodeForComparingDto() { SeriesName = "The Chilling Adventures of Sabrina", SeasonNumber = 1, EpisodeNumberInSeason = 4, EpisodeTitle = "Witch Academy" }; string fileName = @"the.chilling.adventures.of.sabrina.s01e04.720p.webrip.hevc.x265.rmteam.mkv"; Assert.True(comparer.FilenameContainsSeriesName(episodeObject, fileName)); }
public void GetSeasonEpisodeInNumberFormat_Valid_ReturnTrue() { EpisodeForComparingDto episodeObject = new EpisodeForComparingDto() { SeriesName = "The Orville", SeasonNumber = 2, EpisodeNumberInSeason = 9, EpisodeTitle = "Identity, Part 2" }; TitleComparer comparer = new TitleComparer(); string expected = "2.09"; Assert.Equal(expected, comparer.GetSeasonEpisodeInNumberFormat(episodeObject)); }
static void Main(string[] args) { List <Book> books = Book.InitBooks(); ShowBooks(books); // Sort the books by title // TitleComparer does a compare on BookTitle // We gain the compare on Book by contravariance // Only valid in .NET 4.0! TitleComparer comp = new TitleComparer(); books.Sort(comp); ShowBooks(books); }
public void CreateEpisodeObjectFromFilename_ValidFile_CreatesObject() { TitleComparer comparer = new TitleComparer(); string fileName = @"the.chilling.adventures.of.sabrina.s01e07.720p.webrip.hevc.x265.rmteam.mkv"; int expectedSeason = 1; int expectedEpisode = 7; string expectedTitle = "the chilling adventures of sabrina"; EpisodeForComparingDto epDto = comparer.CreateEpisodeObjectFromFilename(fileName); Assert.Equal(expectedSeason, epDto.SeasonNumber); Assert.Equal(expectedEpisode, epDto.EpisodeNumberInSeason); Assert.Equal(expectedTitle, epDto.SeriesName); }
public void GetSeriesNameInLowercaseAndPeriodsWithoutStartingArticle_ReturnsTrue() { TitleComparer comparer = new TitleComparer(); EpisodeForComparingDto episodeObject = new EpisodeForComparingDto() { SeriesName = "The Chilling Adventures of Sabrina", SeasonNumber = 1, EpisodeNumberInSeason = 4, EpisodeTitle = "Witch Academy" }; string expected = "chilling.adventures.of.sabrina"; string result = comparer.GetSeriesNameInLowercaseAndPeriodsWithoutStartingArticle(episodeObject); Assert.Equal(expected, result); }
public void ContainsSeasonEpisode_DoesContain_ReturnTrue() { EpisodeForComparingDto episodeObject = new EpisodeForComparingDto() { SeriesName = "Counterpart", SeasonNumber = 2, EpisodeNumberInSeason = 9, EpisodeTitle = "You to You" }; string fileName = @"counterpart.s02e09.you.to.you.720p.webrip.hevc.x265.rmteam.mkv"; bool expected = true; TitleComparer comparer = new TitleComparer(); bool result = comparer.FilenameContainsSeasonEpisode(episodeObject, fileName); Assert.Equal(expected, result); }
public ListItemTitleComparer( CultureInfo culture, IComparer <ListItem> otherComparer, Func <ListItem, string> getTitle, Func <Franchise, string> getFranchiseTitle, NullComparison nullComparison = NullComparison.NullsFirst) : base(nullComparison) { this.getTitle = getTitle; this.getFranchiseTitle = getFranchiseTitle; this.titleComparer = new TitleComparer(culture); this.otherComparer = otherComparer; this.titleAndOtherComparer = ComparerBuilder.For <ListItem>() .OrderBy(this.getTitle, this.titleComparer) .ThenBy(otherComparer); }
public ActionResult Index() { List <Book> books = new List <Book>(db.Books); string sorting = Request.Cookies["sorting"]?.Value ?? String.Empty; if (sorting.Equals("byName")) { TitleComparer titleComparer = new TitleComparer(); books.Sort(titleComparer); } else if (sorting.Equals("byYear")) { YearComparer yearComparer = new YearComparer(); books.Sort(yearComparer); } ViewBag.Books = books; return(View()); }
public static MalAnime SearchListForShow(string username, string title) { // Clean out any accented characters from the show title var tempBytes = System.Text.Encoding.GetEncoding("ISO-8859-8").GetBytes(title); title = System.Text.Encoding.UTF8.GetString(tempBytes); var searchRequest = WebRequest.Create(string.Format(MalListUrl, username)) as HttpWebRequest; searchRequest.Method = "GET"; var searchResponse = (HttpWebResponse)searchRequest.GetResponse(); string animeList = string.Empty; using (var reader = new System.IO.StreamReader(searchResponse.GetResponseStream(), ASCIIEncoding.ASCII)) { // this is XML animeList = reader.ReadToEnd(); } var responseAsXml = new XmlDocument(); responseAsXml.LoadXml(animeList); var responseAsJson = JsonConvert.SerializeXmlNode(responseAsXml.GetElementsByTagName("myanimelist")[0]); var malList = JsonConvert.DeserializeObject <MyAnimeList>(responseAsJson); var currentlyWatching = from show in malList.AnimeList.AllAnime where show.MyStatus == MalStatus.Watching select show; MalAnime currentShow = new MalAnime(); try { currentShow = (from show in currentlyWatching where (TitleComparer.Compute(show.Title, title) < 5 || show.Title.ToLower().Contains(title.ToLower())) select show).First(); } catch { //Usually the title from Plex is the English title and not the default Japanese title. Check the Synonyms. foreach (var show in currentlyWatching) { foreach (var altTitle in show.Synonyms.Replace("; ", ";").ToLower().Split(';')) { currentShow = (altTitle.Contains(title.ToLower())) ? show : null; if (currentShow != null) { break; } } if (currentShow != null) { break; } } if (currentShow == null) { // Last resort, split the show by spaces and try to find a word try { foreach (var word in title.Split(' ')) { var showByWord = (from show in currentlyWatching where show.Title.Contains(word) select show); if (showByWord.Any()) { currentShow = showByWord.First(); break; } } } catch (Exception ex) { Logger.CreateLogEntry(LogType.Error, ex, DateTime.Now); currentShow = null; } } } if (string.IsNullOrEmpty(currentShow.Title)) { Logger.CreateLogEntry(LogType.Error, "MAL Search was not successful.", DateTime.Now); throw new Exception("MAL show was not found successfully."); } Logger.CreateLogEntry(LogType.Success, $"MAL API search was successful for {title}. ID: {currentShow.Id} | Total Episodes: {currentShow.Episodes}", DateTime.Now); return(currentShow); }
public bool Equals(string title) { return(TitleComparer.Equals(Title, title)); }
public static async Task <bool> UpdateListAsync(RegisterValues values, PlexRequest plexRequest) { var entries = await GetListForUser(values.UserName); var title = plexRequest.Metadata.GrandparentTitle; AniListAnime currentShow = new AniListAnime(); try { currentShow = entries.Entries .Where(x => TitleComparer.Compute(x.MediaItem.Title.UserPreferred, title) < 5 || x.MediaItem.Title.UserPreferred.ToLower().Contains(title.ToLower())).First(); } catch { try { currentShow = entries.Entries.Select(x => x) .OrderByDescending(x => TitleComparer.Compute(x.MediaItem.Title.UserPreferred.ToLower(), title.ToLower())) .First(); } catch (Exception ex) { Logger.CreateLogEntry(LogType.Error, ex, DateTime.Now); currentShow = null; } } if (currentShow == null) { return(false); } var query = FormUpdateQuery(currentShow.EntryId, currentShow.MediaItem.Id, plexRequest.Metadata.Index); var token = values.AniListAccessToken; HttpWebRequest request = WebRequest.Create(BaseUrl + query) as HttpWebRequest; request.Method = "POST"; request.Headers["Authorization"] = "Bearer " + token; AniListSearchResponse aniListResponse; try { var response = (HttpWebResponse)await request.GetResponseAsync(); using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII)) { var aniListResponseString = reader.ReadToEnd(); aniListResponse = JsonConvert.DeserializeObject <AniListSearchResponse>(aniListResponseString); } } catch (Exception ex) { return(false); } return(true); }