Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / UI / ScriptResourceMapping.cs / 1305376 / ScriptResourceMapping.cs
namespace System.Web.UI {
using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.Reflection;
using System.Web.Resources;
using System.Web.Util;
public class ScriptResourceMapping : IScriptResourceMapping {
private ConcurrentDictionary, ScriptResourceDefinition> _definitions =
new ConcurrentDictionary, ScriptResourceDefinition>();
public void AddDefinition(string name, ScriptResourceDefinition definition) {
AddDefinition(name, null, definition);
}
public void AddDefinition(string name, Assembly assembly, ScriptResourceDefinition definition) {
// dictionary indexer will update the value if it already exists
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
}
if (definition == null) {
throw new ArgumentNullException("definition");
}
if (String.IsNullOrEmpty(definition.ResourceName) && String.IsNullOrEmpty(definition.Path)) {
throw new ArgumentException(AtlasWeb.ScriptResourceDefinition_NameAndPathCannotBeEmpty, "definition");
}
EnsureAbsoluteOrAppRelative(definition.Path);
EnsureAbsoluteOrAppRelative(definition.DebugPath);
EnsureAbsoluteOrAppRelative(definition.CdnPath);
EnsureAbsoluteOrAppRelative(definition.CdnDebugPath);
_definitions[new Tuple(name, assembly)] = definition;
}
public void Clear() {
_definitions.Clear();
}
private void EnsureAbsoluteOrAppRelative(string path) {
if (!String.IsNullOrEmpty(path) &&
!UrlPath.IsAppRelativePath(path) && // ~/foo..
!UrlPath.IsRooted(path) && // /foo
!Uri.IsWellFormedUriString(path, UriKind.Absolute)) { // http://...
throw new InvalidOperationException(
String.Format(CultureInfo.InvariantCulture, AtlasWeb.ScriptResourceDefinition_InvalidPath, path));
}
}
public ScriptResourceDefinition GetDefinition(string name, Assembly assembly) {
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
}
ScriptResourceDefinition definition;
_definitions.TryGetValue(new Tuple(name, assembly), out definition);
return definition;
}
public ScriptResourceDefinition GetDefinition(ScriptReference scriptReference) {
if (scriptReference == null) {
throw new ArgumentNullException("scriptReference");
}
string name = scriptReference.Name;
Assembly assembly = null;
ScriptResourceDefinition definition = null;
if (!String.IsNullOrEmpty(name)) {
assembly = scriptReference.GetAssembly();
if ((assembly != null) && AssemblyCache.IsAjaxFrameworkAssembly(assembly)) {
assembly = null;
}
definition = ScriptManager.ScriptResourceMapping.GetDefinition(name, assembly);
}
return definition;
}
public ScriptResourceDefinition RemoveDefinition(string name, Assembly assembly) {
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
}
ScriptResourceDefinition definition;
_definitions.TryRemove(new Tuple(name, assembly), out definition);
return definition;
}
#region IScriptResourceMapping Members
IScriptResourceDefinition IScriptResourceMapping.GetDefinition(string name, Assembly assembly) {
return GetDefinition(name, assembly);
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Web.UI {
using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.Reflection;
using System.Web.Resources;
using System.Web.Util;
public class ScriptResourceMapping : IScriptResourceMapping {
private ConcurrentDictionary, ScriptResourceDefinition> _definitions =
new ConcurrentDictionary, ScriptResourceDefinition>();
public void AddDefinition(string name, ScriptResourceDefinition definition) {
AddDefinition(name, null, definition);
}
public void AddDefinition(string name, Assembly assembly, ScriptResourceDefinition definition) {
// dictionary indexer will update the value if it already exists
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
}
if (definition == null) {
throw new ArgumentNullException("definition");
}
if (String.IsNullOrEmpty(definition.ResourceName) && String.IsNullOrEmpty(definition.Path)) {
throw new ArgumentException(AtlasWeb.ScriptResourceDefinition_NameAndPathCannotBeEmpty, "definition");
}
EnsureAbsoluteOrAppRelative(definition.Path);
EnsureAbsoluteOrAppRelative(definition.DebugPath);
EnsureAbsoluteOrAppRelative(definition.CdnPath);
EnsureAbsoluteOrAppRelative(definition.CdnDebugPath);
_definitions[new Tuple(name, assembly)] = definition;
}
public void Clear() {
_definitions.Clear();
}
private void EnsureAbsoluteOrAppRelative(string path) {
if (!String.IsNullOrEmpty(path) &&
!UrlPath.IsAppRelativePath(path) && // ~/foo..
!UrlPath.IsRooted(path) && // /foo
!Uri.IsWellFormedUriString(path, UriKind.Absolute)) { // http://...
throw new InvalidOperationException(
String.Format(CultureInfo.InvariantCulture, AtlasWeb.ScriptResourceDefinition_InvalidPath, path));
}
}
public ScriptResourceDefinition GetDefinition(string name, Assembly assembly) {
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
}
ScriptResourceDefinition definition;
_definitions.TryGetValue(new Tuple(name, assembly), out definition);
return definition;
}
public ScriptResourceDefinition GetDefinition(ScriptReference scriptReference) {
if (scriptReference == null) {
throw new ArgumentNullException("scriptReference");
}
string name = scriptReference.Name;
Assembly assembly = null;
ScriptResourceDefinition definition = null;
if (!String.IsNullOrEmpty(name)) {
assembly = scriptReference.GetAssembly();
if ((assembly != null) && AssemblyCache.IsAjaxFrameworkAssembly(assembly)) {
assembly = null;
}
definition = ScriptManager.ScriptResourceMapping.GetDefinition(name, assembly);
}
return definition;
}
public ScriptResourceDefinition RemoveDefinition(string name, Assembly assembly) {
if (String.IsNullOrEmpty(name)) {
throw new ArgumentException(AtlasWeb.Common_NullOrEmpty, "name");
}
ScriptResourceDefinition definition;
_definitions.TryRemove(new Tuple(name, assembly), out definition);
return definition;
}
#region IScriptResourceMapping Members
IScriptResourceDefinition IScriptResourceMapping.GetDefinition(string name, Assembly assembly) {
return GetDefinition(name, assembly);
}
#endregion
}
}
// 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
- recordstatescratchpad.cs
- SimpleLine.cs
- ViewCellRelation.cs
- BindingContext.cs
- TextEffect.cs
- SessionStateSection.cs
- RoleManagerSection.cs
- ControlEvent.cs
- RelationshipEntry.cs
- EllipseGeometry.cs
- BooleanKeyFrameCollection.cs
- VirtualizedCellInfoCollection.cs
- TypeSystemProvider.cs
- HMACRIPEMD160.cs
- FontSource.cs
- ProtocolsConfigurationEntry.cs
- ITextView.cs
- DataIdProcessor.cs
- DesignerTextBoxAdapter.cs
- ListViewInsertedEventArgs.cs
- CodeTryCatchFinallyStatement.cs
- AnnotationAuthorChangedEventArgs.cs
- BatchParser.cs
- ScrollBar.cs
- GeometryCollection.cs
- DateTimePicker.cs
- WorkflowFileItem.cs
- CopyNodeSetAction.cs
- DoubleCollection.cs
- ItemsControlAutomationPeer.cs
- TrustExchangeException.cs
- OpCodes.cs
- CompatibleComparer.cs
- FileFormatException.cs
- ValueUtilsSmi.cs
- ContentElement.cs
- CachedTypeface.cs
- XamlLoadErrorInfo.cs
- ImageAnimator.cs
- StatusCommandUI.cs
- RegexGroup.cs
- PlainXmlDeserializer.cs
- TextEditorCharacters.cs
- validation.cs
- XmlSerializerVersionAttribute.cs
- _SslSessionsCache.cs
- ByteArrayHelperWithString.cs
- BaseServiceProvider.cs
- EventRoute.cs
- SerializationSectionGroup.cs
- FormatterServicesNoSerializableCheck.cs
- hwndwrapper.cs
- BindingFormattingDialog.cs
- TableDetailsCollection.cs
- PreservationFileWriter.cs
- ToolStripDropDownItem.cs
- ColorMap.cs
- ExeContext.cs
- BindingExpression.cs
- FreeFormDragDropManager.cs
- CodeNamespace.cs
- PathSegment.cs
- OpCodes.cs
- QilCloneVisitor.cs
- GlyphingCache.cs
- _DigestClient.cs
- DataBindingExpressionBuilder.cs
- XmlMessageFormatter.cs
- XpsSerializationManagerAsync.cs
- TransformGroup.cs
- ListParagraph.cs
- CookieProtection.cs
- FlagsAttribute.cs
- DateTime.cs
- TextComposition.cs
- TextWriter.cs
- RawMouseInputReport.cs
- XMLSchema.cs
- DeferredSelectedIndexReference.cs
- SmtpMail.cs
- Handle.cs
- FilteredAttributeCollection.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- xdrvalidator.cs
- SchemaSetCompiler.cs
- State.cs
- ConstructorExpr.cs
- CompareValidator.cs
- SafeSecurityHelper.cs
- TextSimpleMarkerProperties.cs
- BaseComponentEditor.cs
- FormViewPagerRow.cs
- PerformanceCounterLib.cs
- PlaceHolder.cs
- FontClient.cs
- CopyAction.cs
- SplashScreenNativeMethods.cs
- SQLBinary.cs
- TransformValueSerializer.cs
- ConfigWriter.cs