Esempio n. 1
0
        internal void Add(Asset requirement, bool preventAddToCache = false)
        {
            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);
        }
Esempio n. 2
0
        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;
        }