Exemplo n.º 1
0
        public virtual async ValueTask <InvokeId> Start(IIdentifier stateId, IExecutionContext executionContext, CancellationToken token)
        {
            if (stateId is null)
            {
                throw new ArgumentNullException(nameof(stateId));
            }
            if (executionContext is null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }

            var invokeId = InvokeId.New(stateId, _invoke.Id);

            if (IdLocationEvaluator is not null)
            {
                await IdLocationEvaluator.SetValue(invokeId, executionContext, token).ConfigureAwait(false);
            }

            var type = TypeExpressionEvaluator is not null?ToUri(await TypeExpressionEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false)) : _invoke.Type;

            var source = SourceExpressionEvaluator is not null?ToUri(await SourceExpressionEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false)) : _invoke.Source;

            var rawContent = ContentBodyEvaluator is IStringEvaluator rawContentEvaluator ? await rawContentEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false) : null;

            var content = await DataConverter.GetContent(ContentBodyEvaluator, ContentExpressionEvaluator, executionContext, token).ConfigureAwait(false);

            var parameters = await DataConverter.GetParameters(NameEvaluatorList, ParameterList, executionContext, token).ConfigureAwait(false);

            Infra.NotNull(type);

            var invokeData = new InvokeData(invokeId, type)
            {
                Source     = source,
                RawContent = rawContent,
                Content    = content,
                Parameters = parameters
            };

            await executionContext.StartInvoke(invokeData, token).ConfigureAwait(false);

            return(invokeId);
        }
Exemplo n.º 2
0
        public virtual async ValueTask Execute(IExecutionContext executionContext, CancellationToken token)
        {
            if (executionContext is null)
            {
                throw new ArgumentNullException(nameof(executionContext));
            }

            var sendId = _send.Id is not null?SendId.FromString(_send.Id) : SendId.New();

            if (IdLocationEvaluator is not null)
            {
                await IdLocationEvaluator.SetValue(sendId, executionContext, token).ConfigureAwait(false);
            }

            var name = EventExpressionEvaluator is not null ? await EventExpressionEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false) : _send.EventName;

            var data = await DataConverter.GetData(ContentBodyEvaluator, ContentExpressionEvaluator, NameEvaluatorList, ParameterList, executionContext, token).ConfigureAwait(false);

            var type = TypeExpressionEvaluator is not null?ToUri(await TypeExpressionEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false)) : _send.Type;

            var target = TargetExpressionEvaluator is not null?ToUri(await TargetExpressionEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false)) : _send.Target;

            var delayMs = DelayExpressionEvaluator is not null ? await DelayExpressionEvaluator.EvaluateInteger(executionContext, token).ConfigureAwait(false) : _send.DelayMs ?? 0;

            var eventEntity = new EventEntity(name)
            {
                SendId  = sendId,
                Type    = type,
                Target  = target,
                DelayMs = delayMs,
                Data    = data
            };

            if (ContentBodyEvaluator is IStringEvaluator rawContentEvaluator)
            {
                eventEntity.RawData = await rawContentEvaluator.EvaluateString(executionContext, token).ConfigureAwait(false);
            }

            await executionContext.Send(eventEntity, token).ConfigureAwait(false);
        }