コード例 #1
0
ファイル: Main.master.cs プロジェクト: mehedi09/GridWork
 protected void sm_ResolveScriptReference(object sender, ScriptReferenceEventArgs e)
 {
     if (System.Array.IndexOf(MicrosoftJavaScript, e.Script.Name) >= 0)
     {
         if (AquariumExtenderBase.EnableCombinedScript)
         {
             string lang = CultureInfo.CurrentUICulture.IetfLanguageTag.ToLower();
             string scriptPath = ResolveUrl(String.Format("~/appservices/combined-{0}.{1}.js", ApplicationServices.Version, lang));
             if (ApplicationServices.IsTouchClient)
                 scriptPath = String.Format("{0}?_touch", scriptPath);
             e.Script.Path = scriptPath;
             e.Script.ResourceUICultures = null;
             return;
         }
         e.Script.Name = ("MyCompany.Scripts." + e.Script.Name);
         e.Script.Assembly = typeof(AquariumExtenderBase).Assembly.FullName;
     }
 }
コード例 #2
0
		/// <summary>
		/// Checks if script reference contains already loaded script link and replaces
		/// it with empty script.
		/// </summary>
		/// <param name="e">A <see cref="ScriptReferenceEventArgs" /> that contains event data.</param>
		protected override void OnResolveScriptReference(ScriptReferenceEventArgs e)
		{
			base.OnResolveScriptReference(e);

			if (IsInAsyncPostBack) ProcessLoadedScripts(e.Script);
		}
コード例 #3
0
        protected override void OnResolveScriptReference(ScriptReferenceEventArgs e)
        {
            try
            {
                base.OnResolveScriptReference(e);

                #region Profiling scripts
                if (OptimizerConfig.EnableProfiler)
                {
                    bool isFound = false;
                    foreach (ScriptReference reference in _profilerScripts)
                    {
                        if (reference.Assembly == e.Script.Assembly && reference.Name == e.Script.Name && reference.Path == e.Script.Path)
                        {
                            isFound = true;
                            break;
                        }
                    }
                    if (!isFound)
                    {
                        ScriptReference objScrRef = new ScriptReference(e.Script.Name, e.Script.Assembly);
                        if (!string.IsNullOrEmpty(e.Script.Name) && string.IsNullOrEmpty(e.Script.Assembly))
                        {
                            //TODO: if resource belongs to System.Web.Extensions.dll, it does not provide assembly info that's why hard-coded assembly name is written to get it in profiler
                            objScrRef.Assembly = "System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
                        }
                        objScrRef.Path = e.Script.Path;
                        objScrRef.IgnoreScriptPath = e.Script.IgnoreScriptPath;
                        objScrRef.NotifyScriptLoaded = e.Script.NotifyScriptLoaded;
                        objScrRef.ResourceUICultures = e.Script.ResourceUICultures;
                        objScrRef.ScriptMode = e.Script.ScriptMode;
                        _profilerScripts.Add(objScrRef);
                        objScrRef = null;
                    }
                }
                #endregion

                #region Combining Client Scripts

                bool isAssemblyBased = ((e.Script.Assembly.Length > 0) ? true : false);
                bool isPathBased = ((e.Script.Path.Length > 0) ? true : false);
                bool isNameBased = ((e.Script.Path.Length == 0 && e.Script.Assembly.Length == 0 && e.Script.Name.Length > 0) ? true : false);

                if (OptimizerConfig.Enable && (isAssemblyBased || isPathBased || isNameBased))
                {
                    ScriptElement element = null;
                    try
                    {
                        if (isAssemblyBased)
                            element = OptimizerConfig.GetScriptByResource(e.Script.Name, e.Script.Assembly);
                        else if (isPathBased)
                        {
                            element = OptimizerConfig.GetScriptByPath(e.Script.Path);
                            if (null != element)
                            {
                                if (!OptimizerHelper.IsValidExtension(element, ".js"))
                                {
                                    element = null;
                                }
                                else if (!OptimizerHelper.IsAbsolutePathExists(element))
                                {
                                    string absolutePath = OptimizerHelper.GetAbsolutePath(element);
                                    element = null;
                                }
                            }
                        }
                        else if (isNameBased)
                            element = OptimizerConfig.GetScriptByName(e.Script.Name);
                    }
                    catch (Exception exc)
                    {
                        element = null;
                    }

                    if (element != null)
                    {
                        if (!_scriptContents.ContainsKey(element.Key))
                        {
                            _scriptContents.Add(element.Key, element.GetContents());
                        }
                        if (!_scripts.ContainsKey(element.Key))
                        {
                            try
                            {
                                _scripts.Add(element.Key, e.Script);
                                e.Script.Assembly = string.Empty;
                                e.Script.Name = string.Empty;

                                StringBuilder objStrBuilder = new StringBuilder();
                                objStrBuilder.Append(HANDLER_PATH);

                                foreach (KeyValuePair<string, ScriptReference> script in _scripts)
                                {
                                    objStrBuilder.Append(script.Key + ".");
                                }
                                string strPath = objStrBuilder.ToString();
                                objStrBuilder = null;

                                foreach (KeyValuePair<string, ScriptReference> script in _scripts)
                                {
                                    script.Value.Path = strPath;
                                }
                            }
                            catch { }
                        }
                        else
                        {
                            e.Script.Assembly = string.Empty;
                            e.Script.Name = string.Empty;
                            e.Script.Path = BLOCKED_HANDLER_PATH;
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                this.Page.Response.Write(ex.ToString().Replace("\n", "<br>"));
            }
        }
コード例 #4
0
ファイル: ToolkitScriptManager.cs プロジェクト: madmed/netron
        protected override void OnResolveScriptReference(ScriptReferenceEventArgs e)
        {
            base.OnResolveScriptReference(e);

            // If combining scripts and this is a candidate script
            if (_combineScripts && !String.IsNullOrEmpty(e.Script.Assembly) && !String.IsNullOrEmpty(e.Script.Name))
            {
                // Initialize
                ScriptReference scriptReference = e.Script;
                ScriptEntry scriptEntry = new ScriptEntry(scriptReference);

                if (IsScriptCombinable(scriptEntry))
                {
                    if (!_scriptEntries.Contains(scriptEntry))
                    {
                        // Haven't seen this script yet; add it to the list and invalidate the Url
                        _scriptEntries.Add(scriptEntry);
                        _combinedScriptUrl = null;
                    }

                    if (null == _combinedScriptUrl)
                    {
                        // Url is invalid; update it
                        _combinedScriptUrl = String.Format(CultureInfo.InvariantCulture, "{0}?{1}={2}&{3}={4}", ((null != _combineScriptsHandlerUrl) ? _combineScriptsHandlerUrl.ToString() : Page.Request.Path), HiddenFieldParamName, HiddenFieldName, CombinedScriptsParamName, HttpUtility.UrlEncode(SerializeScriptEntries(_scriptEntries, false)));
                    }

                    // Remove the script from the list and track it
                    scriptReference.Name = "";
                    scriptReference.Assembly = "";
                    _disabledScriptReferences.Add(scriptReference);

                    // Update the common (combined) Url for all tracked scripts
                    foreach (ScriptReference disabledScriptReference in _disabledScriptReferences)
                    {
                        disabledScriptReference.Path = _combinedScriptUrl;
                    }
                }
                else
                {
                    // See if we've already seen this uncombinable script reference
                    bool alreadySeen = false;
                    foreach (ScriptReference uncombinableScriptReference in _uncombinableScriptReferences)
                    {
                        if ((uncombinableScriptReference.Assembly == scriptReference.Assembly) && (uncombinableScriptReference.Name == scriptReference.Name))
                        {
                            alreadySeen = true;
                        }
                    }
                    if (!alreadySeen)
                    {
                        // Haven't seen the script reference yet, so we need to stop building the current combined script
                        // file and let the uncombinable script reference be output so as not to alter the ordering of
                        // scripts (which may have dependencies). Update our state so we'll start building a new combined
                        // script file with the next combinable script.
                        // Note: _combinedScriptUrl was initially cleared here. While that's correct behavior (and was
                        // released without issue), not clearing it means that we can omit an unnecessary <script> tag
                        // for the scenario "CombinableA, Uncombinable?, CombinableA, Uncombinable?" because the second
                        // instance of CombinableA will reuse the URL from the first (vs. an empty one) and ScriptManager
                        // will detect and omit the redundant URL.
                        _uncombinableScriptReferences.Add(scriptReference);
                        _disabledScriptReferences.Clear();
                        foreach (ScriptEntry se in _scriptEntries)
                        {
                            se.Loaded = true;
                        }
                    }
                }
            }
        }
コード例 #5
0
 private void ResolveScriptReferenceHandler(object sender, ScriptReferenceEventArgs e) {
     var clonedReference = string.IsNullOrEmpty(e.Script.Path) ?
         new ScriptReference(e.Script.Name, e.Script.Assembly) :
         new ScriptReference(e.Script.Path);
     clonedReference.IgnoreScriptPath = e.Script.IgnoreScriptPath;
     clonedReference.ResourceUICultures = e.Script.ResourceUICultures;
     clonedReference.ScriptMode = ScriptMode.Auto;
     _references.Add(clonedReference);
 }