internal static bool WatchLocationForRestart(string virtualPath, string filter, bool watchSubdirs)
{
// map the path to the physical one
string physicalPath = HttpRuntime.AppDomainAppPath;
physicalPath = Path.Combine(physicalPath, virtualPath);
bool isDir = Directory.Exists(physicalPath);
bool isFile = isDir ? false : File.Exists(physicalPath);
if (isDir || isFile) {
// create the watcher
FileSystemEventHandler fseh = new FileSystemEventHandler(OnFileChanged);
RenamedEventHandler reh = new RenamedEventHandler(OnFileRenamed);
FileSystemWatcher watcher = CreateWatcher(Path.Combine(physicalPath, filter), fseh, reh);
if (isDir)
watcher.IncludeSubdirectories = watchSubdirs;
lock (watchers_lock) {
watchers.Add(watcher);
}
return true;
} else {
return false;
}
}