private async Task <string> ExecuteKHideNodeAsync(KHideNode node, Dictionary <string, AliasReference> classNameAlias, bool isRepeat)
        {
            try
            {
                dynamic result = await evaluator.EvaluateExpressionAsync(node.Expression, classNameAlias);

                if (result.GetType() == typeof(bool) && !result)
                {
                    return(await ProcessNodesAsync(node.Children, classNameAlias, isRepeat));
                }
            }
            catch (Exception e)
            {
                CacheableResult = false;
            }
            return("");
        }
Ejemplo n.º 2
0
        private HtmlNode ProcessExtractBlocksNode(HtmlNode node)
        {
            HtmlNode returnNode = node;

            bool isKTag = false;

            if (nodeNameBlockDescriptors.Contains(node.Name))
            {
                if (node.Name.Equals(LanguageAttributes.KScript.GetDescription().ToLower()))
                {
                    var       apiUrl          = decodeExpression(node.GetAttributeValue("get-api", null));
                    var       input           = node.GetAttributeValue("input", null);
                    var       headers         = node.GetAttributeValue("headers", null)?.Trim()?.Trim('[')?.Trim(']');
                    string    cacheEnabledStr = node.GetAttributeValue("cacheenabled", null);
                    BlockNode bNode           = new KScriptNode(apiUrl, input, headers, cacheEnabledStr);
                    HtmlNode  tempNode        = node.OwnerDocument.CreateTextNode(GenerateBlockIdentifier());
                    returnNode = tempNode;
                    blockNodeReferenceList.Add(currentBlockNumber, bNode);
                    node.ParentNode.InsertAfter(tempNode, node);
                    node.Remove();
                    var htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml("<div></div>");
                    HtmlNode newNode = htmlDoc.DocumentNode.FirstChild;
                    newNode.AppendChildren(node.ChildNodes);

                    bNode.Children.AddRange(GetNodes(newNode, true));
                    return(tempNode);
                }
                else if (node.Name.Equals(LanguageAttributes.KTag.GetDescription().ToLower()))
                {
                    isKTag = true;
                }
                //Removed the srcset as its domain specific (some cdn was not configured so that it was not working on some domain)
                //else if (node.Name.Equals("img"))
                //{
                //    if (node.Attributes.Any(x => "src" == x.Name?.ToLower()))
                //    {
                //        node.Attributes.Remove("srcset");
                //        node.Attributes.Add("srcset", $"[[getSrcSet({node.Attributes["src"].Value.Replace(@"[[", @"\[\[").Replace(@"]]", @"\]\]")})]]");
                //    }
                //}
            }

            List <HtmlAttribute> attributeList = node.Attributes.Where(x => attributeNameBlockDescriptors.Contains(x.Name)).ToList();

            if (attributeList.Count > 0)
            {
                HtmlAttribute repeatAttribute = null;
                repeatAttribute = attributeList.FirstOrDefault(x => x.Name == LanguageAttributes.KRepeat.GetDescription().ToLower());
                foreach (HtmlAttribute attribute in attributeList)
                {
                    BlockNode blockNode = null;
                    switch (attribute.Name.ToLower())
                    {
                    case "k-show":
                        blockNode = new KShowNode(decodeExpression(attribute.Value.Replace("[[", "").Replace("]]", "")));
                        break;

                    case "k-hide":
                        blockNode = new KHideNode(decodeExpression(attribute.Value.Replace("[[", "").Replace("]]", "")));
                        break;

                    case "k-pay-amount":
                    {
                        node.Attributes.Add("k-pay-checksum", $"[[getChecksum({attribute.Value.Replace("[[", "").Replace("]]", "")})]]");
                    }
                    break;

                    case "k-norepeat":
                        blockNode = new KNoRepeatNode();
                        break;
                    }
                    if (blockNode != null)
                    {
                        attribute.Remove();
                        if (node.ParentNode != null)
                        {
                            HtmlNode tempNode = node.OwnerDocument.CreateTextNode(GenerateBlockIdentifier());
                            blockNodeReferenceList.Add(currentBlockNumber, blockNode);
                            node.ParentNode.InsertAfter(tempNode, node);
                            node.Remove();
                            //exclude the top node if isKtag to remove ktag node
                            blockNode.Children.AddRange(GetNodes(node, isKTag && repeatAttribute == null ? true : false));
                            return(tempNode);
                        }
                        else
                        {
                            return(HtmlNode.CreateNode("<!-- Invalid node -->"));
                        }
                    }
                }

                if (repeatAttribute != null)
                {
                    var repeatNode = ProcessRepeatNode(node, repeatAttribute, isKTag);
                    if (repeatNode != null)
                    {
                        return(repeatNode);
                    }
                }
            }
            return(returnNode);
        }