コード例 #1
0
        public static void AddScriptReference(this AjaxHelper ajaxHelper, string scriptName, ScriptMode scriptMode)
        {
            ScriptModel scriptModel = GetScriptModel(ajaxHelper);

            if (String.IsNullOrEmpty(scriptName))
            {
                throw new ArgumentNullException("scriptName");
            }

            ScriptSharpSection configSection = ScriptSharpSection.GetSettings();
            ScriptElement      scriptElement = configSection.Scripts.GetElement(scriptName, scriptModel.ScriptFlavor);
            string             actualFlavor  = String.Empty;

            int flavorIndex = scriptElement.Name.IndexOf('.');

            if (flavorIndex > 0)
            {
                actualFlavor = scriptElement.Name.Substring(flavorIndex + 1);
            }

            ScriptReference scriptReference =
                new ScriptReference(scriptName, scriptElement.Url, scriptMode,
                                    scriptElement.GetDependencyList(), scriptElement.Version + actualFlavor);

            scriptModel.AddScriptReference(scriptReference);
        }
コード例 #2
0
        public void IncludeDependencies(ScriptCollection configuredScripts)
        {
            HashSet <string> referenceSet = new HashSet <string>();
            Queue <string>   dependencies = new Queue <string>();

            foreach (ScriptReference reference in _references)
            {
                referenceSet.Add(reference.Name);
                if (reference.Dependencies != null)
                {
                    foreach (string dependency in reference.Dependencies)
                    {
                        dependencies.Enqueue(dependency);
                    }
                }
            }

            if (_scriptBlocks != null)
            {
                foreach (ScriptBlock scriptBlock in _scriptBlocks)
                {
                    if (scriptBlock.Dependencies != null)
                    {
                        foreach (string dependency in scriptBlock.Dependencies)
                        {
                            dependencies.Enqueue(dependency);
                        }
                    }
                }
            }

            while (dependencies.Count != 0)
            {
                string name = dependencies.Dequeue();
                if (referenceSet.Contains(name))
                {
                    continue;
                }

                ScriptElement scriptElement        = configuredScripts.GetElement(name, _scriptFlavor);
                string[]      implicitDependencies = scriptElement.GetDependencyList();

                ScriptReference scriptReference =
                    new ScriptReference(name, scriptElement.Url, ScriptMode.OnDemand, implicitDependencies,
                                        scriptElement.Version);
                AddScriptReference(scriptReference);

                referenceSet.Add(name);

                if (implicitDependencies != null)
                {
                    foreach (string implicitDependency in implicitDependencies)
                    {
                        if (referenceSet.Contains(implicitDependency) == false)
                        {
                            dependencies.Enqueue(implicitDependency);
                        }
                    }
                }
            }
        }