示例#1
0
        public async Task <NotifactionPipelineExecutionResults> Execute(NotifcationTrigger trigger)
        {
            _logger.LogDebug("start of {name} pipeline", Name);

            if (TriggerIdentifier != trigger.GetTypeIdentifier())
            {
                _logger.LogDebug("type mismatch. Expected a trigger of {type} but received {otherType}", TriggerIdentifier, trigger.GetTypeIdentifier());
                return(NotifactionPipelineExecutionResults.TriggerNotMatch);
            }

            if (Condition != NotificationCondition.True)
            {
                if (await Condition.IsValid(trigger) == false)
                {
                    _logger.LogDebug("the trigger doens't satisfy the condition. Execution of pipeline stopped");
                    return(NotifactionPipelineExecutionResults.ConditionNotMatched);
                }
                else
                {
                    _logger.LogDebug("the trigger {trgger} meet the condtion {condition}", trigger, Condition);
                }
            }
            else
            {
                _logger.LogDebug("no conditions applied. actor enabled");
            }

            _logger.LogDebug("executing actor...");
            try
            {
                Boolean actorResult = await Actor.Handle(trigger);

                if (actorResult == false)
                {
                    _logger.LogError("Actor {actor} of pipeline {name} failed.", Actor, Name);
                    return(NotifactionPipelineExecutionResults.ActorFailed);
                }

                return(NotifactionPipelineExecutionResults.Success);
            }
            catch (Exception ex)
            {
                _logger.LogError("unable to execute actor", ex.ToString());
                return(NotifactionPipelineExecutionResults.ActorFailed);
            }
        }
示例#2
0
 internal protected abstract Task <Boolean> Handle(NotifcationTrigger trigger);
示例#3
0
 public abstract Task<Boolean> IsValid(NotifcationTrigger trigger);
示例#4
0
 public bool CanExecute(NotifcationTrigger trigger) => trigger.GetTypeIdentifier() == TriggerIdentifier;
示例#5
0
 public override Task<Boolean> IsValid(NotifcationTrigger trigger) => Task.FromResult(true);