Esempio n. 1
0
        public async Task ExecuteTasksAsync(DeferredTaskContext context)
        {
            for (var i = 0; i < _deferredTaskState.Tasks.Count; i++)
            {
                var task = _deferredTaskState.Tasks[i];

                try
                {
                    await task(context);
                }
                catch (Exception e)
                {
                    _logger.LogError("An error occured while processing a deferred task: {0}", e);
                }
            }

            _deferredTaskState.Tasks.Clear();
        }
Esempio n. 2
0
        public async Task Invoke(HttpContext httpContext)
        {
            await _next.Invoke(httpContext);

            // Register the shell settings as a custom feature.
            var shellSettings = httpContext.Features.Get <ShellSettings>();

            // We only serve the next request if the tenant has been resolved.
            if (shellSettings != null)
            {
                var shellContext = _KingHost.GetOrCreateShellContext(shellSettings);

                using (var scope = shellContext.CreateServiceScope())
                {
                    var deferredTaskEngine = scope.ServiceProvider.GetService <IDeferredTaskEngine>();

                    if (deferredTaskEngine != null && deferredTaskEngine.HasPendingTasks)
                    {
                        var context = new DeferredTaskContext(scope.ServiceProvider);
                        await deferredTaskEngine.ExecuteTasksAsync(context);
                    }
                }
            }
        }