public void SetUp()
        {
            _fileSystemListener = new FileSystemListener();
            _fileSystemListener.FolderSystemChanged += HandleFolderSystemChanged;
            _eventArgs = null;

            DirectoryUtility.EnsureClearFolder(FolderName);
        }
        protected virtual void OnFolderSystemChanged(string oldPath, string newPath)
        {
            if (FolderSystemChanged != null)
            {
                try
                {
                    FileSystemChangeEventArgs args = new FileSystemChangeEventArgs(oldPath, newPath);
                    FolderSystemChanged(this, args);
                }
                catch(PathTooLongException)
                {

                }
            }
        }
 private void HandleFolderSystemChanged(object sender, FileSystemChangeEventArgs e)
 {
     _eventArgs = e;
 }
        private void Initialize(bool appRunOnStartup)
        {
            bool cacheFolderCreated;
            _filteredCacheItems = ReadCache(appRunOnStartup, out _cacheUpToDate, out cacheFolderCreated, out _lastFullScanTime);
            _fileSystemChanges = new FileSystemChanges();
            if (cacheFolderCreated)
            {
                string cacheFolder = GetCacheFolder();
                try
                {
                    FileSystemChangeEventArgs e = new FileSystemChangeEventArgs(null, cacheFolder);
                    HandleFolderSystemChanged(this, e);
                }
                catch (PathTooLongException)
                {

                }
            }

            //Listen to the changes in the whole system to update the fullCache.
            //This handler should be bound just after reading the full cache to ensure that _fullCache is initialized.
            _fileSystemListener.FolderSystemChanged += HandleFolderSystemChanged;
            _fileSystemListener.StartListening(null);

            //Parse file system fully (asynchronously).
            if (!_cacheUpToDate)
            {
                StartFileSystemParsing();
            }
        }
        private void HandleFolderSystemChanged(object sender, FileSystemChangeEventArgs e)
        {
            lock (_cacheSync)
            {
                _fileSystemChanges.Changes.Add(e);

                //Though we write the cache back to file system in finalizer,
                //we try to write it periodically also (to minimize the effect of finalization errors,
                //e.g. when the computer is shut down unexpectedly).
                _updatesCount++;
                if (_updatesCount > _updatesCountToWrite)
                {
                    SerializeChanges();
                    _updatesCount = 0;
                }
                Implementation.FileSystemParser.UpdateFolders(_filteredCacheItems, e, _fileSystemFilter.IsCorrect);
            }
        }
 private static string GetChangeItemLine(FileSystemChangeEventArgs item)
 {
     return string.Format(CultureInfo.InvariantCulture, "{1}{0}{2}", Separator, item.OldFullPath ?? string.Empty, item.NewFullPath ?? string.Empty);
 }