Click here to Skip to main content
13,633,125 members
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads

Stats

40.7K views
3.1K downloads
22 bookmarked
Posted 1 Nov 2009
Licenced Apache

Combres - WebForm & MVC Client-side Resource Combine Library

, 1 Nov 2009
A .NET library which enables minification, compression, combination, and caching of JavaScript and CSS resources for ASP.NET and ASP.NET MVC web applications. Simply put, it helps your applications rank better with YSlow and PageSpeed.
Combres
trunk
Combres
API
Common
Configuration
Exceptions
Filters
Model
Properties
Resources
Libraries
EcmaScript.NET.modified.dll
Fasterflect.dll
log4net.dll
Yahoo.Yui.Compressor.dll
Samples
MvcSample
App_Data
Content
images
ui-bg_diagonals-thick_18_b81900_40x40.png
ui-bg_diagonals-thick_20_666666_40x40.png
ui-bg_flat_10_000000_40x100.png
ui-bg_glass_100_f6f6f6_1x400.png
ui-bg_glass_100_fdf5ce_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_gloss-wave_35_f6a828_500x100.png
ui-bg_highlight-soft_100_eeeeee_1x100.png
ui-bg_highlight-soft_75_ffe45c_1x100.png
ui-icons_222222_256x240.png
ui-icons_228ef1_256x240.png
ui-icons_ef8c08_256x240.png
ui-icons_ffd27a_256x240.png
ui-icons_ffffff_256x240.png
Controllers
Properties
Scripts
Views
Home
Shared
Site.Master
WebFormSample
App_Data
Content
images
ui-bg_diagonals-thick_18_b81900_40x40.png
ui-bg_diagonals-thick_20_666666_40x40.png
ui-bg_flat_10_000000_40x100.png
ui-bg_glass_100_f6f6f6_1x400.png
ui-bg_glass_100_fdf5ce_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_gloss-wave_35_f6a828_500x100.png
ui-bg_highlight-soft_100_eeeeee_1x100.png
ui-bg_highlight-soft_75_ffe45c_1x100.png
ui-icons_222222_256x240.png
ui-icons_228ef1_256x240.png
ui-icons_ef8c08_256x240.png
ui-icons_ffd27a_256x240.png
ui-icons_ffffff_256x240.png
Properties
Scripts
Combres.dll
EcmaScript.NET.modified.dll
Fasterflect.dll
log4net.dll
Yahoo.Yui.Compressor.dll
API
Common
Configuration
Exceptions
Filters
Model
Properties
Resources
Samples
MvcSample
App_Data
Content
images
ui-bg_diagonals-thick_18_b81900_40x40.png
ui-bg_diagonals-thick_20_666666_40x40.png
ui-bg_flat_10_000000_40x100.png
ui-bg_glass_100_f6f6f6_1x400.png
ui-bg_glass_100_fdf5ce_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_gloss-wave_35_f6a828_500x100.png
ui-bg_highlight-soft_100_eeeeee_1x100.png
ui-bg_highlight-soft_75_ffe45c_1x100.png
ui-icons_222222_256x240.png
ui-icons_228ef1_256x240.png
ui-icons_ef8c08_256x240.png
ui-icons_ffd27a_256x240.png
ui-icons_ffffff_256x240.png
Controllers
Properties
Scripts
Views
Home
Shared
Site.Master
WebFormSample
App_Data
Content
images
ui-bg_diagonals-thick_18_b81900_40x40.png
ui-bg_diagonals-thick_20_666666_40x40.png
ui-bg_flat_10_000000_40x100.png
ui-bg_glass_100_f6f6f6_1x400.png
ui-bg_glass_100_fdf5ce_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_gloss-wave_35_f6a828_500x100.png
ui-bg_highlight-soft_100_eeeeee_1x100.png
ui-bg_highlight-soft_75_ffe45c_1x100.png
ui-icons_222222_256x240.png
ui-icons_228ef1_256x240.png
ui-icons_ef8c08_256x240.png
ui-icons_ffd27a_256x240.png
ui-icons_ffffff_256x240.png
Properties
Scripts
#region License
// Copyright 2009 Buu Nguyen (http://www.buunguyen.net/blog)
// 
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0 
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
// 
// The latest version of this file can be found at http://combres.codeplex.com
#endregion

using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;

namespace Combres
{
    /// <summary>
    /// Represents a group of resource files.
    /// </summary>
    public class ResourceSet : IEnumerable<Resource>
    {
        /// <summary>
        /// The name of the resource group.  This is to be referred to when generating
        /// links or URLs to the group.
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Version of this resource group.
        /// </summary>
        public string Version { get; private set; }

        /// <summary>
        /// Duration of this resource group.  Specify how long the generated result
        /// should be cached at both client and server.
        /// </summary>
        public TimeSpan DurationInDays { get; private set; }

        /// <summary>
        /// The type of resource (JavaScript or CSS).
        /// </summary>
        public ResourceType Type { get; private set; }

        /// <summary>
        /// If true, items in this resource set won't be cached, compressed and minimized 
        /// to facilitate debugging.
        /// </summary>
        public bool DebugEnabled { get; private set; }

        /// <summary>
        /// The child resources.
        /// </summary>
        private List<Resource> resources = new List<Resource>();

        /// <summary>
        /// List of child resources.
        /// </summary>
        public List<Resource> Resources { get { return resources;} }

        internal ResourceSet(Settings parent, XmlElement section)
        {
            Name = section.GetAttribute(NodeConstants.SetName);
            InitializeDuration(section, parent);
            InitializeVersion(section, parent);
            InitializeCategory(section);
            InitializeDebugEnabled(section, parent);
            foreach (var node in section.ChildNodes)
            {
                if (node is XmlElement)
                {
                    resources.Add(new Resource(node as XmlElement, this));
                }
            }
        }

        private void InitializeVersion(XmlElement section, Settings parent)
        {
            var version = section.GetAttribute(NodeConstants.SetVersion);
            if (string.IsNullOrEmpty(version))
            {
                if (parent.DefaultVersion == null)
                    throw new XmlSchemaException(NodeConstants.SettingDefaultVersion + " must be available if not specified in resourceSet");
                Version = parent.DefaultVersion;
            }
            else
            {
                Version = version;
            }
        }

        private void InitializeDuration(XmlElement section, Settings parent)
        {
            var duration = section.GetAttribute(NodeConstants.SetDuration);
            if (string.IsNullOrEmpty(duration))
            {
                if (parent.DefaultDuration == null)
                    throw new XmlSchemaException(NodeConstants.SettingDefaultDuration + " must be available if not specified in resourceSet");
                DurationInDays = TimeSpan.FromDays(parent.DefaultDuration.Value);
            }
            else
            {
                DurationInDays = TimeSpan.FromDays(int.Parse(duration));
            }
        }

        private void InitializeCategory(XmlElement section)
        {
            Type = (ResourceType)Enum.Parse(typeof(ResourceType),
                                        section.GetAttribute(NodeConstants.SetType).ToUpperInvariant());
        }

        private void InitializeDebugEnabled(XmlElement section, Settings parent)
        {
            var debugEnabled = section.GetAttribute(NodeConstants.DebugEnabled);
            DebugEnabled = string.IsNullOrEmpty(debugEnabled) 
                ? parent.DefaultDebugEnabled 
                : bool.Parse(debugEnabled);
        }

        IEnumerator<Resource> IEnumerable<Resource>.GetEnumerator()
        {
            foreach (var resource in resources)
            {
                yield return resource;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable<Resource>)this).GetEnumerator();
        }

        public override bool Equals(object obj)
        {
            if (obj == this)
                return true;
            if (!(obj is ResourceSet))
                return false;
            return Name.Equals(((ResourceSet)obj).Name);
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        } 
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Share

About the Author

Buu Nguyen
Chief Technology Officer KMS Technology
Vietnam Vietnam
You can visit Buu's blog at http://www.buunguyen.net/blog to read about his thoughts on software development.

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180712.1 | Last Updated 2 Nov 2009
Article Copyright 2009 by Buu Nguyen
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid