Пример #1
0
        static void Main(string[] args)
        {
            string regions = System.Configuration.ConfigurationManager.AppSettings["regions"];

            string[] splitRegions = regions.Split(',');

            RetrievalService rs = new RetrievalService(splitRegions);

            RetrievalService.FullResponse fr = rs.GetNowPlaying();

            var connStr = System.Configuration.ConfigurationManager.
                          ConnectionStrings["movieDBConnStr"].ConnectionString;
            PersistenceService ps = new PersistenceService(connStr);

            ps.processData(fr);
        }
Пример #2
0
        public bool processData(RetrievalService.FullResponse fullResponse)
        {
            // STEP 1: populate movies, where necessary
            truncateMovieStageTable();

            var movies = (from result in fullResponse.nowPlaying
                          from movie in result.results
                          select movie).Distinct().ToList();

            foreach (RetrievalService.NowPlayingResults.movie m in movies)
            {
                addMoviesToStagingTable(m);
            }

            mergeMovies();

            // STEP 2: populate regions, where necessary
            var productionCountries = (from keypair in fullResponse.details
                                       from country in keypair.Value.production_countries
                                       select country
                                       );
            var playingCountries = (from result in fullResponse.nowPlaying
                                    where !productionCountries.Any(x => x.iso_3166_1.Equals(result.region))
                                    select new RetrievalService.MovieDetails.ProductionCountry
            {
                iso_3166_1 = result.region,
                name = ""
            });
            var countries = productionCountries.Union(playingCountries).Distinct().ToList();

            foreach (RetrievalService.MovieDetails.ProductionCountry country in countries)
            {
                addRegionsWhereNeeded(country);
            }

            // STEP 3: populate the Movie-Region cross-ref table
            truncateMovieRegionStageTable();

            var moviesShowingInEachCountry = (from result in fullResponse.nowPlaying
                                              from movie in result.results
                                              select new Tuple <int, string>(movie.id, result.region))
                                             .Distinct().ToList();

            foreach (Tuple <int, string> a in moviesShowingInEachCountry)
            {
                populateTupleInStagingTable(a.Item1, a.Item2);
            }

            mergeMovieRuns();

            // STEP 4: populate genres where necessary
            var genres = (from keyPair in fullResponse.details
                          from g in keyPair.Value.genres
                          select g).Distinct().ToArray();

            foreach (RetrievalService.MovieDetails.Genre g in genres)
            {
                addGenre(g);
            }

            // STEP 5: insert into GenreMovie where necessary
            var moviesByGenre = (from keypair in fullResponse.details
                                 from g in keypair.Value.genres
                                 select new Tuple <int, int>(g.id, keypair.Key))
                                .Distinct().ToArray();

            foreach (Tuple <int, int> mg in moviesByGenre)
            {
                insertIntoGenreMovie(mg.Item1, mg.Item2);
            }

            // STEP 6: insert into MovieProducedInCountry where necessary
            var moviesByProducedIn = (from keypair in fullResponse.details
                                      from country in keypair.Value.production_countries
                                      select new Tuple <int, string>(keypair.Key, country.iso_3166_1))
                                     .Distinct().ToArray();

            foreach (Tuple <int, string> mc in moviesByProducedIn)
            {
                InsertIntoProducedIn(mc.Item1, mc.Item2);
            }

            // STEP 7: insert into PersonCredit
            var crewByMovie = (from keypair in fullResponse.credits
                               from crewEntry in keypair.Value.crew
                               where crewEntry.job.Equals("Director")
                               select new Tuple <int, string>(keypair.Key, crewEntry.name))
                              .Distinct().ToArray();

            foreach (Tuple <int, string> mc in crewByMovie)
            {
                InsertIntoCredits(mc.Item1, mc.Item2);
            }

            // STEP 8: insert reviews, where necessary
            var AuthorReviews = (from keypair in fullResponse.reviews
                                 from reviewSet in keypair.Value
                                 from review in reviewSet.results
                                 select new Tuple <string, int, RetrievalService.MovieReviews.Result> (review.author, keypair.Key, review))
                                .Distinct().ToArray();

            foreach (Tuple <string, int, RetrievalService.MovieReviews.Result> t in AuthorReviews)
            {
                InsertIntoReviews(t.Item1, t.Item2, t.Item3);
            }
            return(true);
        }