Beispiel #1
0
 public void AddRuntimeScripts(CombinableScripts script)
 {
     if (script != null && this.scriptBuckets.GetScriptByAlias(script.Alias, false) == null)
     {
         this.scriptBuckets.InitializeRuntimeScript(script);
     }
 }
Beispiel #2
0
        public static void ExpandAndSort(IList <ScriptReference> scriptReferences)
        {
            List <ScriptReference>   list  = new List <ScriptReference>(scriptReferences.Count);
            List <CombinableScripts> list2 = new List <CombinableScripts>();
            Hashtable hashtable            = new Hashtable(StringComparer.OrdinalIgnoreCase);

            foreach (ScriptReference scriptReference in scriptReferences)
            {
                CombinableScripts scriptByName = ToolkitScriptManager.CacheScriptBuckets.GetScriptByName(scriptReference.Name);
                if (scriptByName != null)
                {
                    if (hashtable[scriptByName.Alias] == null)
                    {
                        list2.Add(scriptByName);
                        hashtable[scriptByName.Alias] = true;
                        if (scriptByName.DependsOn != null && scriptByName.DependsOn.Length > 0)
                        {
                            Stack stack = new Stack(scriptByName.DependsOn);
                            while (stack.Count > 0)
                            {
                                string text = (string)stack.Pop();
                                if (hashtable[text] == null)
                                {
                                    CombinableScripts scriptByAlias = ToolkitScriptManager.CacheScriptBuckets.GetScriptByAlias(text, true);
                                    list2.Add(scriptByAlias);
                                    hashtable[text] = true;
                                    if (scriptByAlias.DependsOn != null && scriptByAlias.DependsOn.Length > 0)
                                    {
                                        for (int i = 0; i < scriptByAlias.DependsOn.Length; i++)
                                        {
                                            stack.Push(scriptByAlias.DependsOn[i]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    list.Add(scriptReference);
                }
            }
            if (list2.Count > 0)
            {
                list2.Sort((CombinableScripts left, CombinableScripts right) => right.Rank - left.Rank);
                list.AddRange(from x in list2
                              select x.ToScriptReference());
            }
            if (scriptReferences.Count > 1 || scriptReferences.Count != list.Count)
            {
                scriptReferences.Clear();
                foreach (ScriptReference item in list)
                {
                    scriptReferences.Add(item);
                }
            }
        }
Beispiel #3
0
        public static bool OutputCombineScriptResourcesFile(HttpContext context)
        {
            bool        result  = false;
            HttpRequest request = context.Request;
            string      text    = request.QueryString["resources"];

            if (!string.IsNullOrEmpty(text))
            {
                HttpResponse response = context.Response;
                response.ContentType = "application/x-javascript";
                HttpCachePolicy cache = response.Cache;
                cache.SetCacheability(HttpCacheability.Private);
                cache.VaryByParams["resources"] = true;
                cache.VaryByParams["v"]         = true;
                cache.VaryByParams["c"]         = true;
                cache.SetOmitVaryStar(true);
                cache.SetExpires(DateTime.Now.AddDays(365.0));
                cache.SetValidUntilExpires(true);
                DateTime lastWriteTime = new FileInfo(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath).LastWriteTime;
                DateTime lastModified  = (DateTime.UtcNow > lastWriteTime.ToUniversalTime()) ? lastWriteTime : DateTime.Now;
                cache.SetLastModified(lastModified);
                Stream stream = response.OutputStream;
                if (!request.Browser.IsBrowser("IE") || 6 < request.Browser.MajorVersion)
                {
                    foreach (string b in (request.Headers["Accept-Encoding"] ?? string.Empty).ToUpperInvariant().Split(new char[]
                    {
                        ','
                    }))
                    {
                        if ("GZIP" == b)
                        {
                            response.AddHeader("Content-encoding", "gzip");
                            stream = new GZipStream(stream, CompressionMode.Compress);
                            break;
                        }
                        if ("DEFLATE" == b)
                        {
                            response.AddHeader("Content-encoding", "deflate");
                            stream = new DeflateStream(stream, CompressionMode.Compress);
                            break;
                        }
                    }
                }
                CultureInfo currentCulture   = Thread.CurrentThread.CurrentCulture;
                CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
                try
                {
                    string text2 = request.QueryString["c"];
                    if (!string.IsNullOrEmpty(text2))
                    {
                        CultureInfo cultureInfoByIetfLanguageTag = CultureInfo.GetCultureInfoByIetfLanguageTag(text2);
                        Thread.CurrentThread.CurrentCulture = (Thread.CurrentThread.CurrentUICulture = cultureInfoByIetfLanguageTag);
                    }
                }
                catch (ArgumentException)
                {
                }
                CombinableScripts scriptByAlias = ToolkitScriptManager.CacheScriptBuckets.GetScriptByAlias(HttpUtility.UrlDecode(text), false);
                if (scriptByAlias != null)
                {
                    using (StreamWriter streamWriter = new StreamWriter(stream))
                    {
                        ToolkitScriptManager.WriteScriptsResources(scriptByAlias.Scripts, streamWriter);
                        streamWriter.WriteLine("if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();");
                    }
                    result = true;
                }
                else
                {
                    stream.Close();
                    stream = null;
                }
                Thread.CurrentThread.CurrentCulture   = currentCulture;
                Thread.CurrentThread.CurrentUICulture = currentUICulture;
            }
            return(result);
        }