Code:
/ 4.0 / 4.0 / 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. 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
- ActivitiesCollection.cs
- ProcessModelInfo.cs
- ToolStripItemGlyph.cs
- Span.cs
- ItemsPresenter.cs
- DataMemberConverter.cs
- RuntimeWrappedException.cs
- HttpDebugHandler.cs
- ReliableOutputConnection.cs
- PerformanceCounterPermission.cs
- BitmapSizeOptions.cs
- WebPartVerbsEventArgs.cs
- SinglePhaseEnlistment.cs
- EnterpriseServicesHelper.cs
- DefinitionBase.cs
- ArrayWithOffset.cs
- TextTreeTextNode.cs
- PolicyException.cs
- CompositeTypefaceMetrics.cs
- StyleXamlParser.cs
- GetIsBrowserClientRequest.cs
- DataTableMapping.cs
- FlowDocumentReaderAutomationPeer.cs
- MenuDesigner.cs
- WebDisplayNameAttribute.cs
- CellCreator.cs
- PropertyConverter.cs
- COM2TypeInfoProcessor.cs
- XmlQualifiedNameTest.cs
- InvalidPrinterException.cs
- AdapterUtil.cs
- SequenceDesigner.xaml.cs
- RegexMatchCollection.cs
- FacetChecker.cs
- BaseAsyncResult.cs
- ConfigUtil.cs
- TextEditorTyping.cs
- SynchronizedPool.cs
- AutomationPattern.cs
- ConfigXmlComment.cs
- CodeAccessPermission.cs
- IPAddressCollection.cs
- CollectionViewGroup.cs
- StorageMappingItemLoader.cs
- TreeViewTemplateSelector.cs
- parserscommon.cs
- OleCmdHelper.cs
- OutOfMemoryException.cs
- OdbcConnectionString.cs
- RegexCode.cs
- CheckBox.cs
- DiscoveryReferences.cs
- DataGridViewCheckBoxColumn.cs
- CodeDOMProvider.cs
- SuppressMergeCheckAttribute.cs
- StorageAssociationSetMapping.cs
- WebBrowserNavigatedEventHandler.cs
- DocumentSequenceHighlightLayer.cs
- LoginAutoFormat.cs
- CellParaClient.cs
- DocumentPageViewAutomationPeer.cs
- MetadataCache.cs
- CollectionChangeEventArgs.cs
- SiteMembershipCondition.cs
- wgx_exports.cs
- DataPagerFieldItem.cs
- PartialToken.cs
- MethodBody.cs
- CryptoKeySecurity.cs
- AuthenticationSection.cs
- MatrixUtil.cs
- HttpProcessUtility.cs
- GridItemProviderWrapper.cs
- WindowsProgressbar.cs
- BooleanExpr.cs
- MSHTMLHost.cs
- BidirectionalDictionary.cs
- MethodImplAttribute.cs
- HashHelper.cs
- SQLSingle.cs
- UnicodeEncoding.cs
- DllNotFoundException.cs
- LinqTreeNodeEvaluator.cs
- CommunicationObjectFaultedException.cs
- MeasureData.cs
- WmlImageAdapter.cs
- StringBuilder.cs
- AllowedAudienceUriElement.cs
- CheckedPointers.cs
- InfoCardConstants.cs
- XmlSchemaObjectTable.cs
- SoapServerProtocol.cs
- TableItemStyle.cs
- OrderPreservingPipeliningMergeHelper.cs
- ExtendedProtectionPolicyElement.cs
- DataReceivedEventArgs.cs
- RevocationPoint.cs
- UniqueEventHelper.cs
- cookieexception.cs
- BaseConfigurationRecord.cs