//[MethodImpl(MethodImplOptions.Synchronized)] public void Run() { // TODO get rid of current and use the marker file instead? DateTime start = DateTime.Now; inProgress = true; if (directoryProviderLock == null) { directoryProviderLock = parent.searchFactory.GetLockableDirectoryProviders()[directoryProvider]; directoryProvider = null; } try { lock (directoryProviderLock) { int oldIndex = parent.current; int index = parent.current == 1 ? 2 : 1; DirectoryInfo sourceFile = new DirectoryInfo(source); DirectoryInfo destinationFile = new DirectoryInfo(Path.Combine(destination, index.ToString())); // TODO make smart a parameter try { log.Info("Copying " + sourceFile + " into " + destinationFile); FileHelper.Synchronize(sourceFile, destinationFile, true); parent.current = index; } catch (IOException e) { // Don't change current log.Error("Unable to synchronize source of " + parent.indexName, e); return; } try { File.Delete(Path.Combine(destination, "current" + oldIndex)); } catch (IOException e) { log.Warn("Unable to remove previous marker file from source of " + parent.indexName, e); } try { File.Create(Path.Combine(destination, "current" + index)).Dispose(); } catch (IOException e) { log.Warn("Unable to create current marker in source of " + parent.indexName, e); } } } finally { inProgress = false; } log.InfoFormat("Copy for {0} took {1}.", parent.indexName, (DateTime.Now - start)); }