예제 #1
0
 public ExternalCancellationTokenScope(BundleBuilderContext context, CancellationToken externalCancellationToken)
 {
     _context = context;
     _originalCancellationToken = context.CancellationToken;
     _linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_originalCancellationToken, externalCancellationToken);
     context.CancellationToken = _linkedCts.Token;
 }
예제 #2
0
            public void Dispose()
            {
                BundleBuilderContext context = Interlocked.Exchange(ref _context, null);

                if (context != null)
                {
                    _linkedCts.Dispose();
                    context.CancellationToken = _originalCancellationToken;
                }
            }
예제 #3
0
        protected virtual async Task <BundleCacheData> BuildBundleAsync(IBundleModel bundle, QueryString query, IDictionary <string, StringValues> @params, HttpContext httpContext)
        {
            var startTicks = Stopwatch.GetTimestamp();

            var builderContext = new BundleBuilderContext
            {
                BundlingContext   = _bundlingContext,
                AppBasePath       = httpContext.Request.PathBase,
                Params            = @params,
                Bundle            = bundle,
                ChangeSources     = _enableChangeDetection ? new HashSet <IChangeSource>() : null,
                CancellationToken = httpContext.RequestAborted
            };

            bundle.OnBuilding(builderContext);

            await bundle.Builder.BuildAsync(builderContext);

            var            content   = bundle.OutputEncoding.GetBytes(builderContext.Result);
            DateTimeOffset timestamp = _clock.UtcNow;

            var versionProviderContext = new BundleVersionProviderContext
            {
                Timestamp         = timestamp,
                Content           = content,
                CancellationToken = httpContext.RequestAborted
            };

            _versionProvider.Provide(versionProviderContext);

            bundle.OnBuilt(builderContext);

            var endTicks = Stopwatch.GetTimestamp();

            if (_logger.IsEnabled(LogLevel.Information))
            {
                var elapsedMs = (endTicks - startTicks) / (Stopwatch.Frequency / 1000);
                _logger.LogInformation("Bundle [{MANAGER_ID}]:{PATH}{QUERY} was built in {ELAPSED}ms.", _id, bundle.Path, query, elapsedMs);
            }

            return(new BundleCacheData
            {
                Content = content,
                Timestamp = timestamp,
                Version = versionProviderContext.Result,
            });
        }
예제 #4
0
        protected virtual async Task <BundleCacheData> BuildBundleAsync(IBundleModel bundle, QueryString query, IDictionary <string, StringValues> @params, HttpContext httpContext)
        {
            var startTicks = Stopwatch.GetTimestamp();

            var builderContext = new BundleBuilderContext
            {
                BundlingContext = _bundlingContext,
                HttpContext     = httpContext,
                Params          = @params,
                Bundle          = bundle,
            };

            await bundle.Builder.BuildAsync(builderContext);

            var content   = bundle.OutputEncoding.GetBytes(builderContext.Result);
            var timestamp = _clock.UtcNow;

            var versionProviderContext = new BundleVersionProviderContext
            {
                HttpContext = httpContext,
                Timestamp   = timestamp,
                Content     = content,
            };

            _versionProvider.Provide(versionProviderContext);

            var endTicks = Stopwatch.GetTimestamp();

            if (_logger.IsEnabled(LogLevel.Information))
            {
                var elapsedMs = (endTicks - startTicks) / (Stopwatch.Frequency / 1000);
                _logger.LogInformation("Bundle instance [{MANAGER_ID}]:{PATH}{QUERY} was built in {ELAPSED}ms.", _id, bundle.Path, query, elapsedMs);
            }

            return(new BundleCacheData
            {
                Content = content,
                Timestamp = timestamp,
                Version = versionProviderContext.Result,
            });
        }
예제 #5
0
        protected virtual async Task <BundleCacheData> BuildBundleAsync(IBundleModel bundle, QueryString query, IDictionary <string, StringValues> @params, HttpContext httpContext)
        {
            var builderContext = new BundleBuilderContext
            {
                BundlingContext   = _bundlingContext,
                AppBasePath       = httpContext.Request.PathBase,
                Params            = @params,
                Bundle            = bundle,
                ChangeSources     = _enableChangeDetection ? new HashSet <IChangeSource>() : null,
                CancellationToken = httpContext.RequestAborted
            };

            bundle.OnBuilding(builderContext);

            await bundle.Builder.BuildAsync(builderContext);

            var            content   = bundle.OutputEncoding.GetBytes(builderContext.Result);
            DateTimeOffset timestamp = _clock.UtcNow;

            var versionProviderContext = new BundleVersionProviderContext
            {
                Timestamp         = timestamp,
                Content           = content,
                CancellationToken = httpContext.RequestAborted
            };

            _versionProvider.Provide(versionProviderContext);

            bundle.OnBuilt(builderContext);

            return(new BundleCacheData
            {
                Content = content,
                Timestamp = timestamp,
                Version = versionProviderContext.Result,
            });
        }