Exemplo n.º 1
0
        public async Task <object> Invoke(object context)
        {
            var contextFrame = new ContextFrame {
                Scope = context, Step = this
            };
            var url = (string) await interpolate(UrlExpression);

            var console = (bool) await interpolate(ConsoleWrite);

            url = HttpUtility.HtmlDecode(url);

            var isJSON = (bool) await interpolate(IsJSONExpression);

            var client = new HttpClient();

            if (console)
            {
                Console.WriteLine($"Request with HTTP GET from: ${url}... hold your horses.");
            }
            var response = await client.GetAsync(url);

            var resultString = await response.Content.ReadAsStringAsync();

            if (!isJSON)
            {
                return(resultString);
            }
            return(JsonConvert.DeserializeObject <dynamic>(resultString));

            Task <object> interpolate(string expression) => Interpolator.InterpolateExpression(expression, contextFrame);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public async Task <object> Invoke(object context)
        {
            var interpolatedMessage = await Interpolator.InterpolateExpression(MessageExpression,
                                                                               new ContextFrame { Scope = context, Step = this });

            Console.WriteLine(interpolatedMessage);
            return(interpolatedMessage);
        }
Exemplo n.º 4
0
        public async Task <object> Invoke(object context)
        {
            var durationValue = await interpolate(DurationExpression, new ContextFrame { Scope = context, Step = this });

            await Task.Delay((int)durationValue);

            return((int)durationValue);

            Task <object> interpolate <T>(string expression, T contextFrame) => Interpolator.InterpolateExpression(expression, contextFrame);
        }
Exemplo n.º 5
0
        public async Task <object> Invoke(object context)
        {
            var expressionValue = await interpolate(Expression, new ContextFrame { Scope = context, Step = this });

            await interpolate($"{Name} = Marshal.Result", new ContextAssignmentFrame(context, expressionValue));

            return(true);

            Task <object> interpolate <T>(string expression, T contextFrame) => Interpolator.InterpolateExpression(expression, contextFrame);
        }
Exemplo n.º 6
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 key = item.Definition["_resultTo"];
                    await Interpolator.InterpolateExpression($"{key} = Marshal.Result",
                                                             new ContextAssignmentFrame { Scope = context, Marshal = new Marshal {
                                                                                              Result = itemResult
                                                                                          } });
                }
            }
            return(await Task.FromResult((object)true));
        }
Exemplo n.º 7
0
        public async Task <object> Invoke(object context)
        {
            // get html text
            var contextFrame = new ContextFrame {
                Scope = context, Step = this
            };
            var htmlString = (string) await interpolate(HtmlExpression);


            // parse html to document object
            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(htmlString);

            htmlDoc.OptionAutoCloseOnEnd = true;

            return(htmlDoc);

            Task <object> interpolate(string expression) => Interpolator.InterpolateExpression(expression, contextFrame);
        }
Exemplo n.º 8
0
        public async Task <object> Invoke(object context)
        {
            // get html text
            var contextFrame = new ContextFrame {
                Scope = context, Step = this
            };
            var htmlDoc = (HtmlDocument) await interpolate(DocumentNode);

            //var selector = (string)await interpolate(Selector);

            // run selector
            HtmlNodeCollection nodes = htmlDoc.DocumentNode
                                       .SelectNodes(Selector);

            // run ndoe expression
            //var nodeContextFrame = new NodeContextFrame { NodeList = nodes };
            //return await Interpolator.InterpolateExpression(NodeExpression, nodeContextFrame);
            return(nodes);

            Task <object> interpolate(string expression) => Interpolator.InterpolateExpression(expression, contextFrame);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }