Esempio n. 1
0
        private bool TryGetCachedAsset(IAsset asset, out IAsset cachedAsset)
        {
            cachedAsset = null;
            var entry = AssetCache.GetAsset(asset.VirtualPath);

            if (entry != null)
            {
                cachedAsset = new CachedAsset
                {
                    AssetTypeCode           = AssetTypeCode.Css,
                    Combined                = true,
                    Content                 = entry.Content,
                    IsStylesheet            = true,
                    Minified                = entry.ProcessorCodes.Contains(DefaultAssetCache.MinificationCode),
                    RelativePathsResolved   = entry.ProcessorCodes.Contains(DefaultAssetCache.UrlRewriteCode),
                    Autoprefixed            = entry.ProcessorCodes.Contains(DefaultAssetCache.AutoprefixCode),
                    OriginalAssets          = new List <IAsset>(),
                    VirtualPath             = asset.VirtualPath,
                    VirtualPathDependencies = entry.VirtualPathDependencies.ToList(),
                    Url = asset.Url
                };
            }

            return(cachedAsset != null);
        }
Esempio n. 2
0
        private IAsset TranslateInternal(IAsset asset)
        {
            IAsset result;
            var    chronometer = EngineContext.Current.Resolve <IChronometer>();

            using (chronometer.Step("Translate asset {0}".FormatInvariant(asset.VirtualPath)))
            {
                bool validationMode = ThemeHelper.IsStyleValidationRequest();

                if (validationMode || !TryGetCachedAsset(asset, out result))
                {
                    lock (String.Intern("CachedAsset:" + asset.VirtualPath))
                    {
                        if (validationMode || !TryGetCachedAsset(asset, out result))
                        {
                            using (chronometer.Step("Compile asset {0}".FormatInvariant(asset.VirtualPath)))
                            {
                                result = _inner.Translate(asset);

                                var cachedAsset = new CachedAsset
                                {
                                    AssetTypeCode           = AssetTypeCode.Css,
                                    IsStylesheet            = true,
                                    Minified                = result.Minified,
                                    Combined                = result.Combined,
                                    Content                 = result.Content,
                                    OriginalAssets          = asset.OriginalAssets,
                                    VirtualPath             = asset.VirtualPath,
                                    VirtualPathDependencies = result.VirtualPathDependencies,
                                    Url = asset.Url
                                };

                                result = AssetTranslorUtil.PostProcessAsset(cachedAsset, this.IsDebugMode);

                                if (!validationMode)
                                {
                                    var pCodes = new List <string>(3);
                                    if (cachedAsset.Minified)
                                    {
                                        pCodes.Add(DefaultAssetCache.MinificationCode);
                                    }
                                    if (cachedAsset.RelativePathsResolved)
                                    {
                                        pCodes.Add(DefaultAssetCache.UrlRewriteCode);
                                    }
                                    if (cachedAsset.Autoprefixed)
                                    {
                                        pCodes.Add(DefaultAssetCache.AutoprefixCode);
                                    }

                                    AssetCache.InsertAsset(
                                        cachedAsset.VirtualPath,
                                        cachedAsset.VirtualPathDependencies,
                                        cachedAsset.Content,
                                        pCodes.ToArray());
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }