Example #1
0
        private void DeltaUpdate(DateTime after)
        {
            Semaphore.Wait();
            Task.Factory.StartNew(() =>
            {
                _logger.Info($"Scanning changes after {after}");
                var libraryPaths = _apiAdapter.GetTrackPaths();
                var paths        = _trackRepository.GetCachedPaths().ToArray();
                var missingPaths = paths.Except(libraryPaths).ToList();
                if (missingPaths.Count > 0)
                {
                    _trackRepository.RemoveAll(missingPaths);
                    _logger.Info($"Removed {missingPaths.Count} tracks from cache");
                }

                var delta = _apiAdapter.GetSyncDelta(paths, after);
                _trackRepository.RemoveAll(delta.DeletedFiles);
                _trackRepository.Insert(_apiAdapter.GetTracks(delta.NewFiles));
                _trackRepository.Update(_apiAdapter.GetTracks(delta.UpdatedFiles));
                _cacheInfoRepository.Update(new CacheInfo {
                    TracksUpdated = DateTime.Now
                });
                _logger.Info($"Cache contains {_trackRepository.Count()} tracks. {delta}");
                Semaphore.Release();
            }, TaskCreationOptions.PreferFairness);
        }
Example #2
0
        private void PerformDeltaUpdate(DateTime after)
        {
            _logger.Info($"Scanning changes after {after}");
            var libraryPaths = _apiAdapter.GetTrackPaths().ToArray();
            var paths        = _trackRepository.GetCachedPaths().ToArray();
            var missingPaths = paths.Except(libraryPaths).ToArray();

            for (int i = 0; i < paths.Length; i++)
            {
                if (paths[i] == null)
                {
                    _logger.Info(i + " was null");
                }
            }

            if (missingPaths.Length > 0)
            {
                _trackRepository.RemoveAll(missingPaths);
                _logger.Info($"Removed {missingPaths.Length} tracks from cache");
            }

            var delta = _apiAdapter.GetSyncDelta(paths, after);

            _logger.Debug($"Delta contains {delta}");
            _trackRepository.RemoveAll(delta.GetDeletedFiles());
            _trackRepository.Insert(_apiAdapter.GetTracks(delta.GetNewFiles()));
            _trackRepository.Update(_apiAdapter.GetTracks(delta.GetUpdatedFiles()));
            _cacheInfoRepository.Update(new CacheInfo {
                TracksUpdated = DateTime.Now
            });
            _logger.Info($"Cache contains {_trackRepository.Count()} tracks.");
            _semaphore.Release();
        }