コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="assetType">Type of the asset.</param>
        /// <param name="assets">The assets.</param>
        public WebAssetItemCollectionBuilder(WebAssetType assetType, WebAssetItemCollection assets)
        {
            if (assetType == WebAssetType.None)
            {
                throw new ArgumentException("None is only used for internal purpose", "assets");
            }

            _assetType = assetType;
            _assets    = assets;
        }
コード例 #2
0
        /// <summary>
        /// Merges the specified assets.
        /// </summary>
        /// <param name="contentType">Type of the content.</param>
        /// <param name="assetHandlerPath">The asset handler path.</param>
        /// <param name="isSecured">if set to <c>true</c> [is secure].</param>
        /// <param name="canCompress">if set to <c>true</c> [can compress].</param>
        /// <param name="assets">The assets.</param>
        /// <returns>The collection of web asset paths.</returns>
        public IList <string> Merge(string contentType, string assetHandlerPath, bool isSecured, bool canCompress, WebAssetItemCollection assets)
        {
            // If the instance object is null.
            if (contentType == null)
            {
                throw new System.ArgumentNullException("contentType");
            }
            if (assetHandlerPath == null)
            {
                throw new System.ArgumentNullException("assetHandlerPath");
            }
            if (assets == null)
            {
                throw new System.ArgumentNullException("assets");
            }

            IList <string> mergedList = new List <string>();
            Func <string, string, string> getRelativePath = (source, version) => _urlResolver.Resolve(_assetRegistry.Locate(source, version));

            Action <WebAssetItemGroup> processGroup = group =>
            {
                if (group.Combined)
                {
                    string id           = _assetRegistry.Store(contentType, group);
                    string virtualPath  = "{0}?{1}={2}".FormatWith(assetHandlerPath, _urlEncoder.Encode(WebAssetHttpHandler.IdParameterName), _urlEncoder.Encode(id));
                    string relativePath = _urlResolver.Resolve(virtualPath);

                    if (!mergedList.Contains(relativePath, StringComparer.OrdinalIgnoreCase))
                    {
                        mergedList.Add(relativePath);
                    }
                }
                else
                {
                    group.Items.Each(i =>
                    {
                        if (!mergedList.Contains(i.Source, StringComparer.OrdinalIgnoreCase))
                        {
                            mergedList.Add(getRelativePath(i.Source, group.Version));
                        }
                    });
                }
            };

            if (!assets.IsEmpty())
            {
                foreach (IWebAssetItem asset in assets)
                {
                    WebAssetItem      item      = asset as WebAssetItem;
                    WebAssetItemGroup itemGroup = asset as WebAssetItemGroup;

                    if (item != null)
                    {
                        mergedList.Add(getRelativePath(item.Source, null));
                    }
                    else if (itemGroup != null)
                    {
                        WebAssetItemGroup frameworkGroup = null;

                        if ((frameworkGroup != null) && !frameworkGroup.Items.IsEmpty())
                        {
                            processGroup(frameworkGroup);
                        }

                        if (!itemGroup.Items.IsEmpty())
                        {
                            processGroup(itemGroup);
                        }
                    }
                }
            }

            // Return the list.
            return(mergedList.ToList());
        }