Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Extensions / UI / CompositeScriptReference.cs / 1305376 / CompositeScriptReference.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Drawing.Design;
using System.Globalization;
using System.Reflection;
using System.Web.Handlers;
using System.Web.Resources;
using System.Web.Util;
[
DefaultProperty("Path"),
TypeConverter(typeof(EmptyStringExpandableObjectConverter))
]
public class CompositeScriptReference : ScriptReferenceBase {
private ScriptReferenceCollection _scripts;
[
ResourceDescription("CompositeScriptReference_Scripts"),
Category("Behavior"),
Editor("System.Web.UI.Design.CollectionEditorBase, " +
AssemblyRef.SystemWebExtensionsDesign, typeof(UITypeEditor)),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
NotifyParentProperty(true),
MergableProperty(false),
]
public ScriptReferenceCollection Scripts {
get {
if (_scripts == null) {
_scripts = new ScriptReferenceCollection();
}
return _scripts;
}
}
[SuppressMessage("Microsoft.Design", "CA1055", Justification = "Consistent with other URL properties in ASP.NET.")]
protected internal override string GetUrl(ScriptManager scriptManager, bool zip) {
bool isDebuggingEnabled = !scriptManager.DeploymentSectionRetail &&
((ScriptMode == ScriptMode.Debug) ||
(((ScriptMode == ScriptMode.Inherit) || (ScriptMode == ScriptMode.Auto)) &&
(scriptManager.IsDebuggingEnabled)));
if (!String.IsNullOrEmpty(Path)) {
string path = Path;
if (isDebuggingEnabled) {
path = GetDebugPath(path);
}
if (scriptManager.EnableScriptLocalization &&
(ResourceUICultures != null) && (ResourceUICultures.Length != 0)) {
CultureInfo currentCulture = CultureInfo.CurrentUICulture;
string cultureName = null;
bool found = false;
while (!currentCulture.Equals(CultureInfo.InvariantCulture)) {
cultureName = currentCulture.ToString();
foreach (string uiCulture in ResourceUICultures) {
if (String.Equals(cultureName, uiCulture.Trim(), StringComparison.OrdinalIgnoreCase)) {
found = true;
break;
}
}
if (found) break;
currentCulture = currentCulture.Parent;
}
if (found) {
path = (path.Substring(0, path.Length - 2) + cultureName + ".js");
}
}
// ResolveClientUrl is appropriate here because the path is consumed by the page it was declared within
return ClientUrlResolver.ResolveClientUrl(path);
}
List>>> resources =
new List>>>();
Pair>> resourceList = null;
foreach (ScriptReference reference in Scripts) {
if ((scriptManager.AjaxFrameworkMode == AjaxFrameworkMode.Explicit) &&
reference.IsAjaxFrameworkScript(scriptManager) &&
reference.EffectiveResourceName.StartsWith("MicrosoftAjax.", StringComparison.Ordinal)) {
continue;
}
bool hasPath = !String.IsNullOrEmpty(reference.EffectivePath);
#pragma warning disable 618
// ScriptPath is obsolete but still functional
bool hasScriptPath = (!String.IsNullOrEmpty(scriptManager.ScriptPath) && !reference.IgnoreScriptPath);
#pragma warning restore 618
// cacheAssembly will be null if ScriptPath is set, but we still need the resource assembly in that case
Assembly resourceAssembly = null;
string resourceName = null;
Assembly cacheAssembly = null;
ScriptMode effectiveScriptModeForReference = reference.EffectiveScriptMode;
bool isDebuggingEnabledForReference =
(effectiveScriptModeForReference == ScriptMode.Inherit) ?
isDebuggingEnabled :
(effectiveScriptModeForReference == ScriptMode.Debug);
if (!hasPath) {
resourceAssembly = reference.GetAssembly(scriptManager);
resourceName = reference.EffectiveResourceName;
reference.DetermineResourceNameAndAssembly(scriptManager, isDebuggingEnabledForReference,
ref resourceName, ref resourceAssembly);
if ((resourceAssembly != scriptManager.AjaxFrameworkAssembly) &&
(resourceAssembly != AssemblyCache.SystemWebExtensions) &&
AssemblyCache.IsAjaxFrameworkAssembly(resourceAssembly)) {
// if it is coming from an assembly that is not the current ajax script assembly, make sure the assembly
// is not meant to be an ajax script assembly.
// it isnt an AjaxFrameworkScript but it might be from an assembly that is meant to
// be an ajax script assembly, in which case we should throw an error.
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
AtlasWeb.ScriptReference_ResourceRequiresAjaxAssembly, resourceName, resourceAssembly));
}
if (!hasScriptPath) {
// The resource requested in the composite url will only contain the assembly name if it
// will ultimately come from the assembly -- if ScriptPath is set, it doesn't.
// We do still need to know the resource assembly in that case though, hence the separate
// assembly variables.
cacheAssembly = resourceAssembly;
}
}
CultureInfo culture = reference.DetermineCulture(scriptManager);
if ((resourceList == null) || (resourceList.First != cacheAssembly)) {
resourceList = new Pair>>(
cacheAssembly, new List>());
resources.Add(resourceList);
}
if (hasPath || hasScriptPath) {
if (hasPath) {
if (String.IsNullOrEmpty(reference.Path)) {
// the Path is coming from a script mapping, so its debug path applies
resourceName = reference.GetPath(scriptManager, reference.EffectivePath, reference.ScriptInfo.DebugPath,
isDebuggingEnabledForReference);
}
else {
// path explicitly set, even if a mapping has a DebugPath it does not apply
resourceName = reference.GetPath(scriptManager, reference.Path, null,
isDebuggingEnabledForReference);
}
}
else {
#pragma warning disable 618
// ScriptPath is obsolete but still functional
resourceName = ScriptReference.GetScriptPath(resourceName, resourceAssembly,
culture, scriptManager.ScriptPath);
#pragma warning restore 618
}
// ResolveClientUrl not appropriate here because the handler that will serve the response is not
// in the same directory as the page that is generating the url. Instead, an absolute url is needed
// as with ResolveUrl(). However, ResolveUrl() would prepend the entire application root name. For
// example, ~/foo.js would be /TheApplicationRoot/foo.js. If there are many path based scripts the
// app root would be repeated many times, which for deep apps or long named apps could cause the url
// to reach the maximum 2048 characters very quickly. So, the path is combined with the control's
// AppRelativeTemplateSourceDirectory manually, so that ~/foo.js remains ~/foo.js, and foo/bar.js
// becomes ~/templatesource/foo/bar.js. Absolute paths can remain as is. The ScriptResourceHandler will
// resolve the ~/ with the app root using VirtualPathUtility.ToAbsolute().
if (UrlPath.IsRelativeUrl(resourceName) && !UrlPath.IsAppRelativePath(resourceName)) {
resourceName = UrlPath.Combine(ClientUrlResolver.AppRelativeTemplateSourceDirectory, resourceName);
}
}
resourceList.Second.Add(new Pair(resourceName, culture));
}
return ScriptResourceHandler.GetScriptResourceUrl(resources, zip);
}
[Obsolete("Use IsAjaxFrameworkScript(ScriptManager)")]
protected internal override bool IsFromSystemWebExtensions() {
foreach (ScriptReference script in Scripts) {
if (script.EffectiveAssembly == AssemblyCache.SystemWebExtensions) {
return true;
}
}
return false;
}
protected internal override bool IsAjaxFrameworkScript(ScriptManager scriptManager) {
foreach (ScriptReference script in Scripts) {
if (script.IsAjaxFrameworkScript(scriptManager)) {
return true;
}
}
return false;
}
}
}
// 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.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Drawing.Design;
using System.Globalization;
using System.Reflection;
using System.Web.Handlers;
using System.Web.Resources;
using System.Web.Util;
[
DefaultProperty("Path"),
TypeConverter(typeof(EmptyStringExpandableObjectConverter))
]
public class CompositeScriptReference : ScriptReferenceBase {
private ScriptReferenceCollection _scripts;
[
ResourceDescription("CompositeScriptReference_Scripts"),
Category("Behavior"),
Editor("System.Web.UI.Design.CollectionEditorBase, " +
AssemblyRef.SystemWebExtensionsDesign, typeof(UITypeEditor)),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
NotifyParentProperty(true),
MergableProperty(false),
]
public ScriptReferenceCollection Scripts {
get {
if (_scripts == null) {
_scripts = new ScriptReferenceCollection();
}
return _scripts;
}
}
[SuppressMessage("Microsoft.Design", "CA1055", Justification = "Consistent with other URL properties in ASP.NET.")]
protected internal override string GetUrl(ScriptManager scriptManager, bool zip) {
bool isDebuggingEnabled = !scriptManager.DeploymentSectionRetail &&
((ScriptMode == ScriptMode.Debug) ||
(((ScriptMode == ScriptMode.Inherit) || (ScriptMode == ScriptMode.Auto)) &&
(scriptManager.IsDebuggingEnabled)));
if (!String.IsNullOrEmpty(Path)) {
string path = Path;
if (isDebuggingEnabled) {
path = GetDebugPath(path);
}
if (scriptManager.EnableScriptLocalization &&
(ResourceUICultures != null) && (ResourceUICultures.Length != 0)) {
CultureInfo currentCulture = CultureInfo.CurrentUICulture;
string cultureName = null;
bool found = false;
while (!currentCulture.Equals(CultureInfo.InvariantCulture)) {
cultureName = currentCulture.ToString();
foreach (string uiCulture in ResourceUICultures) {
if (String.Equals(cultureName, uiCulture.Trim(), StringComparison.OrdinalIgnoreCase)) {
found = true;
break;
}
}
if (found) break;
currentCulture = currentCulture.Parent;
}
if (found) {
path = (path.Substring(0, path.Length - 2) + cultureName + ".js");
}
}
// ResolveClientUrl is appropriate here because the path is consumed by the page it was declared within
return ClientUrlResolver.ResolveClientUrl(path);
}
List>>> resources =
new List>>>();
Pair>> resourceList = null;
foreach (ScriptReference reference in Scripts) {
if ((scriptManager.AjaxFrameworkMode == AjaxFrameworkMode.Explicit) &&
reference.IsAjaxFrameworkScript(scriptManager) &&
reference.EffectiveResourceName.StartsWith("MicrosoftAjax.", StringComparison.Ordinal)) {
continue;
}
bool hasPath = !String.IsNullOrEmpty(reference.EffectivePath);
#pragma warning disable 618
// ScriptPath is obsolete but still functional
bool hasScriptPath = (!String.IsNullOrEmpty(scriptManager.ScriptPath) && !reference.IgnoreScriptPath);
#pragma warning restore 618
// cacheAssembly will be null if ScriptPath is set, but we still need the resource assembly in that case
Assembly resourceAssembly = null;
string resourceName = null;
Assembly cacheAssembly = null;
ScriptMode effectiveScriptModeForReference = reference.EffectiveScriptMode;
bool isDebuggingEnabledForReference =
(effectiveScriptModeForReference == ScriptMode.Inherit) ?
isDebuggingEnabled :
(effectiveScriptModeForReference == ScriptMode.Debug);
if (!hasPath) {
resourceAssembly = reference.GetAssembly(scriptManager);
resourceName = reference.EffectiveResourceName;
reference.DetermineResourceNameAndAssembly(scriptManager, isDebuggingEnabledForReference,
ref resourceName, ref resourceAssembly);
if ((resourceAssembly != scriptManager.AjaxFrameworkAssembly) &&
(resourceAssembly != AssemblyCache.SystemWebExtensions) &&
AssemblyCache.IsAjaxFrameworkAssembly(resourceAssembly)) {
// if it is coming from an assembly that is not the current ajax script assembly, make sure the assembly
// is not meant to be an ajax script assembly.
// it isnt an AjaxFrameworkScript but it might be from an assembly that is meant to
// be an ajax script assembly, in which case we should throw an error.
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture,
AtlasWeb.ScriptReference_ResourceRequiresAjaxAssembly, resourceName, resourceAssembly));
}
if (!hasScriptPath) {
// The resource requested in the composite url will only contain the assembly name if it
// will ultimately come from the assembly -- if ScriptPath is set, it doesn't.
// We do still need to know the resource assembly in that case though, hence the separate
// assembly variables.
cacheAssembly = resourceAssembly;
}
}
CultureInfo culture = reference.DetermineCulture(scriptManager);
if ((resourceList == null) || (resourceList.First != cacheAssembly)) {
resourceList = new Pair>>(
cacheAssembly, new List>());
resources.Add(resourceList);
}
if (hasPath || hasScriptPath) {
if (hasPath) {
if (String.IsNullOrEmpty(reference.Path)) {
// the Path is coming from a script mapping, so its debug path applies
resourceName = reference.GetPath(scriptManager, reference.EffectivePath, reference.ScriptInfo.DebugPath,
isDebuggingEnabledForReference);
}
else {
// path explicitly set, even if a mapping has a DebugPath it does not apply
resourceName = reference.GetPath(scriptManager, reference.Path, null,
isDebuggingEnabledForReference);
}
}
else {
#pragma warning disable 618
// ScriptPath is obsolete but still functional
resourceName = ScriptReference.GetScriptPath(resourceName, resourceAssembly,
culture, scriptManager.ScriptPath);
#pragma warning restore 618
}
// ResolveClientUrl not appropriate here because the handler that will serve the response is not
// in the same directory as the page that is generating the url. Instead, an absolute url is needed
// as with ResolveUrl(). However, ResolveUrl() would prepend the entire application root name. For
// example, ~/foo.js would be /TheApplicationRoot/foo.js. If there are many path based scripts the
// app root would be repeated many times, which for deep apps or long named apps could cause the url
// to reach the maximum 2048 characters very quickly. So, the path is combined with the control's
// AppRelativeTemplateSourceDirectory manually, so that ~/foo.js remains ~/foo.js, and foo/bar.js
// becomes ~/templatesource/foo/bar.js. Absolute paths can remain as is. The ScriptResourceHandler will
// resolve the ~/ with the app root using VirtualPathUtility.ToAbsolute().
if (UrlPath.IsRelativeUrl(resourceName) && !UrlPath.IsAppRelativePath(resourceName)) {
resourceName = UrlPath.Combine(ClientUrlResolver.AppRelativeTemplateSourceDirectory, resourceName);
}
}
resourceList.Second.Add(new Pair(resourceName, culture));
}
return ScriptResourceHandler.GetScriptResourceUrl(resources, zip);
}
[Obsolete("Use IsAjaxFrameworkScript(ScriptManager)")]
protected internal override bool IsFromSystemWebExtensions() {
foreach (ScriptReference script in Scripts) {
if (script.EffectiveAssembly == AssemblyCache.SystemWebExtensions) {
return true;
}
}
return false;
}
protected internal override bool IsAjaxFrameworkScript(ScriptManager scriptManager) {
foreach (ScriptReference script in Scripts) {
if (script.IsAjaxFrameworkScript(scriptManager)) {
return true;
}
}
return false;
}
}
}
// 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
- ChildDocumentBlock.cs
- TypeHelpers.cs
- Point.cs
- TextBreakpoint.cs
- RuleInfoComparer.cs
- TextInfo.cs
- DomainUpDown.cs
- RootBrowserWindow.cs
- Ops.cs
- EventProperty.cs
- SolidColorBrush.cs
- TreeNodeStyle.cs
- SystemIPGlobalStatistics.cs
- AnnotationAdorner.cs
- PkcsMisc.cs
- ErrorActivity.cs
- ArrangedElement.cs
- ResourceKey.cs
- CodeCompileUnit.cs
- ListArgumentProvider.cs
- WindowAutomationPeer.cs
- SoapHeaderAttribute.cs
- arclist.cs
- RepeatBehavior.cs
- Duration.cs
- MultiViewDesigner.cs
- FontStyle.cs
- PolygonHotSpot.cs
- RequestQueue.cs
- DrawToolTipEventArgs.cs
- SQLInt32Storage.cs
- RegexWorker.cs
- SqlProcedureAttribute.cs
- ControlBindingsCollection.cs
- TypefaceMetricsCache.cs
- ToolboxCategoryItems.cs
- ContainerVisual.cs
- SemaphoreFullException.cs
- DirectoryNotFoundException.cs
- EntityDataSourceWrapper.cs
- Renderer.cs
- FrameworkTextComposition.cs
- DataRecordInternal.cs
- ParameterReplacerVisitor.cs
- Socket.cs
- EventArgs.cs
- ControlEvent.cs
- IndentedTextWriter.cs
- StyleCollectionEditor.cs
- Mapping.cs
- AnnotationComponentManager.cs
- NotifyCollectionChangedEventArgs.cs
- AutoResizedEvent.cs
- PageAdapter.cs
- LicenseProviderAttribute.cs
- MemberRelationshipService.cs
- ZipArchive.cs
- MarkupCompilePass2.cs
- DataGridColumn.cs
- DataSourceXmlTextReader.cs
- StringFunctions.cs
- ValidationHelpers.cs
- CounterSample.cs
- StorageModelBuildProvider.cs
- DataStreamFromComStream.cs
- PerfCounters.cs
- HtmlInputHidden.cs
- IgnoreSectionHandler.cs
- EndEvent.cs
- Quaternion.cs
- serverconfig.cs
- SRGSCompiler.cs
- SchemaSetCompiler.cs
- Vector3D.cs
- RoutedCommand.cs
- ObjectAnimationUsingKeyFrames.cs
- VectorConverter.cs
- PointKeyFrameCollection.cs
- RedirectionProxy.cs
- DesignerCommandSet.cs
- GridViewUpdateEventArgs.cs
- SqlRewriteScalarSubqueries.cs
- SQLInt64.cs
- WindowsListViewScroll.cs
- GridPattern.cs
- PrintPreviewControl.cs
- ListBindingConverter.cs
- Relationship.cs
- Rotation3DAnimationUsingKeyFrames.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- ExpressionCopier.cs
- SelectionPattern.cs
- DockAndAnchorLayout.cs
- StorageFunctionMapping.cs
- DragAssistanceManager.cs
- Function.cs
- MgmtConfigurationRecord.cs
- NullableLongMinMaxAggregationOperator.cs
- TreeNodeConverter.cs
- SslStream.cs