Ejemplo n.º 1
0
        public async Task <IEnumerable <string> > Execute(IEsiFragment fragment, EsiExecutionContext executionContext)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException(nameof(fragment));
            }

            var fragmentType = fragment.GetType();

            if (!_executors.TryGetValue(fragmentType, out var executor))
            {
                throw new NotSupportedException($"No executor found for type '{fragmentType}'.");
            }

            var pipelineDelegates = _pipelineCache.GetOrAdd(fragmentType, GetPipelineDelegates);

            if (!pipelineDelegates.Any())
            {
                return(await executor(fragment, executionContext));
            }

            Task <IEnumerable <string> > Exec(IEsiFragment f, EsiExecutionContext ec) => executor(f, ec);

            return(await pipelineDelegates
                   .Aggregate(
                       (ExecuteDelegate)Exec,
                       (next, pipeline) => async (f, ec) => await pipeline(f, ec, next))(fragment, executionContext));
        }
Ejemplo n.º 2
0
        private async Task StoreFragmentInCache(
            HttpContext context, Uri pageUri, EsiExecutionContext executionContext, IEsiFragment fragment)
        {
            CacheControlHeaderValue.TryParse(
                context.Response.Headers[HeaderNames.CacheControl], out var cacheControl);

            if (ShouldSetCache(context))
            {
                var headers      = context.Response.Headers.ToDictionary();
                var pageResponse = new FragmentPageResponse(fragment, headers);

                var vary          = context.Response.Headers[HeaderNames.Vary];
                var cacheResponse = CacheResponse.Create(pageResponse, cacheControl, vary);

                await _cache.Set(pageUri, executionContext, cacheResponse);
            }
        }
Ejemplo n.º 3
0
 public FragmentPageResponse(IEsiFragment fragment, IReadOnlyDictionary <string, IReadOnlyCollection <string> > headers)
 {
     Fragment = fragment ?? throw new ArgumentNullException(nameof(fragment));
     Headers  = headers;
 }
Ejemplo n.º 4
0
 public EsiTryFragment(IEsiFragment attemptFragment, IEsiFragment exceptFragment)
 {
     AttemptFragment = attemptFragment ?? throw new ArgumentNullException(nameof(attemptFragment));
     ExceptFragment  = exceptFragment ?? throw new ArgumentNullException(nameof(exceptFragment));
 }
Ejemplo n.º 5
0
 public EsiChooseFragment(IReadOnlyCollection <EsiWhenFragment> whenFragments, IEsiFragment otherwiseFragment)
 {
     WhenFragments     = whenFragments;
     OtherwiseFragment = otherwiseFragment;
 }
Ejemplo n.º 6
0
 public EsiWhenFragment(IBooleanExpression expression, IEsiFragment innerFragment)
 {
     Expression    = expression ?? throw new ArgumentNullException(nameof(expression));
     InnerFragment = innerFragment ?? throw new ArgumentNullException(nameof(innerFragment));
 }