internal FileMonitorTarget(FileChangeEventHandler callback, string alias) { this.Callback = callback; this.Alias = alias; this.UtcStartMonitoring = DateTime.UtcNow; this._refs = 1; }
internal FileMonitorTarget(FileChangeEventHandler callback, string alias) { this.Callback = callback; this.Alias = alias; this.UtcStartMonitoring = DateTime.UtcNow; this._refs = 1; }
internal static void AddFileDependency(string file) { if (!string.IsNullOrEmpty(file) && UseHttpConfigurationSystem) { if (s_fileChangeEventHandler == null) { s_fileChangeEventHandler = new FileChangeEventHandler(s_httpConfigSystem.OnConfigFileChanged); } HttpRuntime.FileChangesMonitor.StartMonitoringFile(file, s_fileChangeEventHandler); } }
internal static void AddFileDependency(string file) { if (!string.IsNullOrEmpty(file) && UseHttpConfigurationSystem) { if (s_fileChangeEventHandler == null) { s_fileChangeEventHandler = new FileChangeEventHandler(s_httpConfigSystem.OnConfigFileChanged); } HttpRuntime.FileChangesMonitor.StartMonitoringFile(file, s_fileChangeEventHandler); } }
internal void Stop() { if (!this.IsFCNDisabled) { using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireWriterLock(); try { this._disposed = true; goto Label_0039; } finally { this._lockDispose.ReleaseWriterLock(); } Label_002F: Thread.Sleep(250); Label_0039: if (this._activeCallbackCount != 0) { goto Label_002F; } if (this._dirMonSubdirs != null) { this._dirMonSubdirs.StopMonitoring(); this._dirMonSubdirs = null; } if (this._dirMonSpecialDirs != null) { foreach (DirectoryMonitor monitor in this._dirMonSpecialDirs) { if (monitor != null) { monitor.StopMonitoring(); } } this._dirMonSpecialDirs = null; } this._callbackRenameOrCriticaldirChange = null; if (this._dirs != null) { IDictionaryEnumerator enumerator = this._dirs.GetEnumerator(); while (enumerator.MoveNext()) { ((DirectoryMonitor)enumerator.Value).StopMonitoring(); } } this._dirs.Clear(); this._aliases.Clear(); } } }
private void SetupChangesMonitor() { FileChangeEventHandler callback = new FileChangeEventHandler(this.OnAppFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(this._appFilename, callback); if (this._fileDependencies != null) { foreach (string str in this._fileDependencies) { HttpRuntime.FileChangesMonitor.StartMonitoringFile(HostingEnvironment.MapPathInternal(str), callback); } } }
private void SetupChangesMonitor() { FileChangeEventHandler handler = new FileChangeEventHandler(this.OnAppFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(_appFilename, handler); if (_fileDependencies != null) { foreach (string fileName in _fileDependencies) { HttpRuntime.FileChangesMonitor.StartMonitoringFile( HostingEnvironment.MapPathInternal(fileName), handler); } } }
private void SetupChangesMonitor() { FileChangeEventHandler handler = new FileChangeEventHandler(this.OnAppFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(_appFilename, handler); if (_fileDependencies != null) { IDictionaryEnumerator en = _fileDependencies.GetEnumerator(); for (; en.MoveNext();) { string fileName = (string)en.Value; HttpRuntime.FileChangesMonitor.StartMonitoringFile(fileName, handler); } } }
internal void AddTarget(FileChangeEventHandler callback, string alias, bool newAlias) { FileMonitorTarget target = (FileMonitorTarget) this._targets[callback.Target]; if (target != null) { target.AddRef(); } else { this._targets.Add(callback.Target, new FileMonitorTarget(callback, alias)); } if (newAlias) { this.Aliases[alias] = alias; } }
internal static void AddFileDependency(String file) { if (file == null || file.Length == 0) { return; } // doesn't need to be threadsafe, this will always happen on first request init if (s_fileChangeEventHandler == null) { s_fileChangeEventHandler = new FileChangeEventHandler(_system.OnConfigChange); } HttpRuntime.FileChangesMonitor.StartMonitoringFile( file, s_fileChangeEventHandler); }
internal void AddTarget(FileChangeEventHandler callback, string alias, bool newAlias) { FileMonitorTarget target = (FileMonitorTarget)this._targets[callback.Target]; if (target != null) { target.AddRef(); } else { this._targets.Add(callback.Target, new FileMonitorTarget(callback, alias)); } if (newAlias) { this.Aliases[alias] = alias; } }
static internal void AddFileDependency(String file) { if (String.IsNullOrEmpty(file)) { return; } #if !FEATURE_PAL // No file change notification in Coriolis if (UseHttpConfigurationSystem) { if (s_fileChangeEventHandler == null) { s_fileChangeEventHandler = new FileChangeEventHandler(s_httpConfigSystem.OnConfigFileChanged); } HttpRuntime.FileChangesMonitor.StartMonitoringFile(file, s_fileChangeEventHandler); } #endif // !FEATURE_PAL }
private XmlDocument GetConfigDocument() { if (this._document == null) { if (!this._initialized) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_Not_Initialized")); } if (this._virtualPath == null) { throw new ArgumentException(System.Web.SR.GetString("XmlSiteMapProvider_missing_siteMapFile", new object[] { "siteMapFile" })); } if (!this._virtualPath.Extension.Equals(".sitemap", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_Invalid_Extension", new object[] { this._virtualPath })); } this._normalizedVirtualPath = this._virtualPath.CombineWithAppRoot(); this._normalizedVirtualPath.FailIfNotWithinAppRoot(); this.CheckSiteMapFileExists(); this._parentSiteMapFileCollection = new StringCollection(); XmlSiteMapProvider parentProvider = this.ParentProvider as XmlSiteMapProvider; if ((parentProvider != null) && (parentProvider._parentSiteMapFileCollection != null)) { if (parentProvider._parentSiteMapFileCollection.Contains(this._normalizedVirtualPath.VirtualPathString)) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_FileName_already_in_use", new object[] { this._virtualPath })); } foreach (string str in parentProvider._parentSiteMapFileCollection) { this._parentSiteMapFileCollection.Add(str); } } this._parentSiteMapFileCollection.Add(this._normalizedVirtualPath.VirtualPathString); this._filename = HostingEnvironment.MapPathInternal(this._normalizedVirtualPath); if (!string.IsNullOrEmpty(this._filename)) { this._handler = new FileChangeEventHandler(this.OnConfigFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(this._filename, this._handler); base.ResourceKey = new FileInfo(this._filename).Name; } this._document = new ConfigXmlDocument(); } return(this._document); }
internal void StartMonitoringDirectoryRenamesAndBinDirectory(string dir, FileChangeEventHandler callback) { if (string.IsNullOrEmpty(dir)) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { string.Empty })); } if (!this.IsFCNDisabled) { using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireReaderLock(); try { if (!this._disposed) { this._callbackRenameOrCriticaldirChange = callback; string fullPath = GetFullPath(dir); this._dirMonSubdirs = new DirectoryMonitor(fullPath, true, 2, true); try { this._dirMonSubdirs.StartMonitoringFileWithAssert(null, new FileChangeEventHandler(this.OnSubdirChange), fullPath); } catch { ((IDisposable)this._dirMonSubdirs).Dispose(); this._dirMonSubdirs = null; throw; } this._dirMonSpecialDirs = new ArrayList(); for (int i = 0; i < s_dirsToMonitor.Length; i++) { this._dirMonSpecialDirs.Add(this.ListenToSubdirectoryChanges(fullPath, s_dirsToMonitor[i])); } } } finally { this._lockDispose.ReleaseReaderLock(); } } } }
private void OnCriticaldirChange(object sender, FileChangeEvent e) { try { Interlocked.Increment(ref this._activeCallbackCount); if (!this._disposed) { HttpRuntime.SetShutdownMessage(System.Web.SR.GetString("Change_notification_critical_dir")); FileChangeEventHandler handler = this._callbackRenameOrCriticaldirChange; if (handler != null) { handler(this, e); } } } finally { Interlocked.Decrement(ref this._activeCallbackCount); } }
private void OnSubdirChange(object sender, FileChangeEvent e) { try { Interlocked.Increment(ref this._activeCallbackCount); if (!this._disposed) { FileChangeEventHandler handler = this._callbackRenameOrCriticaldirChange; if ((handler != null) && (((e.Action == FileAction.Error) || (e.Action == FileAction.Overwhelming)) || ((e.Action == FileAction.RenamedOldName) || (e.Action == FileAction.Removed)))) { HttpRuntime.SetShutdownMessage(System.Web.SR.GetString("Directory_rename_notification", new object[] { e.FileName })); handler(this, e); } } } finally { Interlocked.Decrement(ref this._activeCallbackCount); } }
internal FileMonitor StartMonitoringFileWithAssert(string file, FileChangeEventHandler callback, string alias) { FileMonitor monitor = null; bool flag = false; lock (this) { monitor = this.FindFileMonitor(file); if (monitor == null) { monitor = this.AddFileMonitor(file); if (this.GetFileMonitorsCount() == 1) { flag = true; } } monitor.AddTarget(callback, alias, true); if (flag) { this.StartMonitoring(); } } return(monitor); }
private XmlDocument GetConfigDocument() { if (this._document == null) { if (!this._initialized) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_Not_Initialized")); } if (this._virtualPath == null) { throw new ArgumentException(System.Web.SR.GetString("XmlSiteMapProvider_missing_siteMapFile", new object[] { "siteMapFile" })); } if (!this._virtualPath.Extension.Equals(".sitemap", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_Invalid_Extension", new object[] { this._virtualPath })); } this._normalizedVirtualPath = this._virtualPath.CombineWithAppRoot(); this._normalizedVirtualPath.FailIfNotWithinAppRoot(); this.CheckSiteMapFileExists(); this._parentSiteMapFileCollection = new StringCollection(); XmlSiteMapProvider parentProvider = this.ParentProvider as XmlSiteMapProvider; if ((parentProvider != null) && (parentProvider._parentSiteMapFileCollection != null)) { if (parentProvider._parentSiteMapFileCollection.Contains(this._normalizedVirtualPath.VirtualPathString)) { throw new InvalidOperationException(System.Web.SR.GetString("XmlSiteMapProvider_FileName_already_in_use", new object[] { this._virtualPath })); } foreach (string str in parentProvider._parentSiteMapFileCollection) { this._parentSiteMapFileCollection.Add(str); } } this._parentSiteMapFileCollection.Add(this._normalizedVirtualPath.VirtualPathString); this._filename = HostingEnvironment.MapPathInternal(this._normalizedVirtualPath); if (!string.IsNullOrEmpty(this._filename)) { this._handler = new FileChangeEventHandler(this.OnConfigFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(this._filename, this._handler); base.ResourceKey = new FileInfo(this._filename).Name; } this._document = new ConfigXmlDocument(); } return this._document; }
internal FileMonitor StartMonitoringFileWithAssert(string file, FileChangeEventHandler callback, string alias) { FileMonitor monitor = null; bool flag = false; lock (this) { monitor = this.FindFileMonitor(file); if (monitor == null) { monitor = this.AddFileMonitor(file); if (this.GetFileMonitorsCount() == 1) { flag = true; } } monitor.AddTarget(callback, alias, true); if (flag) { this.StartMonitoring(); } } return monitor; }
private XmlDocument GetConfigDocument() { if (_document != null) return _document; if (!_initialized) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Not_Initialized)); } // Do the error checking here if (_virtualPath == null) { throw new ArgumentException( SR.GetString(SR.XmlSiteMapProvider_missing_siteMapFile, _siteMapFileAttribute)); } if (!_virtualPath.Extension.Equals(_xmlSiteMapFileExtension, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Invalid_Extension, _virtualPath)); } _normalizedVirtualPath = _virtualPath.CombineWithAppRoot(); _normalizedVirtualPath.FailIfNotWithinAppRoot(); // Make sure the file exists CheckSiteMapFileExists(); _parentSiteMapFileCollection = new StringCollection(); XmlSiteMapProvider xmlParentProvider = ParentProvider as XmlSiteMapProvider; if (xmlParentProvider != null && xmlParentProvider._parentSiteMapFileCollection != null) { if (xmlParentProvider._parentSiteMapFileCollection.Contains(_normalizedVirtualPath.VirtualPathString)) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_FileName_already_in_use, _virtualPath)); } // Copy the sitemapfiles in used from parent provider to current provider. foreach (string filename in xmlParentProvider._parentSiteMapFileCollection) { _parentSiteMapFileCollection.Add(filename); } } // Add current sitemap file to the collection _parentSiteMapFileCollection.Add(_normalizedVirtualPath.VirtualPathString); _filename = HostingEnvironment.MapPathInternal(_normalizedVirtualPath); if (!String.IsNullOrEmpty(_filename)) { _handler = new FileChangeEventHandler(this.OnConfigFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(_filename, _handler); ResourceKey = (new FileInfo(_filename)).Name; } _document = new ConfigXmlDocument(); return _document; }
void Init(bool isPublic, bool isSensitive, string[] filenamesArg, string[] cachekeysArg, CacheDependency dependency, DateTime utcStart) { string[] depFilenames = s_stringsEmpty; CacheEntry[] depEntries = s_entriesEmpty; string [] filenames, cachekeys; CacheInternal cacheInternal; Debug.Assert(_bits == 0, "_bits == 0"); if (isSensitive) { _bits = SENSITIVE; } if (filenamesArg != null) { filenames = (string [])filenamesArg.Clone(); } else { filenames = null; } if (cachekeysArg != null) { cachekeys = (string [])cachekeysArg.Clone(); } else { cachekeys = null; } _utcInitTime = DateTime.UtcNow; try { if (filenames != null) { foreach (string f in filenames) { if (f == null) { throw new ArgumentNullException("filenames"); } if (isPublic) { InternalSecurityPermissions.PathDiscovery(f).Demand(); } } } else { filenames = s_stringsEmpty; } if (cachekeys != null) { foreach (string k in cachekeys) { if (k == null) { throw new ArgumentNullException("cachekeys"); } } } else { cachekeys = s_stringsEmpty; } if (dependency != null) { if ((dependency._bits & CHANGED) != 0) { SetBit(CHANGED); return; } if (dependency._filenames != null) { if (dependency._filenames is string) { depFilenames = new string[1] { (string)dependency._filenames }; } else { depFilenames = (string[])(dependency._filenames); } } if (dependency._entries != null) { if (dependency._entries is CacheEntry) { depEntries = new CacheEntry[1] { (CacheEntry)(dependency._entries) }; } else { depEntries = (CacheEntry[])(dependency._entries); } } } else { dependency = s_dependencyEmpty; } int lenMyFilenames = depFilenames.Length + filenames.Length; if (lenMyFilenames > 0) { string[] myFilenames = new string[lenMyFilenames]; FileChangeEventHandler handler = new FileChangeEventHandler(this.FileChange); FileChangesMonitor fmon = HttpRuntime.FileChangesMonitor; int i = 0; foreach (string f in depFilenames) { fmon.StartMonitoringPath(f, handler); myFilenames[i++] = f; } foreach (string f in filenames) { DateTime utcLastWrite = fmon.StartMonitoringPath(f, handler); myFilenames[i++] = f; if (utcStart < DateTime.MaxValue) { Debug.Trace("CacheDependencyInit", "file=" + f + "; utcStart=" + utcStart + "; utcLastWrite=" + utcLastWrite); if (utcLastWrite >= utcStart) { Debug.Trace("CacheDependencyInit", "changes occurred since start time for file " + f); SetBit(CHANGED); break; } } } if (myFilenames.Length == 1) { _filenames = myFilenames[0]; } else { _filenames = myFilenames; } } int lenMyEntries = depEntries.Length + cachekeys.Length; if (lenMyEntries > 0 && (_bits & CHANGED) == 0) { CacheEntry[] myEntries = new CacheEntry[lenMyEntries]; int i = 0; foreach (CacheEntry entry in depEntries) { entry.AddCacheDependencyNotify(this); myEntries[i++] = entry; } cacheInternal = HttpRuntime.CacheInternal; foreach (string k in cachekeys) { CacheEntry entry = (CacheEntry)cacheInternal.DoGet(isPublic, k, CacheGetOptions.ReturnCacheEntry); if (entry != null) { entry.AddCacheDependencyNotify(this); myEntries[i++] = entry; if (entry.State != CacheEntry.EntryState.AddedToCache || entry.UtcCreated > utcStart) { #if DBG if (entry.State != CacheEntry.EntryState.AddedToCache) { Debug.Trace("CacheDependencyInit", "Entry is not in cache, considered changed:" + k); } else { Debug.Trace("CacheDependencyInit", "Changes occurred to entry since start time:" + k); } #endif SetBit(CHANGED); break; } } else { Debug.Trace("CacheDependencyInit", "Cache item not found to create dependency on:" + k); SetBit(CHANGED); break; } } if (myEntries.Length == 1) { _entries = myEntries[0]; } else { _entries = myEntries; } } SetBit(READY); if ((_bits & CHANGED) != 0 || (dependency._bits & CHANGED) != 0) { SetBit(CHANGED); DisposeInternal(); } } catch { DisposeInternal(); throw; } }
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); } }
static internal void AddFileDependency(String file) { if (String.IsNullOrEmpty(file)) return; #if !FEATURE_PAL // No file change notification in Coriolis if (UseHttpConfigurationSystem) { if (s_fileChangeEventHandler == null) { s_fileChangeEventHandler = new FileChangeEventHandler(s_httpConfigSystem.OnConfigFileChanged); } HttpRuntime.FileChangesMonitor.StartMonitoringFile(file, s_fileChangeEventHandler); } #endif // !FEATURE_PAL }
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); } }
void Init(bool isPublic, string[] filenamesArg, string[] cachekeysArg, CacheDependency dependency, DateTime utcStart) { #if USE_MEMORY_CACHE if (CacheInternal.UseMemoryCache) { InitForMemoryCache(isPublic, filenamesArg, cachekeysArg, dependency, utcStart); return; } #endif DepFileInfo[] depFileInfos = s_depFileInfosEmpty; DepCacheInfo[] depEntries = s_entriesEmpty; string [] filenames, cachekeys; CacheStoreProvider cache; _bits = new SafeBitVector32(0); // copy array argument contents so they can't be changed beneath us if (filenamesArg != null) { filenames = (string [])filenamesArg.Clone(); } else { filenames = null; } if (cachekeysArg != null) { cachekeys = (string [])cachekeysArg.Clone(); } else { cachekeys = null; } _utcLastModified = DateTime.MinValue; try { // validate filenames array if (filenames == null) { filenames = s_stringsEmpty; } else { foreach (string f in filenames) { if (f == null) { throw new ArgumentNullException("filenamesArg"); } // demand PathDiscovery if public if (isPublic) { InternalSecurityPermissions.PathDiscovery(f).Demand(); } } } if (cachekeys == null) { cachekeys = s_stringsEmpty; } else { // validate cachekeys array foreach (string k in cachekeys) { if (k == null) { throw new ArgumentNullException("cachekeysArg"); } } } // copy all parts of another dependency if provided if (dependency == null) { dependency = s_dependencyEmpty; } else { if (dependency.GetType() != s_dependencyEmpty.GetType()) { throw new ArgumentException(SR.GetString(SR.Invalid_Dependency_Type)); } // Copy the parts of the dependency we need before // we reference them, as the dependency can change // underneath us. object d_depFileInfos = dependency._depFileInfos; object d_entries = dependency._entries; DateTime d_lastModified = dependency._utcLastModified; // if the dependency we're copying has changed, we're done if (dependency._bits[CHANGED]) { _bits[CHANGED] = true; // There is nothing to dispose because we haven't started // monitoring anything yet. But we call DisposeInternal in // order to set the WANTS_DISPOSE bit. DisposeInternal(); return; } // copy depFileInfos if (d_depFileInfos != null) { if (d_depFileInfos is DepFileInfo) { depFileInfos = new DepFileInfo[1] { (DepFileInfo)d_depFileInfos }; } else { depFileInfos = (DepFileInfo[])(d_depFileInfos); } // verify that the object was fully constructed // and that we have permission to discover the file foreach (DepFileInfo depFileInfo in depFileInfos) { string f = depFileInfo._filename; if (f == null) { _bits[CHANGED] = true; // There is nothing to dispose because we haven't started // monitoring anything yet. But we call DisposeInternal in // order to set the WANTS_DISPOSE bit. DisposeInternal(); return; } // demand PathDiscovery if public if (isPublic) { InternalSecurityPermissions.PathDiscovery(f).Demand(); } } } // copy cache entries if (d_entries != null) { if (d_entries is DepCacheInfo) { depEntries = new DepCacheInfo[1] { (DepCacheInfo)(d_entries) }; } else { depEntries = (DepCacheInfo[])(d_entries); // verify that the object was fully constructed foreach (DepCacheInfo entry in depEntries) { if (entry == null) { _bits[CHANGED] = true; // There is nothing to dispose because we haven't started // monitoring anything yet. But we call DisposeInternal in // order to set the WANTS_DISPOSE bit. DisposeInternal(); return; } } } } _utcLastModified = d_lastModified; } // Monitor files for changes int lenMyDepFileInfos = depFileInfos.Length + filenames.Length; if (lenMyDepFileInfos > 0) { DepFileInfo[] myDepFileInfos = new DepFileInfo[lenMyDepFileInfos]; FileChangeEventHandler handler = new FileChangeEventHandler(this.FileChange); FileChangesMonitor fmon = HttpRuntime.FileChangesMonitor; int i; for (i = 0; i < lenMyDepFileInfos; i++) { myDepFileInfos[i] = new DepFileInfo(); } // monitor files from the existing dependency // note that we don't check for start times in the existing dependency i = 0; foreach (DepFileInfo depFileInfo in depFileInfos) { string f = depFileInfo._filename; fmon.StartMonitoringPath(f, handler, out myDepFileInfos[i]._fad); myDepFileInfos[i]._filename = f; i++; } // monitor new files DateTime utcNow = DateTime.MinValue; foreach (string f in filenames) { DateTime utcLastWrite = fmon.StartMonitoringPath(f, handler, out myDepFileInfos[i]._fad); myDepFileInfos[i]._filename = f; i++; if (utcLastWrite > _utcLastModified) { _utcLastModified = utcLastWrite; } // check if file has changed since the start time if (utcStart < DateTime.MaxValue) { if (utcNow == DateTime.MinValue) { utcNow = DateTime.UtcNow; } Debug.Trace("CacheDependencyInit", "file=" + f + "; utcStart=" + utcStart + "; utcLastWrite=" + utcLastWrite); if (utcLastWrite >= utcStart && !(utcLastWrite - utcNow > FUTURE_FILETIME_BUFFER)) // See VSWhidbey 400917 { Debug.Trace("CacheDependencyInit", "changes occurred since start time for file " + f); _bits[CHANGED] = true; break; } } } if (myDepFileInfos.Length == 1) { _depFileInfos = myDepFileInfos[0]; } else { _depFileInfos = myDepFileInfos; } } // Monitor other cache entries for changes int lenMyEntries = depEntries.Length + cachekeys.Length; DateTime lastUpdated; if (lenMyEntries > 0 && !_bits[CHANGED]) { DepCacheInfo[] myEntries = new DepCacheInfo[lenMyEntries]; // Monitor entries from the existing cache dependency int i = 0; foreach (DepCacheInfo entry in depEntries) { entry._cacheStore.AddDependent(entry._key, this, out lastUpdated); myEntries[i++] = entry; } // Monitor new entries specified for this depenedency // Entries must be added to cache, and created before the startTime cache = isPublic ? HttpRuntime.Cache.ObjectCache : HttpRuntime.Cache.InternalCache; foreach (string k in cachekeys) { if (cache.AddDependent(k, this, out lastUpdated)) { myEntries[i++] = new DepCacheInfo() { _cacheStore = cache, _key = k }; if (lastUpdated > _utcLastModified) { _utcLastModified = lastUpdated; } if (lastUpdated > utcStart) // Cache item has been updated since start, consider changed { #if DBG Debug.Trace("CacheDependencyInit", "Changes occurred to entry since start time:" + k); #endif _bits[CHANGED] = true; break; } } else { Debug.Trace("CacheDependencyInit", "Cache item not found to create dependency on:" + k); _bits[CHANGED] = true; break; } } if (myEntries.Length == 1) { _entries = myEntries[0]; } else { _entries = myEntries; } } _bits[BASE_INIT] = true; if (dependency._bits[CHANGED]) { _bits[CHANGED] = true; } if (_bits[WANTS_DISPOSE] || _bits[CHANGED]) { DisposeInternal(); } Debug.Assert(_objNotify == null, "_objNotify == null"); } catch { // derived constructor will not execute due to the throw, // so we just force a dispose on ourselves _bits[BASE_INIT] = true; DisposeInternal(); throw; } finally { InitUniqueID(); } }
private void SetupChangesMonitor() { FileChangeEventHandler handler = new FileChangeEventHandler(this.OnAppFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(_appFilename, handler); if (_fileDependencies != null) { foreach (string fileName in _fileDependencies) { HttpRuntime.FileChangesMonitor.StartMonitoringFile( HostingEnvironment.MapPathInternal(fileName), handler); } } }
internal NotificationQueueItem(FileChangeEventHandler callback, FileAction action, string filename) { this.Callback = callback; this.Action = action; this.Filename = filename; }
private void SetupChangesMonitor() { FileChangeEventHandler callback = new FileChangeEventHandler(this.OnAppFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(this._appFilename, callback); if (this._fileDependencies != null) { foreach (string str in this._fileDependencies) { HttpRuntime.FileChangesMonitor.StartMonitoringFile(HostingEnvironment.MapPathInternal(str), callback); } } }
internal FileChangeEventTarget(OnChangedCallback onChangedCallback) { _onChangedCallback = onChangedCallback; _handler = new FileChangeEventHandler(this.OnChanged); }
private void Init(bool isPublic, string[] filenamesArg, string[] cachekeysArg, CacheDependency dependency, DateTime utcStart) { string[] strArray; string[] strArray2; DepFileInfo[] infoArray = s_depFileInfosEmpty; CacheEntry[] entryArray = s_entriesEmpty; this._bits = new SafeBitVector32(0); if (filenamesArg != null) { strArray = (string[])filenamesArg.Clone(); } else { strArray = null; } if (cachekeysArg != null) { strArray2 = (string[])cachekeysArg.Clone(); } else { strArray2 = null; } this._utcLastModified = DateTime.MinValue; try { if (strArray == null) { strArray = s_stringsEmpty; } else { foreach (string str in strArray) { if (str == null) { throw new ArgumentNullException("filenamesArg"); } if (isPublic) { InternalSecurityPermissions.PathDiscovery(str).Demand(); } } } if (strArray2 == null) { strArray2 = s_stringsEmpty; } else { string[] strArray4 = strArray2; for (int i = 0; i < strArray4.Length; i++) { if (strArray4[i] == null) { throw new ArgumentNullException("cachekeysArg"); } } } if (dependency == null) { dependency = s_dependencyEmpty; } else { if (dependency.GetType() != s_dependencyEmpty.GetType()) { throw new ArgumentException(System.Web.SR.GetString("Invalid_Dependency_Type")); } object obj2 = dependency._depFileInfos; object obj3 = dependency._entries; DateTime time = dependency._utcLastModified; if (dependency._bits[4]) { this._bits[4] = true; this.DisposeInternal(); return; } if (obj2 != null) { if (obj2 is DepFileInfo) { infoArray = new DepFileInfo[] { (DepFileInfo)obj2 }; } else { infoArray = (DepFileInfo[])obj2; } foreach (DepFileInfo info in infoArray) { string path = info._filename; if (path == null) { this._bits[4] = true; this.DisposeInternal(); return; } if (isPublic) { InternalSecurityPermissions.PathDiscovery(path).Demand(); } } } if (obj3 != null) { if (obj3 is CacheEntry) { entryArray = new CacheEntry[] { (CacheEntry)obj3 }; } else { entryArray = (CacheEntry[])obj3; CacheEntry[] entryArray4 = entryArray; for (int j = 0; j < entryArray4.Length; j++) { if (entryArray4[j] == null) { this._bits[4] = true; this.DisposeInternal(); return; } } } } this._utcLastModified = time; } int num = infoArray.Length + strArray.Length; if (num > 0) { int num2; DepFileInfo[] infoArray2 = new DepFileInfo[num]; FileChangeEventHandler callback = new FileChangeEventHandler(this.FileChange); FileChangesMonitor fileChangesMonitor = HttpRuntime.FileChangesMonitor; for (num2 = 0; num2 < num; num2++) { infoArray2[num2] = new DepFileInfo(); } num2 = 0; foreach (DepFileInfo info2 in infoArray) { string alias = info2._filename; fileChangesMonitor.StartMonitoringPath(alias, callback, out infoArray2[num2]._fad); infoArray2[num2]._filename = alias; num2++; } DateTime minValue = DateTime.MinValue; foreach (string str5 in strArray) { DateTime time3 = fileChangesMonitor.StartMonitoringPath(str5, callback, out infoArray2[num2]._fad); infoArray2[num2]._filename = str5; num2++; if (time3 > this._utcLastModified) { this._utcLastModified = time3; } if (utcStart < DateTime.MaxValue) { if (minValue == DateTime.MinValue) { minValue = DateTime.UtcNow; } if ((time3 >= utcStart) && ((time3 - minValue) <= FUTURE_FILETIME_BUFFER)) { this._bits[4] = true; break; } } } if (infoArray2.Length == 1) { this._depFileInfos = infoArray2[0]; } else { this._depFileInfos = infoArray2; } } int num3 = entryArray.Length + strArray2.Length; if ((num3 > 0) && !this._bits[4]) { CacheEntry[] entryArray2 = new CacheEntry[num3]; int num4 = 0; foreach (CacheEntry entry2 in entryArray) { entry2.AddCacheDependencyNotify(this); entryArray2[num4++] = entry2; } CacheInternal cacheInternal = HttpRuntime.CacheInternal; foreach (string str6 in strArray2) { CacheEntry entry3 = (CacheEntry)cacheInternal.DoGet(isPublic, str6, CacheGetOptions.ReturnCacheEntry); if (entry3 != null) { entry3.AddCacheDependencyNotify(this); entryArray2[num4++] = entry3; if (entry3.UtcCreated > this._utcLastModified) { this._utcLastModified = entry3.UtcCreated; } if ((entry3.State == CacheEntry.EntryState.AddedToCache) && (entry3.UtcCreated <= utcStart)) { continue; } this._bits[4] = true; } else { this._bits[4] = true; } break; } if (entryArray2.Length == 1) { this._entries = entryArray2[0]; } else { this._entries = entryArray2; } } this._bits[1] = true; if (dependency._bits[4]) { this._bits[4] = true; } if (this._bits[0x10] || this._bits[4]) { this.DisposeInternal(); } } catch { this._bits[1] = true; this.DisposeInternal(); throw; } finally { this.InitUniqueID(); } }
internal NotificationQueueItem(FileChangeEventHandler callback, FileAction action, string filename) { this.Callback = callback; this.Action = action; this.Filename = filename; }
internal void StartMonitoringDirectoryRenamesAndBinDirectory(string dir, FileChangeEventHandler callback) { if (string.IsNullOrEmpty(dir)) { throw new HttpException(System.Web.SR.GetString("Invalid_file_name_for_monitoring", new object[] { string.Empty })); } if (!this.IsFCNDisabled) { using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireReaderLock(); try { if (!this._disposed) { this._callbackRenameOrCriticaldirChange = callback; string fullPath = GetFullPath(dir); this._dirMonSubdirs = new DirectoryMonitor(fullPath, true, 2, true); try { this._dirMonSubdirs.StartMonitoringFileWithAssert(null, new FileChangeEventHandler(this.OnSubdirChange), fullPath); } catch { ((IDisposable) this._dirMonSubdirs).Dispose(); this._dirMonSubdirs = null; throw; } this._dirMonSpecialDirs = new ArrayList(); for (int i = 0; i < s_dirsToMonitor.Length; i++) { this._dirMonSpecialDirs.Add(this.ListenToSubdirectoryChanges(fullPath, s_dirsToMonitor[i])); } } } finally { this._lockDispose.ReleaseReaderLock(); } } } }
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 FileChangeEventTarget(OnChangedCallback onChangedCallback) { this._onChangedCallback = onChangedCallback; this._handler = new FileChangeEventHandler(this.OnChanged); }
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; } }
void Init(bool isPublic, string[] filenamesArg, string[] cachekeysArg, CacheDependency dependency, DateTime utcStart) { #if USE_MEMORY_CACHE if (CacheInternal.UseMemoryCache) { InitForMemoryCache(isPublic, filenamesArg, cachekeysArg, dependency, utcStart); return; } #endif DepFileInfo[] depFileInfos = s_depFileInfosEmpty; CacheEntry[] depEntries = s_entriesEmpty; string [] filenames, cachekeys; CacheInternal cacheInternal; _bits = new SafeBitVector32(0); // copy array argument contents so they can't be changed beneath us if (filenamesArg != null) { filenames = (string []) filenamesArg.Clone(); } else { filenames = null; } if (cachekeysArg != null) { cachekeys = (string []) cachekeysArg.Clone(); } else { cachekeys = null; } _utcLastModified = DateTime.MinValue; try { // validate filenames array if (filenames == null) { filenames = s_stringsEmpty; } else { foreach (string f in filenames) { if (f == null) { throw new ArgumentNullException("filenamesArg"); } // demand PathDiscovery if public if (isPublic) { InternalSecurityPermissions.PathDiscovery(f).Demand(); } } } if (cachekeys == null) { cachekeys = s_stringsEmpty; } else { // validate cachekeys array foreach (string k in cachekeys) { if (k == null) { throw new ArgumentNullException("cachekeysArg"); } } } // copy all parts of another dependency if provided if (dependency == null) { dependency = s_dependencyEmpty; } else { if (dependency.GetType() != s_dependencyEmpty.GetType()) { throw new ArgumentException(SR.GetString(SR.Invalid_Dependency_Type)); } // Copy the parts of the dependency we need before // we reference them, as the dependency can change // underneath us. object d_depFileInfos = dependency._depFileInfos; object d_entries = dependency._entries; DateTime d_lastModified = dependency._utcLastModified; // if the dependency we're copying has changed, we're done if (dependency._bits[CHANGED]) { _bits[CHANGED] = true; // There is nothing to dispose because we haven't started // monitoring anything yet. But we call DisposeInternal in // order to set the WANTS_DISPOSE bit. DisposeInternal(); return; } // copy depFileInfos if (d_depFileInfos != null) { if (d_depFileInfos is DepFileInfo) { depFileInfos = new DepFileInfo[1] {(DepFileInfo) d_depFileInfos}; } else { depFileInfos = (DepFileInfo[]) (d_depFileInfos); } // verify that the object was fully constructed // and that we have permission to discover the file foreach (DepFileInfo depFileInfo in depFileInfos) { string f = depFileInfo._filename; if (f == null) { _bits[CHANGED] = true; // There is nothing to dispose because we haven't started // monitoring anything yet. But we call DisposeInternal in // order to set the WANTS_DISPOSE bit. DisposeInternal(); return; } // demand PathDiscovery if public if (isPublic) { InternalSecurityPermissions.PathDiscovery(f).Demand(); } } } // copy cache entries if (d_entries != null) { if (d_entries is CacheEntry) { depEntries = new CacheEntry[1] {(CacheEntry) (d_entries)}; } else { depEntries = (CacheEntry[]) (d_entries); // verify that the object was fully constructed foreach (CacheEntry entry in depEntries) { if (entry == null) { _bits[CHANGED] = true; // There is nothing to dispose because we haven't started // monitoring anything yet. But we call DisposeInternal in // order to set the WANTS_DISPOSE bit. DisposeInternal(); return; } } } } _utcLastModified = d_lastModified; } // Monitor files for changes int lenMyDepFileInfos = depFileInfos.Length + filenames.Length; if (lenMyDepFileInfos > 0) { DepFileInfo[] myDepFileInfos = new DepFileInfo[lenMyDepFileInfos]; FileChangeEventHandler handler = new FileChangeEventHandler(this.FileChange); FileChangesMonitor fmon = HttpRuntime.FileChangesMonitor; int i; for (i = 0; i < lenMyDepFileInfos; i++) { myDepFileInfos[i] = new DepFileInfo(); } // monitor files from the existing dependency // note that we don't check for start times in the existing dependency i = 0; foreach (DepFileInfo depFileInfo in depFileInfos) { string f = depFileInfo._filename; fmon.StartMonitoringPath(f, handler, out myDepFileInfos[i]._fad); myDepFileInfos[i]._filename = f; i++; } // monitor new files DateTime utcNow = DateTime.MinValue; foreach (string f in filenames) { DateTime utcLastWrite = fmon.StartMonitoringPath(f, handler, out myDepFileInfos[i]._fad); myDepFileInfos[i]._filename = f; i++; if (utcLastWrite > _utcLastModified) { _utcLastModified = utcLastWrite; } // check if file has changed since the start time if (utcStart < DateTime.MaxValue) { if (utcNow == DateTime.MinValue) { utcNow = DateTime.UtcNow; } Debug.Trace("CacheDependencyInit", "file=" + f + "; utcStart=" + utcStart + "; utcLastWrite=" + utcLastWrite); if (utcLastWrite >= utcStart && !(utcLastWrite - utcNow > FUTURE_FILETIME_BUFFER)) { // See VSWhidbey 400917 Debug.Trace("CacheDependencyInit", "changes occurred since start time for file " + f); _bits[CHANGED] = true; break; } } } if (myDepFileInfos.Length == 1) { _depFileInfos = myDepFileInfos[0]; } else { _depFileInfos = myDepFileInfos; } } // Monitor other cache entries for changes int lenMyEntries = depEntries.Length + cachekeys.Length; if (lenMyEntries > 0 && !_bits[CHANGED]) { CacheEntry[] myEntries = new CacheEntry[lenMyEntries]; // Monitor entries from the existing cache dependency int i = 0; foreach (CacheEntry entry in depEntries) { entry.AddCacheDependencyNotify(this); myEntries[i++] = entry; } // Monitor new entries specified for this depenedency // Entries must be added to cache, and created before the startTime cacheInternal = HttpRuntime.CacheInternal; foreach (string k in cachekeys) { CacheEntry entry = (CacheEntry) cacheInternal.DoGet(isPublic, k, CacheGetOptions.ReturnCacheEntry); if (entry != null) { entry.AddCacheDependencyNotify(this); myEntries[i++] = entry; if (entry.UtcCreated > _utcLastModified) { _utcLastModified = entry.UtcCreated; } if ( entry.State != CacheEntry.EntryState.AddedToCache || entry.UtcCreated > utcStart) { #if DBG if (entry.State != CacheEntry.EntryState.AddedToCache) { Debug.Trace("CacheDependencyInit", "Entry is not in cache, considered changed:" + k); } else { Debug.Trace("CacheDependencyInit", "Changes occurred to entry since start time:" + k); } #endif _bits[CHANGED] = true; break; } } else { Debug.Trace("CacheDependencyInit", "Cache item not found to create dependency on:" + k); _bits[CHANGED] = true; break; } } if (myEntries.Length == 1) { _entries = myEntries[0]; } else { _entries = myEntries; } } _bits[BASE_INIT] = true; if (dependency._bits[CHANGED]) { _bits[CHANGED] = true; } if (_bits[WANTS_DISPOSE] || _bits[CHANGED]) { DisposeInternal(); } Debug.Assert(_objNotify == null, "_objNotify == null"); } catch { // derived constructor will not execute due to the throw, // so we just force a dispose on ourselves _bits[BASE_INIT] = true; DisposeInternal(); throw; } finally { InitUniqueID(); } }
internal void Stop() { if (!this.IsFCNDisabled) { using (new ApplicationImpersonationContext()) { this._lockDispose.AcquireWriterLock(); try { this._disposed = true; goto Label_0039; } finally { this._lockDispose.ReleaseWriterLock(); } Label_002F: Thread.Sleep(250); Label_0039: if (this._activeCallbackCount != 0) { goto Label_002F; } if (this._dirMonSubdirs != null) { this._dirMonSubdirs.StopMonitoring(); this._dirMonSubdirs = null; } if (this._dirMonSpecialDirs != null) { foreach (DirectoryMonitor monitor in this._dirMonSpecialDirs) { if (monitor != null) { monitor.StopMonitoring(); } } this._dirMonSpecialDirs = null; } this._callbackRenameOrCriticaldirChange = null; if (this._dirs != null) { IDictionaryEnumerator enumerator = this._dirs.GetEnumerator(); while (enumerator.MoveNext()) { ((DirectoryMonitor) enumerator.Value).StopMonitoring(); } } this._dirs.Clear(); this._aliases.Clear(); } } }
private XmlDocument GetConfigDocument() { if (_document != null) { return(_document); } if (!_initialized) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Not_Initialized)); } // Do the error checking here if (_virtualPath == null) { throw new ArgumentException( SR.GetString(SR.XmlSiteMapProvider_missing_siteMapFile, _siteMapFileAttribute)); } if (!_virtualPath.Extension.Equals(_xmlSiteMapFileExtension, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_Invalid_Extension, _virtualPath)); } _normalizedVirtualPath = _virtualPath.CombineWithAppRoot(); _normalizedVirtualPath.FailIfNotWithinAppRoot(); // Make sure the file exists CheckSiteMapFileExists(); _parentSiteMapFileCollection = new StringCollection(); XmlSiteMapProvider xmlParentProvider = ParentProvider as XmlSiteMapProvider; if (xmlParentProvider != null && xmlParentProvider._parentSiteMapFileCollection != null) { if (xmlParentProvider._parentSiteMapFileCollection.Contains(_normalizedVirtualPath.VirtualPathString)) { throw new InvalidOperationException( SR.GetString(SR.XmlSiteMapProvider_FileName_already_in_use, _virtualPath)); } // Copy the sitemapfiles in used from parent provider to current provider. foreach (string filename in xmlParentProvider._parentSiteMapFileCollection) { _parentSiteMapFileCollection.Add(filename); } } // Add current sitemap file to the collection _parentSiteMapFileCollection.Add(_normalizedVirtualPath.VirtualPathString); _filename = HostingEnvironment.MapPathInternal(_normalizedVirtualPath); if (!String.IsNullOrEmpty(_filename)) { _handler = new FileChangeEventHandler(this.OnConfigFileChange); HttpRuntime.FileChangesMonitor.StartMonitoringFile(_filename, _handler); ResourceKey = (new FileInfo(_filename)).Name; } _document = new ConfigXmlDocument(); return(_document); }
private void Init(bool isPublic, string[] filenamesArg, string[] cachekeysArg, CacheDependency dependency, DateTime utcStart) { string[] strArray; string[] strArray2; DepFileInfo[] infoArray = s_depFileInfosEmpty; CacheEntry[] entryArray = s_entriesEmpty; this._bits = new SafeBitVector32(0); if (filenamesArg != null) { strArray = (string[]) filenamesArg.Clone(); } else { strArray = null; } if (cachekeysArg != null) { strArray2 = (string[]) cachekeysArg.Clone(); } else { strArray2 = null; } this._utcLastModified = DateTime.MinValue; try { if (strArray == null) { strArray = s_stringsEmpty; } else { foreach (string str in strArray) { if (str == null) { throw new ArgumentNullException("filenamesArg"); } if (isPublic) { InternalSecurityPermissions.PathDiscovery(str).Demand(); } } } if (strArray2 == null) { strArray2 = s_stringsEmpty; } else { string[] strArray4 = strArray2; for (int i = 0; i < strArray4.Length; i++) { if (strArray4[i] == null) { throw new ArgumentNullException("cachekeysArg"); } } } if (dependency == null) { dependency = s_dependencyEmpty; } else { if (dependency.GetType() != s_dependencyEmpty.GetType()) { throw new ArgumentException(System.Web.SR.GetString("Invalid_Dependency_Type")); } object obj2 = dependency._depFileInfos; object obj3 = dependency._entries; DateTime time = dependency._utcLastModified; if (dependency._bits[4]) { this._bits[4] = true; this.DisposeInternal(); return; } if (obj2 != null) { if (obj2 is DepFileInfo) { infoArray = new DepFileInfo[] { (DepFileInfo) obj2 }; } else { infoArray = (DepFileInfo[]) obj2; } foreach (DepFileInfo info in infoArray) { string path = info._filename; if (path == null) { this._bits[4] = true; this.DisposeInternal(); return; } if (isPublic) { InternalSecurityPermissions.PathDiscovery(path).Demand(); } } } if (obj3 != null) { if (obj3 is CacheEntry) { entryArray = new CacheEntry[] { (CacheEntry) obj3 }; } else { entryArray = (CacheEntry[]) obj3; CacheEntry[] entryArray4 = entryArray; for (int j = 0; j < entryArray4.Length; j++) { if (entryArray4[j] == null) { this._bits[4] = true; this.DisposeInternal(); return; } } } } this._utcLastModified = time; } int num = infoArray.Length + strArray.Length; if (num > 0) { int num2; DepFileInfo[] infoArray2 = new DepFileInfo[num]; FileChangeEventHandler callback = new FileChangeEventHandler(this.FileChange); FileChangesMonitor fileChangesMonitor = HttpRuntime.FileChangesMonitor; for (num2 = 0; num2 < num; num2++) { infoArray2[num2] = new DepFileInfo(); } num2 = 0; foreach (DepFileInfo info2 in infoArray) { string alias = info2._filename; fileChangesMonitor.StartMonitoringPath(alias, callback, out infoArray2[num2]._fad); infoArray2[num2]._filename = alias; num2++; } DateTime minValue = DateTime.MinValue; foreach (string str5 in strArray) { DateTime time3 = fileChangesMonitor.StartMonitoringPath(str5, callback, out infoArray2[num2]._fad); infoArray2[num2]._filename = str5; num2++; if (time3 > this._utcLastModified) { this._utcLastModified = time3; } if (utcStart < DateTime.MaxValue) { if (minValue == DateTime.MinValue) { minValue = DateTime.UtcNow; } if ((time3 >= utcStart) && ((time3 - minValue) <= FUTURE_FILETIME_BUFFER)) { this._bits[4] = true; break; } } } if (infoArray2.Length == 1) { this._depFileInfos = infoArray2[0]; } else { this._depFileInfos = infoArray2; } } int num3 = entryArray.Length + strArray2.Length; if ((num3 > 0) && !this._bits[4]) { CacheEntry[] entryArray2 = new CacheEntry[num3]; int num4 = 0; foreach (CacheEntry entry2 in entryArray) { entry2.AddCacheDependencyNotify(this); entryArray2[num4++] = entry2; } CacheInternal cacheInternal = HttpRuntime.CacheInternal; foreach (string str6 in strArray2) { CacheEntry entry3 = (CacheEntry) cacheInternal.DoGet(isPublic, str6, CacheGetOptions.ReturnCacheEntry); if (entry3 != null) { entry3.AddCacheDependencyNotify(this); entryArray2[num4++] = entry3; if (entry3.UtcCreated > this._utcLastModified) { this._utcLastModified = entry3.UtcCreated; } if ((entry3.State == CacheEntry.EntryState.AddedToCache) && (entry3.UtcCreated <= utcStart)) { continue; } this._bits[4] = true; } else { this._bits[4] = true; } break; } if (entryArray2.Length == 1) { this._entries = entryArray2[0]; } else { this._entries = entryArray2; } } this._bits[1] = true; if (dependency._bits[4]) { this._bits[4] = true; } if (this._bits[0x10] || this._bits[4]) { this.DisposeInternal(); } } catch { this._bits[1] = true; this.DisposeInternal(); throw; } finally { this.InitUniqueID(); } }