Example #1
0
        public void Execute(object parameter)
        {
            var exisitingMovieLibrary = _fileController.GetMovieDataFromLocalLibraryFile();
            var movies = new ConcurrentBag <Movie>(_fileController.FindLocalMovieFiles());

            var concurrentMovieList = new ConcurrentBag <Movie>();

            Parallel.ForEach(movies, _parallelOptions, m =>
            {
                var existingMatch = exisitingMovieLibrary.FirstOrDefault(x => x.FileLocation == m.FileLocation && !string.IsNullOrEmpty(x.TagLine) && !string.IsNullOrEmpty(x.Title));
                if (existingMatch != null)
                {
                    concurrentMovieList.Add(existingMatch);
                }
                else
                {
                    var mov = Task.Run(() => _apiController.EnrichMovieMatchedByTitle(m)).Result;
                    concurrentMovieList.Add(mov);

                    //// Yeh......ought to look into issues around API latency to get around this
                    Thread.Sleep(500);
                }
            });

            _commonData.UpdateValue(cd => cd.CommonDataMovies, concurrentMovieList.OrderBy(x => x.Title).ToList());
            _fileController.StoreMovieData(concurrentMovieList.ToList());
        }