Exemple #1
0
        public async Task <InteractionResult> ExecuteAsync(InteractConfig config, NameValueCollection inputs = null, string target = null)
        {
            var targets = config.Targets;

            if (string.IsNullOrEmpty(target))
            {
                target = config.DefaultTarget;
            }

            if (string.IsNullOrEmpty(target))
            {
                throw new Exception("No target is specified.");
            }

            var entranceTarget = targets.FirstOrDefault(t => t.Name.Equals(target, StringComparison.OrdinalIgnoreCase));

            if (entranceTarget == null)
            {
                throw new Exception("target cannot be found:" + target);
            }

            var context = new InterationContext();

            context.Inputs      = inputs;
            context.WebAccessor = this.serviceProvider.GetService <IWebAccessor>();

            return(await ExecuteTargetAsync(entranceTarget, context, targets));
        }
        protected string GetValue(InterationContext context, string property)
        {
            if (property.StartsWith("$(") && property.EndsWith(")"))
            {
                var inputPropertyName = property.Substring(1, property.Length - 3);
                return(GetInputValue(context.Inputs, inputPropertyName));
            }

            if (property.StartsWith("${") && property.EndsWith("}"))
            {
                var outputPropertyName = property.Substring(1, property.Length - 3);
                return(GetOutputValue(context.Outputs, outputPropertyName));
            }

            return(string.Empty);
        }
        protected string PrepareValue(InterationContext context, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(string.Empty);
            }

            while (true)
            {
                var pos    = value.IndexOf("${");
                var endPos = -1;

                if (pos >= 0)
                {
                    endPos = value.IndexOf("}", pos);

                    if (endPos >= 0)
                    {
                        var outputPropertyName = value.Substring(pos, endPos - pos - 2);
                        value = value.Substring(0, pos) + GetOutputValue(context.Outputs, outputPropertyName) + value.Substring(endPos + 1);
                        continue;
                    }
                }

                pos = value.IndexOf("$(");

                if (pos >= 0)
                {
                    endPos = value.IndexOf(")", pos);

                    if (endPos >= 0)
                    {
                        var inputPropertyName = value.Substring(pos, endPos - pos - 2);
                        value = value.Substring(0, pos) + GetOutputValue(context.Inputs, inputPropertyName) + value.Substring(endPos + 1);
                        continue;
                    }
                }

                break;
            }

            return(value);
        }
 public abstract Task <InteractionResult> ExecuteAsync(InterationContext context);
Exemple #5
0
        private async Task <InteractionResult> ExecuteTargetAsync(TargetConfig target, InterationContext context, TargetConfig[] allTargets)
        {
            var actions = target.Actions.Select(x => x.GetAction());

            var lastResult = default(InteractionResult);

            foreach (var action in actions)
            {
                var result = lastResult = await action.ExecuteAsync(context);

                if (!result.Ok)
                {
                    break;
                }

                if (string.IsNullOrEmpty(result.Target))
                {
                    continue;
                }

                var callTarget = allTargets.FirstOrDefault(t => t.Name.Equals(result.Target, StringComparison.OrdinalIgnoreCase));

                if (callTarget == null)
                {
                    throw new Exception("callTarget cannot be found:" + result.Target);
                }

                result = lastResult = await ExecuteTargetAsync(callTarget, context, allTargets);

                if (!result.Ok)
                {
                    break;
                }
            }

            lastResult.Outputs = context.Outputs;

            return(lastResult);
        }