public ExternalCancellationTokenScope(BundleBuilderContext context, CancellationToken externalCancellationToken) { _context = context; _originalCancellationToken = context.CancellationToken; _linkedCts = CancellationTokenSource.CreateLinkedTokenSource(_originalCancellationToken, externalCancellationToken); context.CancellationToken = _linkedCts.Token; }
public void Dispose() { BundleBuilderContext context = Interlocked.Exchange(ref _context, null); if (context != null) { _linkedCts.Dispose(); context.CancellationToken = _originalCancellationToken; } }
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, }); }
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, }); }
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, }); }