internal int RemoveTarget(object callbackTarget) { FileMonitorTarget target = (FileMonitorTarget)this._targets[callbackTarget]; if ((target != null) && (target.Release() == 0)) { this._targets.Remove(callbackTarget); } return(this._targets.Count); }
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; } }
private bool IsChangeAfterStartMonitoring(FileAttributesData fad, FileMonitorTarget target, DateTime utcCompletion) { return ((fad.UtcLastAccessTime.AddSeconds(60.0) < target.UtcStartMonitoring) || ((utcCompletion > target.UtcStartMonitoring) || ((fad.UtcLastAccessTime < fad.UtcLastWriteTime) || ((fad.UtcLastAccessTime.TimeOfDay == TimeSpan.Zero) || (fad.UtcLastAccessTime >= target.UtcStartMonitoring))))); }
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) { } }
private bool IsChangeAfterStartMonitoring(FileAttributesData fad, FileMonitorTarget target, DateTime utcCompletion) { return((fad.UtcLastAccessTime.AddSeconds(60.0) < target.UtcStartMonitoring) || ((utcCompletion > target.UtcStartMonitoring) || ((fad.UtcLastAccessTime < fad.UtcLastWriteTime) || ((fad.UtcLastAccessTime.TimeOfDay == TimeSpan.Zero) || (fad.UtcLastAccessTime >= target.UtcStartMonitoring))))); }