예제 #1
0
        private void ComputeNewState(FileSystemTreeSnapshot newSnapshot)
        {
            _fileLoadingOperationProcessor.Execute(new OperationInfo <OperationResultEventArgs> {
                OnBeforeExecute = args => OnFilesLoading(args),
                OnAfterExecute  = args => OnFilesLoaded(args),
                Execute         = _ => {
                    Logger.Log("Computing new state of file database from file system tree.");
                    var sw = Stopwatch.StartNew();

                    var oldState = _currentFileDatabase;
                    var newState = _fileDatabaseFactory.CreateIncremental(oldState, newSnapshot);

                    sw.Stop();
                    Logger.Log(">>>>>>>> Done computing new state of file database from file system tree in {0:n0} msec.",
                               sw.ElapsedMilliseconds);
                    Logger.LogMemoryStats();

                    // Swap states
                    lock (_lock) {
                        _currentFileDatabase = newState;
                    }

                    return(new OperationResultEventArgs());
                }
            });
        }
예제 #2
0
        private void ComputeNewState(
            FileSystemTreeSnapshot previousSnapshot,
            FileSystemTreeSnapshot newSnapshot,
            FullPathChanges fullPathChanges)
        {
            _operationProcessor.Execute(new OperationHandlers {
                OnBeforeExecute = info =>
                                  OnFilesLoading(info),

                OnError = (info, error) => {
                    _currentTreeVersion = newSnapshot.Version;
                    OnFilesLoaded(new FilesLoadedResult {
                        OperationInfo = info,
                        Error         = error,
                        TreeVersion   = newSnapshot.Version
                    });
                },

                Execute = info => {
                    using (new TimeElapsedLogger("Computing new state of file database")) {
                        var oldState = _currentFileDatabase;
                        var newState = _fileDatabaseFactory.CreateIncremental(
                            oldState,
                            previousSnapshot,
                            newSnapshot,
                            fullPathChanges,
                            fileDatabase => {
                            // Store and activate intermediate new state (atomic operation).
                            _currentFileDatabase = fileDatabase;
                            OnFilesLoadingProgress(info);
                        });
                        // Store and activate final new state (atomic operation).
                        _currentFileDatabase = newState;
                    }
                    _currentTreeVersion = newSnapshot.Version;
                    OnFilesLoaded(new FilesLoadedResult {
                        OperationInfo = info,
                        TreeVersion   = newSnapshot.Version
                    });
                }
            });
        }