예제 #1
0
        /// <summary>
        /// Adds the specified source as <see cref="WebAsset"/> in the specified <see cref="WebAssetGroup"/>.
        /// </summary>
        /// <param name="groupName">Name of the group.</param>
        /// <param name="itemSource">The item source.</param>
        public virtual void Add(string groupName, string itemSource)
        {
            Guard.IsNotNullOrEmpty(groupName, "groupName");
            Guard.IsNotVirtualPath(itemSource, "itemSource");

            WebAssetGroup itemGroup = FindGroupByName(groupName);

            if (itemGroup == null)
            {
                itemGroup = CreateGroup(groupName);
                Add(itemGroup);
            }

            itemGroup.Items.Add(CreateItem(itemSource));
        }
예제 #2
0
        private bool AlreadyExists(IWebAsset item)
        {
            WebAsset      assetItem      = item as WebAsset;
            WebAssetGroup assetItemGroup = item as WebAssetGroup;

            if (assetItem != null)
            {
                return(AssetItems.Any(i => i != item && i.Source.IsCaseInsensitiveEqual(assetItem.Source)));
            }

            if (assetItemGroup != null)
            {
                return(AssetGroups.Any(i => i != item && i.Name.IsCaseInsensitiveEqual(assetItemGroup.Name)));
            }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Enables a WebAssetHttpHandler object to process of requests.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void ProcessRequest(HttpContextBase context)
        {
            string id = context.Request.QueryString[IdParameterName];

            if (!string.IsNullOrEmpty(id))
            {
                WebAssetGroup group = SharedWebAssets.FindScriptGroup(id)
                                      ?? SharedWebAssets.FindStyleSheetGroup(id) ?? new WebAssetGroupSerializer().Deserialize(id);

                if (group != null)
                {
                    HttpResponseBase response = context.Response;

                    // Set the content type
                    response.ContentType = group.ContentType;

                    string content = reader.Read(group);

                    if (!string.IsNullOrEmpty(content))
                    {
                        // Compress
                        if (group.Compress && !context.IsMono())
                        {
                            httpResponseCompressor.Compress(context);
                        }

                        // Write
                        using (StreamWriter sw = new StreamWriter((response.OutputStream)))
                        {
                            sw.Write(content);
                        }

                        // Cache
                        if (!context.IsDebuggingEnabled)
                        {
                            httpResponseCacher.Cache(context, TimeSpan.FromDays(group.CacheDurationInDays));
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Adds the group.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="configureAction">The configure action.</param>
        /// <returns></returns>
        public virtual SharedWebAssetGroupBuilder AddGroup(string name, Action <WebAssetGroupBuilder> configureAction)
        {
            Guard.IsNotNullOrEmpty(name, "name");
            Guard.IsNotNull(configureAction, "configureAction");

            WebAssetGroup group;

            if (assets.TryGetValue(name, out group))
            {
                throw new ArgumentException(TextResource.GroupWithSpecifiedNameAlreadyExistsPleaseSpecifyADifferentName.FormatWith(name));
            }

            group = new WebAssetGroup(name, true)
            {
                DefaultPath = defaultPath
            };
            assets.Add(name, group);

            WebAssetGroupBuilder builder = new WebAssetGroupBuilder(group);

            configureAction(builder);

            return(this);
        }
예제 #5
0
        private static void LoadGroups(WebAssetGroupConfigurationElementCollection source, IDictionary <string, WebAssetGroup> destination, string defaultPath, string defaultVersion)
        {
            foreach (WebAssetGroupConfigurationElement configurationGroup in source)
            {
                WebAssetGroup group = new WebAssetGroup(configurationGroup.Name, true)
                {
                    DefaultPath = !string.IsNullOrEmpty(configurationGroup.DefaultPath) ? configurationGroup.DefaultPath : defaultPath,
                    ContentDeliveryNetworkUrl = configurationGroup.ContentDeliveryNetworkUrl,
                    Enabled             = configurationGroup.Enabled,
                    Version             = !string.IsNullOrEmpty(configurationGroup.Version) ? configurationGroup.Version : defaultVersion,
                    Compress            = configurationGroup.Compress,
                    CacheDurationInDays = configurationGroup.CacheDurationInDays,

                    Combined = configurationGroup.Combined
                };

                if (configurationGroup.UseTelerikContentDeliveryNetwork.HasValue)
                {
                    group.UseTelerikContentDeliveryNetwork = configurationGroup.UseTelerikContentDeliveryNetwork.Value;
                }

                foreach (WebAssetConfigurationElement configurationItem in configurationGroup.Items)
                {
                    string itemSource = configurationItem.Source;

                    if (!itemSource.StartsWith("~/", StringComparison.OrdinalIgnoreCase) && !itemSource.Contains("://"))
                    {
                        itemSource = PathHelper.CombinePath(group.DefaultPath, itemSource);
                    }

                    group.Items.Add(new WebAsset(itemSource));
                }

                destination.Add(group.Name, group);
            }
        }