Exemple #1
0
        public Task InvokeAsync(IQuidjiboContext context, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogDebug("The pipeline was canceled.");
                return(Task.CompletedTask);
            }

            _running.TryGetValue(context, out var steps);
            if (steps == null || steps.Count == 0)
            {
                _logger.LogDebug("The pipeline is complete.");
                return(Task.CompletedTask);
            }

            var step = steps.Dequeue();

            if (step.Instance == null)
            {
                _logger.LogDebug("resolving {0}", step.Type);
                step.Instance = (IQuidjiboMiddleware)context.Resolver.Resolve(step.Type);
            }

            return(step.Instance.InvokeAsync(context, () => InvokeAsync(context, cancellationToken), cancellationToken));
        }
Exemple #2
0
        public async Task InvokeAsync(IQuidjiboContext context, Func <Task> next, CancellationToken cancellationToken)
        {
            var logger  = context.LoggerFactory.CreateLogger <QuidjiboUnwrapMiddleware>();
            var payload = await context.Protector.UnprotectAsync(context.Item.Payload, cancellationToken);

            context.Command = await context.Serializer.DeserializeAsync(payload, cancellationToken);

            logger.LogDebug("{0} was set on the context.", context.Command.GetQualifiedName());
            await next();
        }
        public async Task InvokeAsync(IQuidjiboContext context, Func <Task> next, CancellationToken cancellationToken)
        {
            var logger  = context.LoggerFactory.CreateLogger <QuidjiboUnwrapMiddleware>();
            var payload = await context.Protector.UnprotectAsync(context.Item.Payload, cancellationToken);

            context.Command = await context.Serializer.DeserializeAsync(payload, cancellationToken);

            var correlationId = context.Item.CorrelationId;

            using (logger.BeginScope(new Dictionary <string, object> {
                ["CorrelationId"] = correlationId
            }))
            {
                logger.LogDebug("{Command} was set on the context.", context.Command.GetQualifiedName());
                await next();
            }
        }
Exemple #4
0
        public async Task StartAsync(IQuidjiboContext context, CancellationToken cancellationToken)
        {
            _running.Add(context, new Queue <PipelineStep>(_steps.Where(x => x != null)
                                                           .Select(x => new PipelineStep
            {
                Type     = x.Type,
                Instance = x.Instance
            })));
            using (_resolver.Begin())
            {
                context.Protector     = _protector;
                context.Dispatcher    = _dispatcher;
                context.LoggerFactory = _loggerFactory;
                context.Serializer    = _serializer;
                context.Resolver      = _resolver;

                await InvokeAsync(context, cancellationToken);
            }
        }
        public async Task InvokeAsync(IQuidjiboContext context, Func <Task> next, CancellationToken cancellationToken)
        {
            var logger = context.LoggerFactory.CreateLogger <QuidjiboHandlerMiddleware>();

            if (context.Command is WorkflowCommand workflow)
            {
                var tasks = workflow.Entries.Where(e => e.Key == workflow.CurrentStep)
                            .SelectMany(e => e.Value, (e, c) => context.Dispatcher.DispatchAsync(c, context.Progress, cancellationToken))
                            .ToList();
                await Task.WhenAll(tasks);

                workflow.NextStep();
                if (workflow.CurrentStep < workflow.Step)
                {
                    var nextPayload = await context.Serializer.SerializeAsync(workflow, cancellationToken);

                    var protectedPayload = await context.Protector.ProtectAsync(nextPayload, cancellationToken);

                    var nextItem = new WorkItem
                    {
                        Id            = Guid.NewGuid(),
                        CorrelationId = context.Item.CorrelationId,
                        Attempts      = 0,
                        Name          = workflow.GetName(),
                        Payload       = protectedPayload,
                        Queue         = context.Item.Queue
                    };
                    logger.LogDebug("Enqueue the next workflow step : {Id}", nextItem.Id);
                    await context.WorkProvider.SendAsync(nextItem, 0, cancellationToken);
                }
            }
            else
            {
                await context.Dispatcher.DispatchAsync(context.Command, context.Progress, cancellationToken);
            }

            await next();
        }
Exemple #6
0
 public Task EndAsync(IQuidjiboContext context)
 {
     _running.Remove(context);
     return(Task.CompletedTask);
 }
 public Task InvokeAsync(IQuidjiboContext context, Func <Task> next, CancellationToken cancellationToken)
 {
     return(_func.Invoke(context, next));
 }
Exemple #8
0
 public Task InvokeAsync(IQuidjiboContext context, Func <Task> next, CancellationToken cancellationToken)
 {
     Invoked = true;
     return(next());
 }