예제 #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();
        }
예제 #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);
 }
예제 #3
0
        private void SendPage(string connectionId, int offset = 0, int limit = 4000)
        {
            var total     = _trackRepository.Count();
            var realLimit = offset + limit > total ? total - offset : limit;
            var tracks    = _trackRepository.GetRange(offset, realLimit);
            var message   = new SocketMessage
            {
                Context = Constants.LibraryBrowseTracks,
                Data    = new Page <Track> {
                    Data = tracks.ToList(), Offset = offset, Limit = limit, Total = total
                },
                NewLineTerminated = true,
            };

            _hub.Publish(new PluginResponseAvailableEvent(message, connectionId));
        }