コード例 #1
0
        private static MovieIdentifier CreateMovieId(int year, XmlNode titleLink)
        {
            var title   = titleLink.InnerText;
            var movieId = new MovieIdentifier
            {
                Year  = year,
                Title = title
            };

            return(movieId);
        }
コード例 #2
0
        private static List <MovieIdentifier> ExtractMovieIds(int year, XmlNode topGrossingTable)
        {
            var movieIds = new List <MovieIdentifier>();

            foreach (XmlNode n in topGrossingTable.ChildNodes)
            {
                var titleLink = n.SelectSingleNode(".//a");
                if (titleLink != null && titleLink.ParentNode.Name != "sup") // not a superscript link
                {
                    MovieIdentifier movieId = CreateMovieId(year, titleLink);
                    movieIds.Add(movieId);
                }
            }

            return(movieIds);
        }
コード例 #3
0
        private static async Task <string> CreateRequestUri(MovieIdentifier m)
        {
            var values = new Dictionary <string, string>
            {
                { "t", m.Title },
                { "y", m.Year.ToString() },
                { "plot", "short" },
                { "r", "json" },
                { "type", "movie" }
            };

            string query;

            using (var content = new FormUrlEncodedContent(values))
            {
                query = await content.ReadAsStringAsync();
            }
            var requestUri = "?" + query;

            return(requestUri);
        }
コード例 #4
0
        private static async Task <ContestantRequest> GetContestantFromOmdbApi(MovieIdentifier m)
        {
            try
            {
                using (var client = CreateClient())
                {
                    var requestUri = await CreateRequestUri(m);

                    var response = await client.GetAsync(requestUri);

                    response.EnsureSuccessStatusCode();
                    var movieContestant = await CreateContestant(response);

                    return(movieContestant);
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to get contestant info for movie {m.Title} ({m.Year}).", ex);
            }
        }