Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / Compilation / IImplicitResourceProvider.cs / 1 / IImplicitResourceProvider.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.IO;
using System.CodeDom;
using System.Globalization;
using System.Resources;
using System.Web.Compilation;
using System.Web.Util;
using System.Web.UI;
using System.Security.Permissions;
/*
* Interface to access implicit (automatic) page resources
*/
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public interface IImplicitResourceProvider {
/*
* Retrieve a resource object for the passed in key and culture
*/
object GetObject(ImplicitResourceKey key, CultureInfo culture);
/*
* Return a collection of ImplicitResourceKey's for the given prefix
*/
ICollection GetImplicitResourceKeys(string keyPrefix);
}
/*
* Contains fields which identify a specific implicit resource key
*/
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class ImplicitResourceKey {
private string _filter;
private string _keyPrefix;
private string _property;
public ImplicitResourceKey() {
}
public ImplicitResourceKey(string filter, string keyPrefix, string property) {
_filter = filter;
_keyPrefix = keyPrefix;
_property = property;
}
/*
* The filter, if any
*/
public string Filter {
get {
return _filter;
}
set {
_filter = value;
}
}
/*
* The prefix, as appears on tag's meta:resourcekey attributes
*/
public string KeyPrefix {
get {
return _keyPrefix;
}
set {
_keyPrefix = value;
}
}
/*
* The property, possibly including sub-properties (e.g. MyProp.MySubProp)
*/
public string Property {
get {
return _property;
}
set {
_property = value;
}
}
}
/*
* IImplicitResourceProvider implementation on top of an arbitrary IResourceProvider
*/
internal class DefaultImplicitResourceProvider: IImplicitResourceProvider {
private IResourceProvider _resourceProvider;
private IDictionary _implicitResources;
private bool _attemptedGetPageResources;
internal DefaultImplicitResourceProvider(IResourceProvider resourceProvider) {
_resourceProvider = resourceProvider;
}
public virtual object GetObject(ImplicitResourceKey entry, CultureInfo culture) {
// Put together the full resource key based on the ImplicitResourceKey
string fullResourceKey = ConstructFullKey(entry);
// Look it up in the resource provider
return _resourceProvider.GetObject(fullResourceKey, culture);
}
public virtual ICollection GetImplicitResourceKeys(string keyPrefix) {
// Try to get the page resources
EnsureGetPageResources();
// If there aren't any, return null
if (_implicitResources == null)
return null;
// Return the collection of resources for this key prefix
return (ICollection) _implicitResources[keyPrefix];
}
/*
* Create a dictionary, in which the key is a resource key (as found on meta:resourcekey
* attributes), and the value is an ArrayList containing all the resources for that
* resource key. Each element of the ArrayList is an ImplicitResourceKey
*/
internal void EnsureGetPageResources() {
// If we already attempted to get them, don't do it again
if (_attemptedGetPageResources)
return;
_attemptedGetPageResources = true;
IResourceReader resourceReader = _resourceProvider.ResourceReader;
if (resourceReader == null)
return;
_implicitResources = new Hashtable(StringComparer.OrdinalIgnoreCase);
// Enumerate through all the page resources
foreach (DictionaryEntry entry in resourceReader) {
// Attempt to parse the key into a ImplicitResourceKey
ImplicitResourceKey implicitResKey = ParseFullKey((string) entry.Key);
// If we couldn't parse it as such, skip it
if (implicitResKey == null)
continue;
// Check if we already have an entry for this resource key prefix
ArrayList controlResources = (ArrayList) _implicitResources[implicitResKey.KeyPrefix];
// If not, create one
if (controlResources == null) {
controlResources = new ArrayList();
_implicitResources[implicitResKey.KeyPrefix] = controlResources;
}
// Add an entry in the ArrayList for this property
controlResources.Add(implicitResKey);
}
}
/*
* Parse a complete page resource key into a ImplicitResourceKey.
* Return null if the key does not appear to be meant for implict resources.
*/
private static ImplicitResourceKey ParseFullKey(string key) {
string filter = String.Empty;
// A page resource key looks like [myfilter:]MyResKey.MyProp[.MySubProp]
// Check if there is a filter
if (key.IndexOf(':') > 0) {
string[] parts = key.Split(':');
// Shouldn't be multiple ':'. If there is, ignore it
if (parts.Length > 2)
return null;
filter = parts[0];
key = parts[1];
}
int periodIndex = key.IndexOf('.');
// There should be at least one period, for the meta:resourcekey part. If not, ignore.
if (periodIndex <= 0)
return null;
string keyPrefix = key.Substring(0, periodIndex);
// The rest of the string is the property (e.g. MyProp.MySubProp)
string property = key.Substring(periodIndex+1);
// Create a ImplicitResourceKey with the parsed data
ImplicitResourceKey implicitResKey = new ImplicitResourceKey();
implicitResKey.Filter = filter;
implicitResKey.KeyPrefix = keyPrefix;
implicitResKey.Property = property;
return implicitResKey;
}
private static string ConstructFullKey(ImplicitResourceKey entry) {
string key = entry.KeyPrefix + "." + entry.Property;
if (entry.Filter.Length > 0)
key = entry.Filter + ":" + key;
return key;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.IO;
using System.CodeDom;
using System.Globalization;
using System.Resources;
using System.Web.Compilation;
using System.Web.Util;
using System.Web.UI;
using System.Security.Permissions;
/*
* Interface to access implicit (automatic) page resources
*/
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public interface IImplicitResourceProvider {
/*
* Retrieve a resource object for the passed in key and culture
*/
object GetObject(ImplicitResourceKey key, CultureInfo culture);
/*
* Return a collection of ImplicitResourceKey's for the given prefix
*/
ICollection GetImplicitResourceKeys(string keyPrefix);
}
/*
* Contains fields which identify a specific implicit resource key
*/
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class ImplicitResourceKey {
private string _filter;
private string _keyPrefix;
private string _property;
public ImplicitResourceKey() {
}
public ImplicitResourceKey(string filter, string keyPrefix, string property) {
_filter = filter;
_keyPrefix = keyPrefix;
_property = property;
}
/*
* The filter, if any
*/
public string Filter {
get {
return _filter;
}
set {
_filter = value;
}
}
/*
* The prefix, as appears on tag's meta:resourcekey attributes
*/
public string KeyPrefix {
get {
return _keyPrefix;
}
set {
_keyPrefix = value;
}
}
/*
* The property, possibly including sub-properties (e.g. MyProp.MySubProp)
*/
public string Property {
get {
return _property;
}
set {
_property = value;
}
}
}
/*
* IImplicitResourceProvider implementation on top of an arbitrary IResourceProvider
*/
internal class DefaultImplicitResourceProvider: IImplicitResourceProvider {
private IResourceProvider _resourceProvider;
private IDictionary _implicitResources;
private bool _attemptedGetPageResources;
internal DefaultImplicitResourceProvider(IResourceProvider resourceProvider) {
_resourceProvider = resourceProvider;
}
public virtual object GetObject(ImplicitResourceKey entry, CultureInfo culture) {
// Put together the full resource key based on the ImplicitResourceKey
string fullResourceKey = ConstructFullKey(entry);
// Look it up in the resource provider
return _resourceProvider.GetObject(fullResourceKey, culture);
}
public virtual ICollection GetImplicitResourceKeys(string keyPrefix) {
// Try to get the page resources
EnsureGetPageResources();
// If there aren't any, return null
if (_implicitResources == null)
return null;
// Return the collection of resources for this key prefix
return (ICollection) _implicitResources[keyPrefix];
}
/*
* Create a dictionary, in which the key is a resource key (as found on meta:resourcekey
* attributes), and the value is an ArrayList containing all the resources for that
* resource key. Each element of the ArrayList is an ImplicitResourceKey
*/
internal void EnsureGetPageResources() {
// If we already attempted to get them, don't do it again
if (_attemptedGetPageResources)
return;
_attemptedGetPageResources = true;
IResourceReader resourceReader = _resourceProvider.ResourceReader;
if (resourceReader == null)
return;
_implicitResources = new Hashtable(StringComparer.OrdinalIgnoreCase);
// Enumerate through all the page resources
foreach (DictionaryEntry entry in resourceReader) {
// Attempt to parse the key into a ImplicitResourceKey
ImplicitResourceKey implicitResKey = ParseFullKey((string) entry.Key);
// If we couldn't parse it as such, skip it
if (implicitResKey == null)
continue;
// Check if we already have an entry for this resource key prefix
ArrayList controlResources = (ArrayList) _implicitResources[implicitResKey.KeyPrefix];
// If not, create one
if (controlResources == null) {
controlResources = new ArrayList();
_implicitResources[implicitResKey.KeyPrefix] = controlResources;
}
// Add an entry in the ArrayList for this property
controlResources.Add(implicitResKey);
}
}
/*
* Parse a complete page resource key into a ImplicitResourceKey.
* Return null if the key does not appear to be meant for implict resources.
*/
private static ImplicitResourceKey ParseFullKey(string key) {
string filter = String.Empty;
// A page resource key looks like [myfilter:]MyResKey.MyProp[.MySubProp]
// Check if there is a filter
if (key.IndexOf(':') > 0) {
string[] parts = key.Split(':');
// Shouldn't be multiple ':'. If there is, ignore it
if (parts.Length > 2)
return null;
filter = parts[0];
key = parts[1];
}
int periodIndex = key.IndexOf('.');
// There should be at least one period, for the meta:resourcekey part. If not, ignore.
if (periodIndex <= 0)
return null;
string keyPrefix = key.Substring(0, periodIndex);
// The rest of the string is the property (e.g. MyProp.MySubProp)
string property = key.Substring(periodIndex+1);
// Create a ImplicitResourceKey with the parsed data
ImplicitResourceKey implicitResKey = new ImplicitResourceKey();
implicitResKey.Filter = filter;
implicitResKey.KeyPrefix = keyPrefix;
implicitResKey.Property = property;
return implicitResKey;
}
private static string ConstructFullKey(ImplicitResourceKey entry) {
string key = entry.KeyPrefix + "." + entry.Property;
if (entry.Filter.Length > 0)
key = entry.Filter + ":" + key;
return key;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NegotiateStream.cs
- QuadraticBezierSegment.cs
- DiagnosticsConfiguration.cs
- PageVisual.cs
- DecoderExceptionFallback.cs
- SqlSupersetValidator.cs
- SqlDependencyListener.cs
- SystemBrushes.cs
- _NegoStream.cs
- MsmqInputMessage.cs
- VarRemapper.cs
- QueryConverter.cs
- RsaSecurityKey.cs
- SerTrace.cs
- HttpCachePolicyWrapper.cs
- Emitter.cs
- MetadataHelper.cs
- CollectionChangedEventManager.cs
- AssociationSetMetadata.cs
- OrderedDictionary.cs
- MarkupObject.cs
- CombinedGeometry.cs
- AnimationException.cs
- InArgumentConverter.cs
- AssemblyBuilder.cs
- XmlHelper.cs
- MenuBindingsEditor.cs
- Compiler.cs
- OdbcDataAdapter.cs
- PreservationFileWriter.cs
- ContextActivityUtils.cs
- FileFormatException.cs
- DataSourceCacheDurationConverter.cs
- XPathAncestorIterator.cs
- TemplatedWizardStep.cs
- BulletedListEventArgs.cs
- BinaryConverter.cs
- HttpResponseHeader.cs
- CalloutQueueItem.cs
- Debug.cs
- ClientConfigPaths.cs
- IndexedGlyphRun.cs
- TreeIterators.cs
- StringInfo.cs
- QuaternionValueSerializer.cs
- DebugTrace.cs
- ColorComboBox.cs
- SelectedCellsCollection.cs
- ExclusiveTcpListener.cs
- CurrentTimeZone.cs
- BufferedGraphics.cs
- ProcessModelSection.cs
- BitmapEffectCollection.cs
- ArrayTypeMismatchException.cs
- Model3D.cs
- DSASignatureFormatter.cs
- listitem.cs
- StreamReader.cs
- XmlNullResolver.cs
- manifestimages.cs
- ImportContext.cs
- FontStyle.cs
- GlobalizationSection.cs
- CheckBoxPopupAdapter.cs
- FSWPathEditor.cs
- ActivityInterfaces.cs
- MultipleViewProviderWrapper.cs
- PDBReader.cs
- CalendarItem.cs
- EdmConstants.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- DbConvert.cs
- CodeDomSerializerException.cs
- Freezable.cs
- HttpHandlersSection.cs
- FullTextBreakpoint.cs
- GatewayDefinition.cs
- ColumnHeaderConverter.cs
- GridViewColumnHeader.cs
- DoubleAnimation.cs
- HttpDebugHandler.cs
- ProviderManager.cs
- PresentationSource.cs
- MD5.cs
- StyleHelper.cs
- HelpFileFileNameEditor.cs
- ToolStripComboBox.cs
- DataGridViewSelectedCellsAccessibleObject.cs
- BrowserCapabilitiesCodeGenerator.cs
- FieldNameLookup.cs
- ConstrainedGroup.cs
- XamlStream.cs
- DeclaredTypeValidatorAttribute.cs
- LineUtil.cs
- ObservableCollection.cs
- SafeNativeMethods.cs
- QilInvokeEarlyBound.cs
- PrivateFontCollection.cs
- RectangleGeometry.cs
- wmiprovider.cs