private void ProcessMergeGroup(ICollection <string> minifiedContents,
                                       IEnumerable <Resource> mergeGroup, MinifierInfo currentMinifier)
        {
            var singleContents  = processor.GetSingleContents(mergeGroup, true);
            var combinedContent = processor.GetCombinedContents(mergeGroup, singleContents, false);
            var minifiedContent = processor.MinifyContent(currentMinifier, mergeGroup, combinedContent);

            minifiedContents.Add(minifiedContent);
        }
        public void Execute()
        {
            if (processor.IsInBrowserCache())
            {
                return;
            }

            if (processor.WriteFromServerCache())
            {
                return;
            }

            using (var memoryStream = new MemoryStream(4096))
            {
                /*
                 * Each resource in a set may have a unique minifier.  At the same time,
                 * the order of resource as configured in the XML data file must be honored
                 * when merging them together.
                 *
                 * Combres will group resources into merge-groups each includes resources sitting
                 * next to each other in the XML data file having the same minifier.
                 */
                var          minifiedContents = new List <string>();
                var          mergeGroup       = new List <Resource>();
                MinifierInfo currentMinifier  = null;
                foreach (var resource in processor.ResourceSet)
                {
                    // not the first time AND hit a different minifier, finish up the current merge-group
                    if (currentMinifier != null && currentMinifier != resource.Minifier)
                    {
                        ProcessMergeGroup(minifiedContents, mergeGroup, currentMinifier);
                        mergeGroup.Clear();
                    }
                    currentMinifier = resource.Minifier;
                    mergeGroup.Add(resource);
                }
                if (mergeGroup.Count > 0) // there's some left-over
                {
                    ProcessMergeGroup(minifiedContents, mergeGroup, currentMinifier);
                }

                var    mergedContent     = processor.MergeContents(minifiedContents.ToArray());
                var    compressedContent = processor.TryZipContent(mergedContent, memoryStream);
                string etag = processor.GenerateETag(compressedContent);
                processor.CacheNewResponse(compressedContent, etag);
                processor.SendOutputToClient(compressedContent, true, etag);
            }
        }
Ejemplo n.º 3
0
        internal string MinifyContent(MinifierInfo minifierInfo, IEnumerable <Resource> resources, string combinedContent)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug(string.Format(CultureInfo.InvariantCulture,
                                        "Minifying combined content using minifier {0} and binder {1}...",
                                        minifierInfo.Name,
                                        minifierInfo.BinderType));
            }

            using (new Timer("Minifying & filtering " + ResourceSet.Name, Log.IsDebugEnabled, Log.Debug))
            {
                var minifier = (IResourceMinifier)minifierInfo.Type.CreateInstance();
                BindParameters(minifier, minifierInfo.BinderType, minifierInfo.Parameters);
                var minifiedContent = minifier.Minify(Settings, ResourceSet, combinedContent);
                return(FilterContent <string, IMinifiedContentFilter, IEnumerable <Resource> >(
                           resources, minifiedContent));
            }
        }
Ejemplo n.º 4
0
 private static void LoadMinifiers(XElement xe, string elementName, IDictionary <string, MinifierInfo> map)
 {
     foreach (var childXe in xe.ChildrenOfChild(elementName, SchemaConstants.Namespace))
     {
         var name = childXe.Attr <string>(SchemaConstants.Minifier.Name);
         if (map.ContainsKey(name))
         {
             throw new XmlSchemaException(string.Format(CultureInfo.InvariantCulture,
                                                        "Minifier {0} already exists", name));
         }
         var typeName = childXe.Attr <string>(SchemaConstants.Minifier.Type);
         var type     = ModelUtils.LoadType("Minifier", typeName, SchemaConstants.Minifier.ValidTypes);
         var minifier = new MinifierInfo
         {
             Name       = name,
             Type       = type,
             Parameters = childXe.Elements(XName.Get(SchemaConstants.Param.Root, SchemaConstants.Namespace)).ToList(),
             BinderType = GetBinderType(childXe),
         };
         map.Add(name, minifier);
     }
 }
Ejemplo n.º 5
0
 private static void LoadMinifiers(XElement xe, string elementName, IDictionary<string, MinifierInfo> map)
 {
     foreach (var childXe in xe.ChildrenOfChild(elementName, SchemaConstants.Namespace))
     {
         var name = childXe.Attr<string>(SchemaConstants.Minifier.Name);
         if (map.ContainsKey(name))
             throw new XmlSchemaException(string.Format(CultureInfo.InvariantCulture, 
                                              "Minifier {0} already exists", name));
         var typeName = childXe.Attr<string>(SchemaConstants.Minifier.Type);
         var type = ModelUtils.LoadType("Minifier", typeName, SchemaConstants.Minifier.ValidTypes);
         var minifier = new MinifierInfo
                            {
                                Name = name,
                                Type = type,
                                Parameters = childXe.Elements(XName.Get(SchemaConstants.Param.Root, SchemaConstants.Namespace)).ToList(),
                                BinderType = GetBinderType(childXe),
                            };
         map.Add(name, minifier);
     }
 }
Ejemplo n.º 6
0
 private void ProcessMergeGroup(ICollection<string> minifiedContents, 
     IEnumerable<Resource> mergeGroup, MinifierInfo currentMinifier)
 {
     var singleContents = processor.GetSingleContents(mergeGroup, true);
     var combinedContent = processor.GetCombinedContents(mergeGroup, singleContents, false);
     var minifiedContent = processor.MinifyContent(currentMinifier, mergeGroup, combinedContent);
     minifiedContents.Add(minifiedContent);
 }