Ejemplo n.º 1
0
        private async Task <SyncDetails> SaveAsync(ConcurrentDictionary <int, IEnumerable <Studios.StudioMovie> > buffer, SyncDetails syncDetails, int studioId)
        {
            var pages = buffer.OrderByDescending(e => e.Key).ToList();

            if (pages.Any())
            {
                var studioMovies = pages.SelectMany(e => e.Value.Reverse());
                var moviesToSave = MapMovies(studioMovies, studioId);

                var saved = await _movieRepository.AddRangeAsync(moviesToSave);

                var first = pages.LastOrDefault();
                syncDetails = await UpdateSyncDetailsAsync(syncDetails, studioId, first.Key);

                Console.WriteLine($"Synched ({buffer.Count} pages):\n\nLast sync page: {syncDetails.LastSyncPage}\n\nMovies saved: {saved.Count()}\n\n");

                buffer.Clear();
            }

            return(syncDetails);
        }
Ejemplo n.º 2
0
        private async Task SaveMoviesAsync(IEnumerable <Movie> items)
        {
            //Interlocked.Increment(ref counter);

            foreach (var studioMovie in items)
            {
                _buffer.Add(studioMovie);
            }

            //if (counter % 2 == 0)
            {
                var itemsToSave = _buffer.OrderByDescending(e => e.Duration).ToList();
                _buffer.Clear();
                //Interlocked.Exchange(ref counter, 0);

                Console.WriteLine($"Saving {itemsToSave.Count} videos");
                await _movieRepository.AddRangeAsync(itemsToSave);

                Console.WriteLine("Saved");
            }

            await Task.Delay(10);
        }