public void Inflate(PersistentCache persistentCache) { var knownSegments = new HashSet <string>(); var parallelTasks = new List <Task>(); foreach (var distributionName in LessRegistry.CssDistributions.Keys) { foreach (var item in LessAggregation.EnumerateAllItems(_sourcePath, distributionName)) { LessAggregation.CheckLessDuplicates(item); foreach (var segment in item.Segments) { if (knownSegments.Contains(segment.Key)) { continue; } knownSegments.Add(segment.Key); parallelTasks.Add(new Task(delegate() { var paths = segment.LessFiles.Select(i => Path.Combine(_sourcePath, i)); var bag = persistentCache.Get(new[] { "css", segment.Key }, paths, delegate() { if (distributionName == LessRegistry.CSS_DISTRIBUTION_DEFAULT) { CheckUnusedLessConsts(paths); } var css = LessAggregation.CompileLessPaths(paths); css = ImageInliner.InlineImages(css, _sourcePath); css = CssHelper.StripCommentsOnly(css); return(new Dictionary <string, string> { { "_", css } }); }); _SegmentCache[segment.Key] = bag["_"]; })); } } } foreach (var t in parallelTasks) { t.Start(); if (Utils.IsDocker()) { // limit CPU usage in Docker builds t.Wait(); } } Task.WaitAll(parallelTasks.ToArray()); }
public void ProcessRequest(IQueryCollection queryString, Stream responseBody) { var allLessPaths = from segment in CreateAggregationItem(queryString).Segments from fileName in segment.LessFiles select Path.Combine(_sourcePath, fileName); var css = LessAggregation.CompileLessPaths(allLessPaths); css = NormalizeUrls(css); if (queryString.ContainsKey("disable_font_face")) { css = css.Replace("@font-face", "@disabled-font-face"); } using (var writer = new StreamWriter(responseBody)) { writer.Write(css); } }