private bool IsForContextSite(Asset asset) { if (asset.Site == null) return true; foreach (var part in asset.Site.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries)) { var siteWildcard = part.Trim().ToLowerInvariant(); if (siteWildcard == "*" || Context.Site.Name.Equals(siteWildcard, StringComparison.InvariantCultureIgnoreCase)) return true; } return false; }
internal void Add(Asset requirement, bool preventAddToCache = false) { lock (_items) { if (requirement.AddOnceToken != null) { if (this._items.Any(x => x.AddOnceToken != null && x.AddOnceToken == requirement.AddOnceToken)) { return; } } if (requirement.File != null) { if (this._items.Any(x => x.File != null && x.File == requirement.File)) { return; } } if (!preventAddToCache) { if (RenderingContext.Current != null) { var rendering = RenderingContext.Current.Rendering; if (rendering != null && rendering.Caching.Cacheable) { AssetRequirementList cachedRequirements; var renderingId = rendering.RenderingItem.ID; if (!this._seenRenderings.Contains(renderingId)) { this._seenRenderings.Add(renderingId); cachedRequirements = new AssetRequirementList(); } else { cachedRequirements = _cache.Get(renderingId) ?? new AssetRequirementList(); } cachedRequirements.Add(requirement); _cache.Set(renderingId, cachedRequirements); } } } // Passed the checks, add the requirement. this._items.Add(requirement); } }
internal Asset CreateFromConfiguration(XmlNode node) { var assetTypeString = XmlUtil.GetAttribute("type", node, null); var assetFile = XmlUtil.GetAttribute("file", node, null); var scriptLocationString = XmlUtil.GetAttribute("location", node, null); var innerValue = node.InnerXml; if (string.IsNullOrWhiteSpace(assetTypeString)) { Log.Warn($"Invalid asset in GetPageRendering.AddAssets pipeline: {node.OuterXml}", this); return null; } AssetType assetType; if (!Enum.TryParse(assetTypeString, true, out assetType)) { Log.Warn($"Invalid asset type in GetPageRendering.AddAssets pipeline: {node.OuterXml}", this); return null; } ScriptLocation? scriptLocation = null; if (scriptLocationString != null) { ScriptLocation location; if (!Enum.TryParse(scriptLocationString, true, out location)) { Log.Warn($"Invalid script location in GetPageRendering.AddAssets pipeline: {node.OuterXml}", this); return null; } scriptLocation = location; } Asset asset = null; if (!string.IsNullOrEmpty(assetFile)) { if (scriptLocation.HasValue) { asset = new Asset(assetType, assetFile, scriptLocation.Value); } else { asset = new Asset(assetType, assetFile); } } else if (!string.IsNullOrEmpty(innerValue)) { if (scriptLocation.HasValue) { asset = new Asset(assetType, null, inline: innerValue, addOnceToken: innerValue.GetHashCode().ToString(), location: scriptLocation.Value); } else { asset = new Asset(assetType, null, inline: innerValue, addOnceToken: innerValue.GetHashCode().ToString()); } } return asset; }
internal Asset CreateFromConfiguration(XmlNode node) { var assetTypeString = XmlUtil.GetAttribute("type", node, null); var assetFile = XmlUtil.GetAttribute("file", node, null); var scriptLocationString = XmlUtil.GetAttribute("location", node, null); var site = XmlUtil.GetAttribute("site", node, null); var inlineValue = node.InnerXml; if (string.IsNullOrWhiteSpace(assetTypeString)) { Log.Warn($"Invalid asset in GetPageRendering.AddAssets pipeline: {node.OuterXml}", this); return null; } AssetType assetType; if (!Enum.TryParse(assetTypeString, true, out assetType)) { Log.Warn($"Invalid asset type in GetPageRendering.AddAssets pipeline: {node.OuterXml}", this); return null; } var scriptLocation = ScriptLocation.Body; if (scriptLocationString != null) { ScriptLocation location; if (!Enum.TryParse(scriptLocationString, true, out location)) { Log.Warn($"Invalid script location in GetPageRendering.AddAssets pipeline: {node.OuterXml}", this); return null; } scriptLocation = location; } Asset asset = null; if (!string.IsNullOrEmpty(assetFile)) { asset = new Asset(assetType, scriptLocation, assetFile, site:site); } else if (!string.IsNullOrEmpty(inlineValue)) { asset = new Asset(assetType, scriptLocation, inline:inlineValue, site:site); } return asset; }