Exemple #1
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();
        }
Exemple #2
0
 private void BuildCache()
 {
     Semaphore.Wait();
     Task.Factory.StartNew(() =>
     {
         _logger.Info("Scanning for the first time");
         _trackRepository.AddAll(_apiAdapter.GetTracks());
         _cacheInfoRepository.Update(new CacheInfo {
             TracksUpdated = DateTime.Now
         });
         _logger.Info($"Cache contains {_trackRepository.Count()} tracks.");
         Semaphore.Release();
     }, TaskCreationOptions.PreferFairness);
 }