Exemplo n.º 1
0
        public void WatchFile(string filePath)
        {
            bool   flag = false;
            string str  = PathHelper.GetDirectory(filePath);

            if (!FileChangeWatcher.DirectoryIsAccessible(str))
            {
                flag = true;
                str  = FileChangeWatcher.GetExistingParentDirectory(str);
            }
            if (string.IsNullOrEmpty(str))
            {
                return;
            }
            FileChangeWatcher.WatchedDirectory watchedDirectory;
            lock (this.syncLock)
            {
                if (!this.pathToWatchedDirectories.TryGetValue(str, out watchedDirectory))
                {
                    watchedDirectory = new FileChangeWatcher.WatchedDirectory(this, str);
                    this.pathToWatchedDirectories.Add(str, watchedDirectory);
                }
            }
            if (flag)
            {
                watchedDirectory.IncludeSubdirectories = flag;
            }
            watchedDirectory.WatchFile(filePath);
        }
Exemplo n.º 2
0
 internal WatchedDirectory(FileChangeWatcher watcher, string directory)
     : base(directory)
 {
     this.watcher = watcher;
     this.IncludeSubdirectories = false;
     this.NotifyFilter          = NotifyFilters.FileName | NotifyFilters.LastWrite;
     this.Changed += new FileSystemEventHandler(this.OnFileChanged);
     this.Deleted += new FileSystemEventHandler(this.OnFileChanged);
     this.Renamed += new RenamedEventHandler(this.OnFileChanged);
 }
Exemplo n.º 3
0
 private static string GetExistingParentDirectory(string directory)
 {
     do
     {
         string parentDirectory = PathHelper.GetParentDirectory(directory);
         if (string.Equals(parentDirectory, directory, StringComparison.OrdinalIgnoreCase))
         {
             return((string)null);
         }
         directory = parentDirectory;
     }while (!FileChangeWatcher.DirectoryIsAccessible(directory));
     return(directory);
 }
Exemplo n.º 4
0
        private void MoveToParentDirectory(FileChangeWatcher.WatchedDirectory watchedDirectory)
        {
            this.pathToWatchedDirectories.Remove(watchedDirectory.Path);
            string existingParentDirectory = FileChangeWatcher.GetExistingParentDirectory(watchedDirectory.Path);

            if (string.IsNullOrEmpty(existingParentDirectory))
            {
                return;
            }
            string[] strArray = Enumerable.ToArray <string>(watchedDirectory.FilePaths);
            if (!this.pathToWatchedDirectories.TryGetValue(existingParentDirectory, out watchedDirectory))
            {
                watchedDirectory = new FileChangeWatcher.WatchedDirectory(this, existingParentDirectory);
                this.pathToWatchedDirectories.Add(existingParentDirectory, watchedDirectory);
            }
            watchedDirectory.IncludeSubdirectories = true;
            foreach (string filePath in strArray)
            {
                watchedDirectory.WatchFile(filePath);
            }
        }