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
 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);
 }