Esempio n. 1
0
        public static T ScheduleDisposeForScopeEnd <T>(this IScopedDisposer disposer, T disposable)
            where T : IDisposable
        {
            if (disposer == null)
            {
                throw new ArgumentNullException(nameof(disposer));
            }

            disposer.Register(disposable);
            return(disposable);
        }
Esempio n. 2
0
        public async Task <bool> TryEnsureUrlAsync(HttpContext httpContext)
        {
            PathString branchPath = httpContext.Request.Path;

            if (!branchPath.StartsWithSegments(_bundlingContext.BundlesPathPrefix, out PathString bundlePath))
            {
                return(false);
            }

            QueryString query = httpContext.Request.QueryString;

            _urlHelper.RemoveVersion(ref bundlePath, ref query);

            if (!_bundles.TryGetValue(bundlePath, out IBundleModel bundle))
            {
                return(false);
            }

            IScopedDisposer disposer = httpContext.RequestServices.GetRequiredService <IScopedDisposer>();

            query = UrlUtils.NormalizeQuery(query, out IDictionary <string, StringValues> @params);
            if (!bundle.DependsOnParams)
            {
                query = QueryString.Empty;
            }

            var cacheKey = new BundleCacheKey(_id, bundlePath, query);
            IBundleCacheItem cacheItem = await _cache.GetOrAddAsync(cacheKey, ct => BuildBundleAsync(bundle, query, @params, httpContext),
                                                                    httpContext.RequestAborted, bundle.CacheOptions, lockFile : true);

            try
            {
                // scheduling release of the lock for the end of the scope (request),
                // so that the file remain unchanged until it's served
                disposer.Register(cacheItem.FileReleaser);
            }
            catch
            {
                cacheItem.FileReleaser.Dispose();
                throw;
            }

            // passing file info to GetFileInfo(), which is called later in the request (see BundlingMiddleware and BundleFileProvider)
            httpContext.Items.Add(s_httpContextItemKey, cacheItem.FileInfo);

            return(true);
        }
Esempio n. 3
0
 public static T ScheduleDisposeForScopeEnd <T>(this IScopedDisposer @this, T disposable)
     where T : IDisposable
 {
     @this.Register(disposable);
     return(disposable);
 }