internal void DoRuntimeValidation() { string directoryName = this.DirectoryName; if (!BuildManager.IsPrecompiledApp) { FindFileData data; if (!Util.IsValidFileName(directoryName)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_CodeSubDirectory", new object[] { directoryName }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber); } VirtualPath virtualDir = HttpRuntime.CodeDirectoryVirtualPath.SimpleCombineWithDir(directoryName); if (!VirtualPathProvider.DirectoryExistsNoThrow(virtualDir)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_CodeSubDirectory_Not_Exist", new object[] { virtualDir }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber); } FindFileData.FindFile(virtualDir.MapPathInternal(), out data); if (!System.Web.Util.StringUtil.EqualsIgnoreCase(directoryName, data.FileNameLong)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_CodeSubDirectory", new object[] { directoryName }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber); } if (BuildManager.IsReservedAssemblyName(directoryName)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Reserved_AssemblyName", new object[] { directoryName }), base.ElementInformation.Properties["directoryName"].Source, base.ElementInformation.Properties["directoryName"].LineNumber); } } }
private void EnsureFileInfoObtained() { if (this._physicalPath == null) { this._physicalPath = HostingEnvironment.MapPathInternal(base.VirtualPath); FindFileData.FindFile(this._physicalPath, out this._ffd); } }
private void EnsureFileInfoObtained() { // Get the physical path and FindFileData on demand if (_physicalPath == null) { Debug.Assert(_ffd == null); _physicalPath = HostingEnvironment.MapPathInternal(VirtualPath); FindFileData.FindFile(_physicalPath, out _ffd); } }
// Validate the element for runtime use internal void DoRuntimeValidation() { string directoryName = DirectoryName; // If the app is precompiled, don't attempt further validation, sine the directory // will not actually exist (VSWhidbey 394333) if (BuildManager.IsPrecompiledApp) { return; } // Make sure it's just a valid simple directory name if (!Util.IsValidFileName(directoryName)) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_CodeSubDirectory, directoryName), ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber); } VirtualPath codeVirtualSubDir = HttpRuntime.CodeDirectoryVirtualPath.SimpleCombineWithDir(directoryName); // Make sure the specified directory exists if (!VirtualPathProvider.DirectoryExistsNoThrow(codeVirtualSubDir)) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_CodeSubDirectory_Not_Exist, codeVirtualSubDir), ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber); } // Look at the actual physical dir to get its name canonicalized (VSWhidbey 288568) string physicalDir = codeVirtualSubDir.MapPathInternal(); FindFileData ffd; FindFileData.FindFile(physicalDir, out ffd); // If the name was not canonical, reject it if (!StringUtil.EqualsIgnoreCase(directoryName, ffd.FileNameLong)) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_CodeSubDirectory, directoryName), ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber); } if (BuildManager.IsReservedAssemblyName(directoryName)) { throw new ConfigurationErrorsException( SR.GetString(SR.Reserved_AssemblyName, directoryName), ElementInformation.Properties[dirNameAttribName].Source, ElementInformation.Properties[dirNameAttribName].LineNumber); } }
private FileMonitor AddFileMonitor(string file) { FileMonitor monitor; FindFileData data = null; int num; if (string.IsNullOrEmpty(file)) { monitor = new FileMonitor(this, null, null, true, null, null); this._anyFileMon = monitor; return(monitor); } string fullPath = Path.Combine(this.Directory, file); if (this._isDirMonAppPathInternal) { num = FindFileData.FindFile(fullPath, this.Directory, out data); } else { num = FindFileData.FindFile(fullPath, out data); } if (num == 0) { if (!this._isDirMonAppPathInternal && ((data.FileAttributesData.FileAttributes & FileAttributes.Directory) != 0)) { throw FileChangesMonitor.CreateFileMonitoringException(-2147024809, fullPath); } byte[] dacl = FileSecurity.GetDacl(fullPath); monitor = new FileMonitor(this, data.FileNameLong, data.FileNameShort, true, data.FileAttributesData, dacl); this._fileMons.Add(data.FileNameLong, monitor); this.UpdateFileNameShort(monitor, null, data.FileNameShort); return(monitor); } if ((num != -2147024893) && (num != -2147024894)) { throw FileChangesMonitor.CreateFileMonitoringException(num, fullPath); } if (file.IndexOf('~') != -1) { throw FileChangesMonitor.CreateFileMonitoringException(-2147024809, fullPath); } monitor = new FileMonitor(this, file, null, false, null, null); this._fileMons.Add(file, monitor); 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); } }
internal DateTime StartMonitoringFile(string alias, FileChangeEventHandler callback) { string fullPath; bool flag = false; if (alias == null) { throw CreateFileMonitoringException(-2147024809, alias); } if (this.IsFCNDisabled) { fullPath = GetFullPath(alias); FindFileData data = null; if (FindFileData.FindFile(fullPath, out data) == 0) { return(data.FileAttributesData.UtcLastWriteTime); } return(DateTime.MinValue); } using (new ApplicationImpersonationContext()) { FileMonitor monitor; string fileNameLong; FileAttributesData data2; this._lockDispose.AcquireReaderLock(); try { DirectoryMonitor directoryMonitor; if (this._disposed) { return(DateTime.MinValue); } monitor = (FileMonitor)this._aliases[alias]; if (monitor != null) { directoryMonitor = monitor.DirectoryMonitor; fileNameLong = monitor.FileNameLong; } else { flag = true; if ((alias.Length == 0) || !UrlPath.IsAbsolutePhysicalPath(alias)) { throw CreateFileMonitoringException(-2147024809, alias); } fullPath = GetFullPath(alias); if (this.IsBeneathAppPathInternal(fullPath)) { directoryMonitor = this._dirMonAppPathInternal; fileNameLong = fullPath.Substring(this._appPathInternal.Length + 1); } else { string directoryOrRootName = UrlPath.GetDirectoryOrRootName(fullPath); fileNameLong = Path.GetFileName(fullPath); if (string.IsNullOrEmpty(fileNameLong)) { throw CreateFileMonitoringException(-2147024809, alias); } directoryMonitor = this.FindDirectoryMonitor(directoryOrRootName, true, true); } } monitor = directoryMonitor.StartMonitoringFileWithAssert(fileNameLong, callback, alias); if (flag) { this._aliases[alias] = monitor; } } finally { this._lockDispose.ReleaseReaderLock(); } monitor.DirectoryMonitor.GetFileAttributes(fileNameLong, out data2); if (data2 != null) { return(data2.UtcLastWriteTime); } return(DateTime.MinValue); } }
internal FileAttributesData GetFileAttributes(string alias) { DirectoryMonitor directoryMonitor = null; string fullPath; string file = null; FileAttributesData fad = null; if (alias == null) { throw CreateFileMonitoringException(-2147024809, alias); } if (this.IsFCNDisabled) { if ((alias.Length == 0) || !UrlPath.IsAbsolutePhysicalPath(alias)) { throw CreateFileMonitoringException(-2147024809, alias); } fullPath = GetFullPath(alias); FindFileData data = null; if (FindFileData.FindFile(fullPath, out data) == 0) { return(data.FileAttributesData); } return(null); } using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireReaderLock(); try { if (!this._disposed) { FileMonitor monitor = (FileMonitor)this._aliases[alias]; if ((monitor != null) && !monitor.IsDirectory) { directoryMonitor = monitor.DirectoryMonitor; file = monitor.FileNameLong; } else { if ((alias.Length == 0) || !UrlPath.IsAbsolutePhysicalPath(alias)) { throw CreateFileMonitoringException(-2147024809, alias); } fullPath = GetFullPath(alias); string directoryOrRootName = UrlPath.GetDirectoryOrRootName(fullPath); file = Path.GetFileName(fullPath); if ((file != null) || (file.Length > 0)) { directoryMonitor = this.FindDirectoryMonitor(directoryOrRootName, false, false); } } } } finally { this._lockDispose.ReleaseReaderLock(); } if ((directoryMonitor == null) || !directoryMonitor.GetFileAttributes(file, out fad)) { FileAttributesData.GetFileAttributes(alias, out fad); } return(fad); } }
internal void OnFileChange(FileAction action, string fileName, DateTime utcCompletion) { try { FileMonitor fileMon = null; ArrayList list = null; FileAttributesData attributes = null; FileAttributesData fad = null; byte[] dacl = null; byte[] buffer2 = null; FileAction error = FileAction.Error; DateTime minValue = DateTime.MinValue; bool fileMonitorForSpecialDirectory = false; if (this._dirMonCompletion != null) { lock (this) { ICollection targets; if (this._fileMons.Count > 0) { if ((action == FileAction.Error) || (action == FileAction.Overwhelming)) { if (action == FileAction.Overwhelming) { HttpRuntime.SetShutdownMessage("Overwhelming Change Notification in " + this.Directory); if (Interlocked.Increment(ref s_notificationBufferSizeIncreased) == 1) { System.Web.UnsafeNativeMethods.GrowFileNotificationBuffer(HttpRuntime.AppDomainAppIdInternal, this._watchSubtree); } } else if (action == FileAction.Error) { HttpRuntime.SetShutdownMessage("File Change Notification Error in " + this.Directory); } list = new ArrayList(); foreach (DictionaryEntry entry in this._fileMons) { string key = (string)entry.Key; fileMon = (FileMonitor)entry.Value; if ((fileMon.FileNameLong == key) && fileMon.Exists) { fileMon.ResetCachedAttributes(); fileMon.LastAction = action; fileMon.UtcLastCompletion = utcCompletion; targets = fileMon.Targets; list.AddRange(targets); } } fileMon = null; } else { fileMon = (FileMonitor)this._fileMons[fileName]; if (this._isDirMonAppPathInternal && (fileMon == null)) { fileMonitorForSpecialDirectory = this.GetFileMonitorForSpecialDirectory(fileName, ref fileMon); } if (fileMon != null) { list = new ArrayList(fileMon.Targets); attributes = fileMon.Attributes; dacl = fileMon.Dacl; error = fileMon.LastAction; minValue = fileMon.UtcLastCompletion; fileMon.LastAction = action; fileMon.UtcLastCompletion = utcCompletion; if ((action == FileAction.Removed) || (action == FileAction.RenamedOldName)) { fileMon.MakeExtinct(); } else if (fileMon.Exists) { if (minValue != utcCompletion) { fileMon.UpdateCachedAttributes(); } } else { int num3; FindFileData data = null; string fullPath = Path.Combine(this.Directory, fileMon.FileNameLong); if (this._isDirMonAppPathInternal) { num3 = FindFileData.FindFile(fullPath, this.Directory, out data); } else { num3 = FindFileData.FindFile(fullPath, out data); } if (num3 == 0) { string fileNameShort = fileMon.FileNameShort; byte[] buffer3 = FileSecurity.GetDacl(fullPath); fileMon.MakeExist(data, buffer3); this.UpdateFileNameShort(fileMon, fileNameShort, data.FileNameShort); } } fad = fileMon.Attributes; buffer2 = fileMon.Dacl; } } } if (this._anyFileMon != null) { targets = this._anyFileMon.Targets; if (list != null) { list.AddRange(targets); } else { list = new ArrayList(targets); } } if ((action == FileAction.Error) || (action == FileAction.Overwhelming)) { ((IDisposable)this).Dispose(); } } bool flag2 = false; if ((!fileMonitorForSpecialDirectory && (fileName != null)) && (action == FileAction.Modified)) { FileAttributesData data4 = fad; if (data4 == null) { FileAttributesData.GetFileAttributes(Path.Combine(this.Directory, fileName), out data4); } if ((data4 != null) && ((data4.FileAttributes & FileAttributes.Directory) != 0)) { flag2 = true; } } if ((this._ignoreSubdirChange && ((action == FileAction.Removed) || (action == FileAction.RenamedOldName))) && (fileName != null)) { string str5 = Path.Combine(this.Directory, fileName); if (!HttpRuntime.FileChangesMonitor.IsDirNameMonitored(str5, fileName)) { flag2 = true; } } if ((list != null) && !flag2) { lock (s_notificationQueue.SyncRoot) { int num = 0; int count = list.Count; while (num < count) { bool flag3; FileMonitorTarget target = (FileMonitorTarget)list[num]; if (((action != FileAction.Added) && (action != FileAction.Modified)) || (fad == null)) { flag3 = true; } else if (action == FileAction.Added) { flag3 = this.IsChangeAfterStartMonitoring(fad, target, utcCompletion); } else if (utcCompletion == minValue) { flag3 = error != FileAction.Modified; } else if (attributes == null) { flag3 = true; } else if ((dacl == null) || (dacl != buffer2)) { flag3 = true; } else { flag3 = this.IsChangeAfterStartMonitoring(fad, target, utcCompletion); } if (flag3) { s_notificationQueue.Enqueue(new NotificationQueueItem(target.Callback, action, target.Alias)); } num++; } } if (((s_notificationQueue.Count > 0) && (s_inNotificationThread == 0)) && (Interlocked.Exchange(ref s_inNotificationThread, 1) == 0)) { WorkItem.PostInternal(s_notificationCallback); } } } } catch (Exception) { } }