private DirectoryMonitor ListenToSubdirectoryChanges(string dirRoot, string dirToListenTo) { string str; DirectoryMonitor monitor; if (StringUtil.StringEndsWith(dirRoot, '\\')) { str = dirRoot + dirToListenTo; } else { str = dirRoot + @"\" + dirToListenTo; } if (this.IsBeneathAppPathInternal(str)) { monitor = this._dirMonAppPathInternal; dirToListenTo = str.Substring(this._appPathInternal.Length + 1); monitor.StartMonitoringFileWithAssert(dirToListenTo, new FileChangeEventHandler(this.OnCriticaldirChange), str); return(monitor); } if (Directory.Exists(str)) { monitor = new DirectoryMonitor(str, true, 0x159); try { monitor.StartMonitoringFileWithAssert(null, new FileChangeEventHandler(this.OnCriticaldirChange), str); return(monitor); } catch { ((IDisposable)monitor).Dispose(); monitor = null; throw; } } monitor = (DirectoryMonitor)this._subDirDirMons[dirRoot]; if (monitor == null) { monitor = new DirectoryMonitor(dirRoot, false, 0x15b); this._subDirDirMons[dirRoot] = monitor; } try { monitor.StartMonitoringFileWithAssert(dirToListenTo, new FileChangeEventHandler(this.OnCriticaldirChange), str); } catch { ((IDisposable)monitor).Dispose(); monitor = null; throw; } return(monitor); }
private DirectoryMonitor ListenToSubdirectoryChanges(string dirRoot, string dirToListenTo) { string str; DirectoryMonitor monitor; if (StringUtil.StringEndsWith(dirRoot, '\\')) { str = dirRoot + dirToListenTo; } else { str = dirRoot + @"\" + dirToListenTo; } if (this.IsBeneathAppPathInternal(str)) { monitor = this._dirMonAppPathInternal; dirToListenTo = str.Substring(this._appPathInternal.Length + 1); monitor.StartMonitoringFileWithAssert(dirToListenTo, new FileChangeEventHandler(this.OnCriticaldirChange), str); return monitor; } if (Directory.Exists(str)) { monitor = new DirectoryMonitor(str, true, 0x159); try { monitor.StartMonitoringFileWithAssert(null, new FileChangeEventHandler(this.OnCriticaldirChange), str); return monitor; } catch { ((IDisposable) monitor).Dispose(); monitor = null; throw; } } monitor = (DirectoryMonitor) this._subDirDirMons[dirRoot]; if (monitor == null) { monitor = new DirectoryMonitor(dirRoot, false, 0x15b); this._subDirDirMons[dirRoot] = monitor; } try { monitor.StartMonitoringFileWithAssert(dirToListenTo, new FileChangeEventHandler(this.OnCriticaldirChange), str); } catch { ((IDisposable) monitor).Dispose(); monitor = null; throw; } return monitor; }
internal DateTime StartMonitoringPath(string alias, FileChangeEventHandler callback, out FileAttributesData fad) { FileMonitor monitor = null; DirectoryMonitor monitor2 = null; string fullPath; string file = null; bool flag = false; fad = null; if (alias == null) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { string.Empty })); } if (this.IsFCNDisabled) { fullPath = GetFullPath(alias); FindFileData data = null; if (FindFileData.FindFile(fullPath, out data) == 0) { fad = data.FileAttributesData; return(data.FileAttributesData.UtcLastWriteTime); } return(DateTime.MinValue); } using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireReaderLock(); try { if (this._disposed) { return(DateTime.MinValue); } monitor = (FileMonitor)this._aliases[alias]; if (monitor != null) { file = monitor.FileNameLong; monitor = monitor.DirectoryMonitor.StartMonitoringFileWithAssert(file, callback, alias); } else { flag = true; if ((alias.Length == 0) || !UrlPath.IsAbsolutePhysicalPath(alias)) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { HttpRuntime.GetSafePath(alias) })); } fullPath = GetFullPath(alias); if (this.IsBeneathAppPathInternal(fullPath)) { monitor2 = this._dirMonAppPathInternal; file = fullPath.Substring(this._appPathInternal.Length + 1); monitor = monitor2.StartMonitoringFileWithAssert(file, callback, alias); } else { monitor2 = this.FindDirectoryMonitor(fullPath, false, false); if (monitor2 != null) { monitor = monitor2.StartMonitoringFileWithAssert(null, callback, alias); } else { string directoryOrRootName = UrlPath.GetDirectoryOrRootName(fullPath); file = Path.GetFileName(fullPath); if (!string.IsNullOrEmpty(file)) { monitor2 = this.FindDirectoryMonitor(directoryOrRootName, false, false); if (monitor2 != null) { try { monitor = monitor2.StartMonitoringFileWithAssert(file, callback, alias); } catch { } if (monitor != null) { goto Label_01C7; } } } monitor2 = this.FindDirectoryMonitor(fullPath, true, false); if (monitor2 != null) { file = null; } else { if (string.IsNullOrEmpty(file)) { throw CreateFileMonitoringException(-2147024809, alias); } monitor2 = this.FindDirectoryMonitor(directoryOrRootName, true, true); } monitor = monitor2.StartMonitoringFileWithAssert(file, callback, alias); } } } Label_01C7: if (!monitor.IsDirectory) { monitor.DirectoryMonitor.GetFileAttributes(file, out fad); } if (flag) { this._aliases[alias] = monitor; } } finally { this._lockDispose.ReleaseReaderLock(); } if (fad != null) { return(fad.UtcLastWriteTime); } return(DateTime.MinValue); } }