Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / Util / FileChangeNotifier.cs / 1305376 / FileChangeNotifier.cs
using System.Collections; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections.Specialized; using System.Diagnostics; using System.Web.Resources; using System.Globalization; using System.Web.Caching; using System.Web.Hosting; namespace System.Web.DynamicData { delegate void FileChangedCallback(string path); class FileChangeNotifier { private static VirtualPathProvider _vpp; internal static VirtualPathProvider VirtualPathProvider { private get { if (_vpp == null) { _vpp = HostingEnvironment.VirtualPathProvider; } return _vpp; } // For unit test purpose set { _vpp = value; } } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Web.DynamicData.FileChangeNotifier", Justification="The object deals with file change notifications and we don't need to hold on to it")] internal static void Register(string virtualPath, FileChangedCallback onFileChanged) { new FileChangeNotifier(virtualPath, onFileChanged); } private FileChangedCallback _onFileChanged; private FileChangeNotifier(string virtualPath, FileChangedCallback onFileChanged) { _onFileChanged = onFileChanged; RegisterForNextNotification(virtualPath); } private void RegisterForNextNotification(string virtualPath) { // Get a CacheDependency from the BuildProvider, so that we know anytime something changes var virtualPathDependencies = new List(); virtualPathDependencies.Add(virtualPath); CacheDependency cacheDependency = VirtualPathProvider.GetCacheDependency( virtualPath, virtualPathDependencies, DateTime.UtcNow); // Rely on the ASP.NET cache for file change notifications, since FileSystemWatcher // doesn't work in medium trust HttpRuntime.Cache.Insert(virtualPath /*key*/, virtualPath /*value*/, cacheDependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(OnCacheItemRemoved)); } private void OnCacheItemRemoved(string key, object value, CacheItemRemovedReason reason) { // We only care about dependency changes if (reason != CacheItemRemovedReason.DependencyChanged) return; _onFileChanged(key); // We need to register again to get the next notification RegisterForNextNotification(key); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HttpServerProtocol.cs
- HandoffBehavior.cs
- ArrayHelper.cs
- ComPlusAuthorization.cs
- NativeMsmqMessage.cs
- LinqDataSourceHelper.cs
- SiteMapDataSourceView.cs
- ClientRuntimeConfig.cs
- _ScatterGatherBuffers.cs
- StringKeyFrameCollection.cs
- AddInServer.cs
- CommonProperties.cs
- AssemblyAssociatedContentFileAttribute.cs
- URLEditor.cs
- FixedSOMTableRow.cs
- ButtonColumn.cs
- EnumValidator.cs
- CompilerError.cs
- DetailsViewRowCollection.cs
- AppliedDeviceFiltersEditor.cs
- Light.cs
- NonSerializedAttribute.cs
- ClientConfigurationHost.cs
- LocalIdKeyIdentifierClause.cs
- TextRange.cs
- DeferredBinaryDeserializerExtension.cs
- SplashScreenNativeMethods.cs
- WriteStateInfoBase.cs
- BounceEase.cs
- embossbitmapeffect.cs
- UIInitializationException.cs
- DrawingBrush.cs
- ViewManager.cs
- AsymmetricKeyExchangeDeformatter.cs
- EnumerableRowCollection.cs
- AnnotationMap.cs
- DiscardableAttribute.cs
- BamlResourceContent.cs
- ClientSettingsProvider.cs
- WebServiceReceiveDesigner.cs
- TimeIntervalCollection.cs
- TypeNameConverter.cs
- ThreadPool.cs
- OperationResponse.cs
- ControlCodeDomSerializer.cs
- XmlChoiceIdentifierAttribute.cs
- RuntimeConfigurationRecord.cs
- CheckoutException.cs
- ResXResourceReader.cs
- ExpressionHelper.cs
- DataGridViewCellLinkedList.cs
- basevalidator.cs
- DataGridTextBoxColumn.cs
- HtmlTableCellCollection.cs
- Material.cs
- WebBrowserEvent.cs
- ProgressBarHighlightConverter.cs
- DataGridViewCellStyleConverter.cs
- PersonalizationProviderHelper.cs
- StructuredTypeEmitter.cs
- PassportPrincipal.cs
- WebBaseEventKeyComparer.cs
- documentation.cs
- PathGradientBrush.cs
- ContentElement.cs
- HttpListenerRequest.cs
- WindowInteractionStateTracker.cs
- IndexerNameAttribute.cs
- Int64Animation.cs
- HttpContext.cs
- HostingEnvironmentException.cs
- WpfPayload.cs
- CopyAttributesAction.cs
- StopStoryboard.cs
- VSWCFServiceContractGenerator.cs
- CodeBlockBuilder.cs
- Point4DConverter.cs
- IpcChannel.cs
- TempFiles.cs
- PathData.cs
- AnnotationStore.cs
- ControlPropertyNameConverter.cs
- ControlBuilder.cs
- SecurityContextSecurityTokenResolver.cs
- StringToken.cs
- ObjectManager.cs
- StateValidator.cs
- Rotation3DAnimationBase.cs
- UdpDiscoveryMessageFilter.cs
- ContainerUtilities.cs
- QilCloneVisitor.cs
- EntitySqlException.cs
- HttpSessionStateBase.cs
- ViewValidator.cs
- StickyNoteHelper.cs
- BrowsableAttribute.cs
- EdgeProfileValidation.cs
- ItemType.cs
- StylusPoint.cs
- CompModSwitches.cs