private void CreateFileWatcher()

in src/WebJobs.Extensions/Extensions/Files/Listener/FileListener.cs [158:197]


        private void CreateFileWatcher()
        {
            if ((_attribute.ChangeTypes & WatcherChangeTypes.Changed) != 0 && _attribute.AutoDelete)
            {
                throw new NotSupportedException("Use of AutoDelete is not supported when using change type 'Changed'.");
            }

            if (!Directory.Exists(_watchPath))
            {
                throw new InvalidOperationException(string.Format("Path '{0}' does not exist.", _watchPath));
            }

            _watcher = new FileSystemWatcher
            {
                Path = _watchPath,
                NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName,
                Filter = _attribute.Filter
            };

            if ((_attribute.ChangeTypes & WatcherChangeTypes.Created) != 0)
            {
                _watcher.Created += new FileSystemEventHandler(FileChangeHandler);
            }

            if ((_attribute.ChangeTypes & WatcherChangeTypes.Changed) != 0)
            {
                _watcher.Changed += new FileSystemEventHandler(FileChangeHandler);
            }

            if ((_attribute.ChangeTypes & WatcherChangeTypes.Renamed) != 0)
            {
                _watcher.Renamed += new RenamedEventHandler(FileRenameHandler);
            }

            if ((_attribute.ChangeTypes & WatcherChangeTypes.Deleted) != 0)
            {
                _watcher.Deleted += new FileSystemEventHandler(FileChangeHandler);
            }
            _watcher.EnableRaisingEvents = true;
        }