示例#1
0
        /// <summary>
        /// Eliminates the duplicates and resolve urls.
        /// </summary>
        /// <param name="refs">The refs.</param>
        /// <param name="tagFormat">The tag format.</param>
        /// <returns>List Of Asset Tags</returns>
        private IEnumerable <AssetManager.AssetTag> EliminateDuplicatesAndResolveUrls(IEnumerable <AssetManager.AssetTag> refs, string tagFormat)
        {
            List <AssetManager.AssetTag> list            = new List <AssetManager.AssetTag>();
            HashSet <string>             hashSet         = new HashSet <string>();
            HashSet <string>             bundledContents = new HashSet <string>();
            HtmlTemplateBundleResolver   resolver        = (HtmlTemplateBundleResolver)this.Resolver;

            foreach (AssetManager.AssetTag assetTag in refs)
            {
                if (assetTag.IsStaticAsset)
                {
                    list.Add(assetTag);
                }
                else
                {
                    string virtualPath1 = assetTag.Value;
                    if (!hashSet.Contains(virtualPath1))
                    {
                        if (resolver.IsBundleVirtualPath(virtualPath1))
                        {
                            StringBuilder stringBuilder = new StringBuilder();
                            foreach (BundleFile bundleFile in resolver.GetBundleFileContents(virtualPath1))
                            {
                                string fileContent = bundleFile.ApplyTransforms();
                                string templateId  = bundleFile.IncludedVirtualPath;
                                stringBuilder.Append(assetTag.Render(tagFormat, fileContent, templateId));
                                stringBuilder.Append(Environment.NewLine);
                            }
                            assetTag.Value = stringBuilder.ToString();
                            list.Add(assetTag);
                        }
                        else
                        {
                            string str = this.ResolveVirtualPath(virtualPath1);
                            if (!hashSet.Contains(str))
                            {
                                hashSet.Add(str);
                                assetTag.Value = str;
                                list.Add(assetTag);
                            }
                        }
                        hashSet.Add(virtualPath1);
                    }
                }
            }
            return(Enumerable.Where <AssetManager.AssetTag>((IEnumerable <AssetManager.AssetTag>)list, (Func <AssetManager.AssetTag, bool>)(asset =>
            {
                if (!asset.IsStaticAsset)
                {
                    return !bundledContents.Contains(asset.Value);
                }
                else
                {
                    return true;
                }
            })));
        }
示例#2
0
        private IEnumerable <AssetManager.AssetTag> DeterminePathsToRender(IEnumerable <string> assets, string tagFormat)
        {
            List <AssetManager.AssetTag> list     = new List <AssetManager.AssetTag>();
            HtmlTemplateBundleResolver   resolver = (HtmlTemplateBundleResolver)this.Resolver;

            foreach (string str1 in assets)
            {
                if (resolver.IsBundleVirtualPath(str1))
                {
                    if (!this.OptimizationEnabled)
                    {
                        list.Add(new AssetManager.AssetTag(str1));
                    }
                    else
                    {
                        list.Add(new AssetManager.AssetTag(str1));
                        if (this.Bundles.UseCdn)
                        {
                            Bundle bundleFor = this.Bundles.GetBundleFor(str1);
                            if (bundleFor != null && !string.IsNullOrEmpty(bundleFor.CdnPath) && !string.IsNullOrEmpty(bundleFor.CdnFallbackExpression))
                            {
                                list.Add(new AssetManager.AssetTag(string.Format((IFormatProvider)CultureInfo.InvariantCulture, OptimizationResources.CdnFallBackScriptString, new object[2]
                                {
                                    (object)bundleFor.CdnFallbackExpression,
                                    (object)this.ResolveVirtualPath(str1)
                                }))
                                {
                                    IsStaticAsset = true
                                });
                            }
                        }
                    }
                }
                else
                {
                    list.Add(new AssetManager.AssetTag(str1));
                }
            }
            return(this.EliminateDuplicatesAndResolveUrls((IEnumerable <AssetManager.AssetTag>)list, tagFormat));
        }