Ejemplo n.º 1
0
        private FileSystemWatcher MonitorContentFileSystemChanges()
        {
            var fileSystemWatcher = new FileSystemWatcher();

            if (Directory.Exists(_baseLocalPath))
            {
                fileSystemWatcher.Path = _baseLocalPath;
                fileSystemWatcher.IncludeSubdirectories = true;

                FileSystemEventHandler handler = (sender, args) =>
                {
                    _cacheManager.Clear();
                };
                RenamedEventHandler renamedHandler = (sender, args) =>
                {
                    _cacheManager.Clear();
                };
                var throttledHandler = handler.Throttle(TimeSpan.FromSeconds(5));
                // Add event handlers.
                fileSystemWatcher.Changed += throttledHandler;
                fileSystemWatcher.Created += throttledHandler;
                fileSystemWatcher.Deleted += throttledHandler;
                fileSystemWatcher.Renamed += renamedHandler;

                // Begin watching.
                fileSystemWatcher.EnableRaisingEvents = true;
            }
            return(fileSystemWatcher);
        }
Ejemplo n.º 2
0
        private FileSystemWatcher SetFileSystemWatcher(string path)
        {
            var fileSystemWatcher = new FileSystemWatcher();

            fileSystemWatcher.Path = path;
            fileSystemWatcher.IncludeSubdirectories = true;

            FileSystemEventHandler handler = (sender, args) =>
            {
                RaiseChangedEvent(args);
            };
            RenamedEventHandler renamedHandler = (sender, args) =>
            {
                RaiseRenamedEvent(args);
            };
            var throttledHandler = handler.Throttle(TimeSpan.FromSeconds(5));

            // Add event handlers.
            fileSystemWatcher.Changed += throttledHandler;
            fileSystemWatcher.Created += throttledHandler;
            fileSystemWatcher.Deleted += throttledHandler;
            fileSystemWatcher.Renamed += renamedHandler;

            // Begin watching.
            fileSystemWatcher.EnableRaisingEvents = true;

            return(fileSystemWatcher);
        }