public static IndexDifferences FindDifferences( IFileSystem fileSystem, IEnumerable <LucenePackage> indexedPackages, CancellationToken cancellationToken, Action <SynchronizationState> setState, SynchronizationMode mode) { setState(SynchronizationState.ScanningFiles); var fileSystemPackages = fileSystem.GetFiles(string.Empty, "*" + Constants.PackageExtension, true) .WithCancellation(cancellationToken) .Where(file => !fileSystem.IsTempFile(file)) .ToArray(); setState(SynchronizationState.ScanningIndex); var indexedPackagesByPath = indexedPackages .WithCancellation(cancellationToken) .ToDictionary(pkg => pkg.Path, StringComparer.InvariantCultureIgnoreCase); setState(SynchronizationState.Comparing); var calc = new IndexDifferenceCalculator(fileSystem, fileSystemPackages, indexedPackagesByPath); return(calc.Calculate(mode)); }
public static IndexDifferences FindDifferences( IFileSystem fileSystem, IEnumerable<LucenePackage> indexedPackages, CancellationToken cancellationToken, Action<SynchronizationState> setState, SynchronizationMode mode) { setState(SynchronizationState.ScanningFiles); var fileSystemPackages = fileSystem.GetFiles(string.Empty, "*" + Constants.PackageExtension, true) .WithCancellation(cancellationToken) .Where(file => !fileSystem.IsTempFile(file)) .ToArray(); setState(SynchronizationState.ScanningIndex); var indexedPackagesByPath = indexedPackages .WithCancellation(cancellationToken) .ToDictionary(pkg => pkg.Path, StringComparer.InvariantCultureIgnoreCase); setState(SynchronizationState.Comparing); var calc = new IndexDifferenceCalculator(fileSystem, fileSystemPackages, indexedPackagesByPath); return calc.Calculate(mode); }
private async Task AddToIndex(string fullPath) { if (FileSystem.IsTempFile(fullPath)) { return; } var existingPackage = PackageRepository.LoadFromIndex(fullPath); if (existingPackage != null && !IndexDifferenceCalculator.TimestampsMismatch( existingPackage, FileSystem.GetLastModified(fullPath))) { return; } var package = PackageRepository.LoadFromFileSystem(fullPath); await Indexer.AddPackageAsync(package, CancellationToken.None); }
public async Task SynchronizeIndexWithFileSystemAsync(SynchronizationMode mode, CancellationToken cancellationToken) { lock (synchronizationStatusLock) { if (synchronizationStatus.SynchronizationState != SynchronizationState.Idle) { throw new InvalidOperationException("Already running"); } UpdateSynchronizationStatus(SynchronizationState.ScanningFiles); } try { var differences = IndexDifferenceCalculator.FindDifferences( FileSystem, PackageRepository.LucenePackages, cancellationToken, UpdateSynchronizationStatus, mode); await SynchronizeIndexWithFileSystemAsync(differences, cancellationToken); } finally { UpdateSynchronizationStatus(SynchronizationState.Idle); } }