コード例 #1
0
 static PersistentCache()
 {
     Instance = new PersistentCache(
         Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "style_compiler_persistent_cache"),
         new[] { typeof(PersistentCache).GetTypeInfo().Assembly }
         );
     Instance.Debug   = true;
     Instance.Enabled = !Utils.IsContinuousIntegration();
 }
コード例 #2
0
        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());
        }