Beispiel #1
0
        public IEsiFragment Parse(IReadOnlyDictionary <string, string> attributes, string body)
        {
            if (attributes == null)
            {
                throw new ArgumentNullException(nameof(attributes));
            }
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            var srcUrl = VariableStringParser.Parse(attributes["src"]);

            var srcFragment = new EsiIncludeFragment(srcUrl);

            IEsiFragment includeFragment;

            if (attributes.TryGetValue("alt", out var altUrl))
            {
                var altFragment = new EsiIncludeFragment(VariableStringParser.Parse(altUrl));
                includeFragment = new EsiTryFragment(srcFragment, altFragment);
            }
            else
            {
                includeFragment = srcFragment;
            }

            return(ShouldContinueOnError(attributes)
                ? new EsiTryFragment(includeFragment, new EsiIgnoreFragment())
                : includeFragment);
        }
        public async Task <IEnumerable <string> > Execute(
            EsiIncludeFragment fragment,
            EsiExecutionContext executionContext)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException(nameof(fragment));
            }

            var rawUrl = string.Concat(VariableStringResolver.Resolve(executionContext, fragment.Url));
            var uri    = _uriParser(rawUrl);

            var remoteFragment = await _cache.GetOrAdd(
                uri,
                executionContext,
                () => RequestAndParse(uri, executionContext));

            return(await _fragmentExecutor.Execute(remoteFragment, executionContext));
        }