示例#1
0
        public async Task <object> Invoke(object context)
        {
            var evaluationContext = new ContextFrame {
                Scope = context, Step = this,
            };

            // check the existence of the object
            var check = false;

            try
            {
                await Interpolate(Name);

                check = true;
            }
            catch (Exception)
            {
            }

            if (!check)
            {
                // create list if not exist
                var List = new List <dynamic>();
                await Interpolator.AssignValueOnDynamic(context, Name, List);
            }

            var expressionValue = await Interpolate(Expression);

            var result = await AppendValueOnDynamic(Name, expressionValue);

            Task <object> Interpolate(string expression) => Interpolator.InterpolateExpression(expression, evaluationContext);
            Task <object> AppendValueOnDynamic(string name, dynamic value) => Interpolator.AppendValueOnDynamic(context, name, value);

            return(result);
        }
示例#2
0
        public async Task <object> Invoke(object context)
        {
            dynamic ctx = context;

            foreach (var item in Items)
            {
                var itemResult = await item.Invoke(context);

                if (item.Definition.ContainsKey("_resultTo"))
                {
                    var contextFrame = new ContextFrame {
                        Scope = context, Step = this
                    };
                    var key = item.Definition["_resultTo"];
                    await Interpolator.AssignValueOnDynamic(context, key, itemResult);
                }
            }
            return(await Task.FromResult((object)true));
        }
示例#3
0
        public async Task <object> Invoke(object context)
        {
            dynamic ctx          = context;
            var     contextFrame = new ContextFrame {
                Scope = context, Step = this
            };
            var items = await Interpolator.InterpolateExpression(InExpression, contextFrame);

            var varName = VarName ?? "Scope.Item";

            if (items is IEnumerable itemsCollection)
            {
                foreach (var item in itemsCollection)
                {
                    await Interpolator.AssignValueOnDynamic(context, varName, item);

                    await LoopTask.Invoke(context);
                }
            }

            return(true);
        }
示例#4
0
        public async Task <object> Invoke(object context)
        {
            var evaluationContext = new ContextFrame {
                Scope = context, Step = this,
            };

            if (!(Expression is string))
            {
                // get result object
                //var resultObject = Interpolate(Name).Result;
                //var resultList = new List<dynamic>();

                try
                {
                    var dictionary = (IDictionary <string, dynamic>)Expression;
                    await AssignValueOnDynamic(Name, new System.Dynamic.ExpandoObject());

                    //context.Result = new System.Dynamic.ExpandoObject();

                    //var iss = new System.Dynamic.ExpandoObject();

                    foreach (var expressionItem in dictionary)
                    {
                        if (expressionItem.Value is string)
                        {
                            await AssignValue(expressionItem.Value, Name + "." + expressionItem.Key);
                        }
                        else if (expressionItem.Value is object)
                        {
                            try
                            {
                                var dc = (IDictionary <string, dynamic>)expressionItem.Value;

                                dynamic selector;
                                dynamic expression;

                                if (dc.TryGetValue("selector", out selector))
                                {
                                    var definition = new Dictionary <string, dynamic>()
                                    {
                                        { "from", FromNode }, { "selector", selector }
                                    };
                                    SelectNodes.InitializeFromJson(definition);
                                    var result = SelectNodes.Invoke(context).Result;


                                    if (dc.TryGetValue("expression", out expression))
                                    {
                                        var expressionValue = "";
                                        if (result != null)
                                        {
                                            var ResultContext = new Marshal()
                                            {
                                                Result = result
                                            };
                                            expressionValue = await Interpolator.InterpolateExpression(expression, ResultContext);
                                        }

                                        await AssignValueOnDynamic(Name + "." + expressionItem.Key, expressionValue);
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                await AssignValue(Expression, Name);
            }

            async Task <object> AssignValue(string expression, string name)
            {
                var expressionValue = await Interpolate(expression);

                return(await AssignValueOnDynamic(name, expressionValue));
            }

            Task <object> Interpolate(string expression) => Interpolator.InterpolateExpression(expression, evaluationContext);
            Task <object> AssignValueOnDynamic(string name, dynamic expressionValue) => Interpolator.AssignValueOnDynamic(context, name, expressionValue);

            return(Name);
        }