예제 #1
0
        private static int ExtractReviewsFromFile(MovieRepository repo, StreamReader reader)
        {
            var c               = 0;
            int movieid         = 0;
            var reviewsimported = 0;

            var itemsPerCompany = 0;

            while (c < Int32.MaxValue && !reader.EndOfStream)
            {
                var line = reader.ReadLine();
                if (!string.IsNullOrEmpty(line))
                {
                    if (line.EndsWith(":"))
                    {
                        movieid         = Int32.Parse(line.Replace(":", ""));
                        itemsPerCompany = 0;
                        Console.WriteLine(movieid);
                    }
                    else
                    {
                        if (itemsPerCompany < 5)
                        {
                            var items = line.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                            var r = new Review
                            {
                                MovieId = movieid,
                                UserId  = Int32.Parse(items[0]),
                                Rating  = Int32.Parse(items[1]),
                                Date    = DateTime.Parse(items[2])
                            };
                            itemsPerCompany++;

                            var existingReviews = repo.GetReviewsByUserAndMovie(r.UserId, movieid);

                            if (existingReviews.Count() == 0)
                            {
                                repo.AddReview(r);
                            }
                            reviewsimported++;
                        }
                    }

                    c++;
                }
            }

            return(reviewsimported);
        }