コード例 #1
0
        private string GetUrlForCdn(ScriptManager scriptManager, string resourceName, Assembly assembly, bool hasDebugResource)
        {
            // if EnableCdn, then url always comes from mapping.Cdn[Debug]Path or WRA.CdnPath, if available.
            // first see if the script description mapping has a cdn path defined
            bool isDebuggingEnabled = IsDebuggingEnabled(scriptManager);
            bool isAssemblyResource = !String.IsNullOrEmpty(resourceName);
            bool secureConnection   = scriptManager.IsSecureConnection;

            isDebuggingEnabled = isDebuggingEnabled && (hasDebugResource || !isAssemblyResource);
            string cdnPath = isDebuggingEnabled ?
                             (secureConnection ? ScriptInfo.CdnDebugPathSecureConnection : ScriptInfo.CdnDebugPath) :
                             (secureConnection ? ScriptInfo.CdnPathSecureConnection : ScriptInfo.CdnPath);

            // then see if the WebResourceAttribute for the resource has one
            // EXCEPT when the ScriptInfo has a cdnpath but it wasn't selected due to this being a secure connection
            // and it does not support secure connections. Avoid having the HTTP cdn path come from the mapping and the
            // HTTPS path come from the WRA.
            if (isAssemblyResource && String.IsNullOrEmpty(cdnPath) && String.IsNullOrEmpty(isDebuggingEnabled ? ScriptInfo.CdnDebugPath : ScriptInfo.CdnPath))
            {
                ScriptResourceInfo scriptResourceInfo = ScriptResourceInfo.GetInstance(assembly, resourceName);
                if (scriptResourceInfo != null)
                {
                    cdnPath = secureConnection ? scriptResourceInfo.CdnPathSecureConnection : scriptResourceInfo.CdnPath;
                }
            }
            return(String.IsNullOrEmpty(cdnPath) ? null : ClientUrlResolver.ResolveClientUrl(AddCultureName(scriptManager, cdnPath)));
        }
コード例 #2
0
            public ScriptEffectiveInfo(ScriptReference scriptReference)
            {
                ScriptResourceDefinition definition =
                    ScriptManager.ScriptResourceMapping.GetDefinition(scriptReference);
                string   name     = scriptReference.Name;
                string   path     = scriptReference.Path;
                Assembly assembly = scriptReference.GetAssembly();

                if (definition != null)
                {
                    if (String.IsNullOrEmpty(path))
                    {
                        // only when the SR has no path, the mapping's path and debug path, if any, apply
                        path       = definition.Path;
                        _debugPath = definition.DebugPath;
                    }
                    name                          = definition.ResourceName;
                    assembly                      = definition.ResourceAssembly;
                    _cdnPath                      = definition.CdnPath;
                    _cdnDebugPath                 = definition.CdnDebugPath;
                    _cdnPathSecureConnection      = definition.CdnPathSecureConnection;
                    _cdnDebugPathSecureConnection = definition.CdnDebugPathSecureConnection;
                    LoadSuccessExpression         = definition.LoadSuccessExpression;
                }
                else if ((assembly == null) && !String.IsNullOrEmpty(name))
                {
                    // name is set and there is no mapping, default to SWE for assembly
                    assembly = AssemblyCache.SystemWebExtensions;
                }
                _resourceName = name;
                _assembly     = assembly;
                _path         = path;

                if (assembly != null && !String.IsNullOrEmpty(name) && String.IsNullOrEmpty(LoadSuccessExpression))
                {
                    var scriptResourceInfo = ScriptResourceInfo.GetInstance(assembly, name);
                    if (scriptResourceInfo != null)
                    {
                        LoadSuccessExpression = scriptResourceInfo.LoadSuccessExpression;
                    }
                }
            }
コード例 #3
0
        internal static string GetScriptFromWebResourceInternal(
            Assembly assembly, string resourceName, CultureInfo culture,
            bool zip, out string contentType)
        {
            ScriptResourceInfo resourceInfo        = ScriptResourceInfo.GetInstance(assembly, resourceName);
            ScriptResourceInfo releaseResourceInfo = null;

            if (resourceName.EndsWith(".debug.js", StringComparison.OrdinalIgnoreCase))
            {
                // This is a debug script, we'll need to merge the debug resource
                // with the release one.
                string releaseResourceName = resourceName.Substring(0, resourceName.Length - 9) + ".js";
                releaseResourceInfo = ScriptResourceInfo.GetInstance(assembly, releaseResourceName);
            }
            if ((resourceInfo == ScriptResourceInfo.Empty) &&
                ((releaseResourceInfo == null) || (releaseResourceInfo == ScriptResourceInfo.Empty)))
            {
                throw new HttpException(AtlasWeb.ScriptResourceHandler_InvalidRequest);
            }

            ResourceManager resourceManager        = null;
            ResourceSet     neutralSet             = null;
            ResourceManager releaseResourceManager = null;
            ResourceSet     releaseNeutralSet      = null;
            CultureInfo     previousCulture        = Thread.CurrentThread.CurrentUICulture;

            try {
                Thread.CurrentThread.CurrentUICulture = culture;

                if (!String.IsNullOrEmpty(resourceInfo.ScriptResourceName))
                {
                    resourceManager = GetResourceManager(resourceInfo.ScriptResourceName, assembly);
                    // The following may throw MissingManifestResourceException
                    neutralSet = resourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, true);
                }
                if ((releaseResourceInfo != null) &&
                    !String.IsNullOrEmpty(releaseResourceInfo.ScriptResourceName))
                {
                    releaseResourceManager = GetResourceManager(releaseResourceInfo.ScriptResourceName, assembly);
                    releaseNeutralSet      = releaseResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, true);
                }
                if ((releaseResourceInfo != null) &&
                    !String.IsNullOrEmpty(releaseResourceInfo.ScriptResourceName) &&
                    !String.IsNullOrEmpty(resourceInfo.ScriptResourceName) &&
                    (releaseResourceInfo.TypeName != resourceInfo.TypeName))
                {
                    throw new HttpException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                AtlasWeb.ScriptResourceHandler_TypeNameMismatch,
                                                releaseResourceInfo.ScriptResourceName));
                }

                StringBuilder builder = new StringBuilder();
                WriteScript(assembly,
                            resourceInfo, releaseResourceInfo,
                            resourceManager, neutralSet,
                            releaseResourceManager, releaseNeutralSet,
                            zip, builder);
                contentType = resourceInfo.ContentType;
                return(builder.ToString());
            }
            finally {
                Thread.CurrentThread.CurrentUICulture = previousCulture;

                if (releaseNeutralSet != null)
                {
                    releaseNeutralSet.Dispose();
                }
                if (neutralSet != null)
                {
                    neutralSet.Dispose();
                }
            }
        }