示例#1
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var result = new TextEvulateResult();

            result.Result = TextEvulateResultEnum.EVULATE_DEPTHSCAN;
            return(result);
        }
示例#2
0
            public override TextEvulateResult Render(TextElement tag, object vars)
            {
                TextEvulateResult result = new TextEvulateResult();

                result.TextContent = $"<{tag.ElemName.ToLowerInvariant()}>" + tag.Inner() + $"</{tag.ElemName.ToLowerInvariant()}>";
                result.Result      = TextEvulateResultEnum.EVULATE_TEXT;
                return(result);
            }
        public override void RenderFinish(TextElement tag, object vars, TextEvulateResult latestResult)
        {
            ColoredInfo info = this.Evulator.CustomDataSingle as ColoredInfo;

            //Mevcut tag içerisindeki işlem bittiğinde bir önceki ayarı geri atıyoruz.
            info.Font = new Font(info.Font, lastStyle);
            base.RenderFinish(tag, vars, latestResult);
        }
示例#4
0
            public override TextEvulateResult Render(TextElement tag, object vars)
            {
                TextEvulateResult result = new TextEvulateResult();

                result.TextContent = $"<a href=\"{tag.TagAttrib}\">" + tag.InnerText() + "</a>";
                result.Result      = TextEvulateResultEnum.EVULATE_TEXT;
                return(result);
            }
示例#5
0
            public override TextEvulateResult Render(TextElement tag, object vars)
            {
                TextEvulateResult result = new TextEvulateResult();

                result.TextContent = "Custom*: " + tag.Inner();
                result.Result      = TextEvulateResultEnum.EVULATE_TEXT;
                return(result);
            }
示例#6
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var result = new TextEvulateResult
            {
                Result = TextEvulateResultEnum.EVULATE_BREAK
            };

            return(result);
        }
示例#7
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var result = new TextEvulateResult();

            if (tag.ElementType != TextElementType.Parameter)
            {
                result.Result = TextEvulateResultEnum.EVULATE_NOACTION;
                return(result);
            }
            result.TextContent += this.EvulateText(tag.ElemName, vars);
            return(result);
        }
示例#8
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            this.BBCodeEvulator = this.Evulator.CustomDataSingle as BBCodeEvulator;

            TextEvulateResult result = new TextEvulateResult()
            {
                Result = TextEvulateResultEnum.EVULATE_DEPTHSCAN
            };

            if (tag.AutoClosed && tag.SubElementsCount == 0)
            {
                return(result);
            }
            var bbcodeInfo = this.BBCodeEvulator.GetTag(tag.ElemName);

            if (bbcodeInfo == null || !bbcodeInfo.Enabled)
            {
                return(result);
            }

            Type defaultHandlertype = typeof(BBCodeDefaultHandler);

            if (bbcodeInfo.CustomHandler != null)
            {
                defaultHandlertype = bbcodeInfo.CustomHandler;
            }
            this.Handler            = Activator.CreateInstance(defaultHandlertype) as BBCodeDefaultHandler;
            this.Handler.BBCodeInfo = bbcodeInfo;
            this.Handler.Element    = tag;
            this.Handler.TagVars    = vars;
            this.Handler.TagStart();
            if (this.Handler.Result.Handled)
            {
                var data = this.GetData(tag);
                data.Text     = this.Handler.Result.Text;
                result.Result = TextEvulateResultEnum.EVULATE_TEXT;
                var validateResult = bbcodeInfo.Validate(data, tag);
                if (validateResult != null && validateResult.Cancel)
                {
                    result.TextContent = null;
                }
                else
                {
                    result.TextContent = bbcodeInfo.TagFormat.Apply(data);
                }
            }
            else
            {
                result.TextContent = this.Handler.Result.Text;
            }
            return(result);
        }
示例#9
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var total = tag.GetAttribute("count");

            if (string.IsNullOrEmpty(total))
            {
                return(null);
            }
            var toResult = this.EvulateText(total, vars);

            if (!TypeUtil.IsNumericType(toResult))
            {
                return(null);
            }
            int tonum = (int)Convert.ChangeType(toResult, TypeCode.Int32);

            if (tonum < 1)
            {
                return(null);
            }
            var varname = tag.GetAttribute("current_repeat");
            var result  = new TextEvulateResult();
            var svar    = new KeyValues <object>();

            this.Evulator.LocalVariables.Add(svar);
            for (int i = 0; i < tonum; i++)
            {
                svar[varname] = i;
                var cresult = tag.EvulateValue(0, 0, vars);
                if (cresult == null)
                {
                    continue;
                }
                result.TextContent += cresult.TextContent;
                if (cresult.Result == TextEvulateResultEnum.EVULATE_RETURN)
                {
                    result.Result = TextEvulateResultEnum.EVULATE_RETURN;
                    this.Evulator.LocalVariables.Remove(svar);
                    return(result);
                }
                else if (cresult.Result == TextEvulateResultEnum.EVULATE_BREAK)
                {
                    break;
                }
            }
            this.Evulator.LocalVariables.Remove(svar);
            result.Result = TextEvulateResultEnum.EVULATE_TEXT;
            return(result);
        }
示例#10
0
        private TextEvulateResult Render_Parse(TextElement tag, object vars)
        {
            var loc = tag.GetAttribute("name");

            loc = this.EvulateText(loc)?.ToString();
            if (!this.ConditionSuccess(tag, "if") || !File.Exists(loc))
            {
                return(null);
            }
            string xpath    = tag.GetAttribute("xpath");
            bool   xpathold = false;

            if (string.IsNullOrEmpty(xpath))
            {
                xpath    = tag.GetAttribute("xpath_old");
                xpathold = true;
            }

            var content = File.ReadAllText(loc);
            var result  = new TextEvulateResult();

            result.Result = TextEvulateResultEnum.EVULATE_NOACTION;
            tag.Parent.SubElements.Remove(tag);
            if (string.IsNullOrEmpty(xpath))
            {
                this.Evulator.Parse(tag.Parent, content);
            }
            else
            {
                var tempitem = new TextElement();
                tempitem.ElemName = "#document";
                this.Evulator.Parse(tempitem, content);
                TextElements elems = null;
                if (!xpathold)
                {
                    elems = tempitem.FindByXPath(xpath);
                }
                else
                {
                    elems = tempitem.FindByXPathOld(xpath);
                }
                for (int i = 0; i < elems.Count; i++)
                {
                    elems[i].Parent = tag.Parent;
                    tag.Parent.SubElements.Add(@elems[i]);
                }
            }
            return(result);
        }
示例#11
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var cr = this.ConditionSuccess(tag, "if");

            if (!cr)
            {
                return(null);
            }
            var result = new TextEvulateResult
            {
                Result = TextEvulateResultEnum.EVULATE_CONTINUE
            };

            return(result);
        }
示例#12
0
        public TextEvulateResult RenderDefault(TextElement tag, object vars)
        {
            var result = new TextEvulateResult();

            if (this.ConditionSuccess(tag))
            {
                var elseitem = tag.GetSubElement("elif", "else");
                if (elseitem != null)
                {
                    result.End = elseitem.Index;
                }
                result.Result = TextEvulateResultEnum.EVULATE_DEPTHSCAN;
            }
            else
            {
                var elseitem = tag.GetSubElement("elif", "else");
                while (elseitem != null)
                {
                    if (elseitem.ElemName == "else")
                    {
                        result.Start  = elseitem.Index + 1;
                        result.Result = TextEvulateResultEnum.EVULATE_DEPTHSCAN;
                        return(result);
                    }
                    else
                    {
                        if (this.ConditionSuccess(elseitem))
                        {
                            result.Start = elseitem.Index + 1;
                            var nextelse = elseitem.NextElementWN("elif", "else");
                            if (nextelse != null)
                            {
                                result.End = nextelse.Index;
                            }
                            result.Result = TextEvulateResultEnum.EVULATE_DEPTHSCAN;
                            return(result);
                        }
                    }
                    elseitem = elseitem.NextElementWN("elif", "else");
                }
                if (elseitem == null)
                {
                    return(result);
                }
            }
            return(result);
        }
示例#13
0
        public TextEvulateResult Render_ParseMode(TextElement tag, object vars)
        {
            var  result      = new TextEvulateResult();
            bool conditionok = this.ConditionSuccess(tag);
            bool sil         = false;

            for (int i = 0; i < tag.SubElementsCount; i++)
            {
                var sub = tag.SubElements[i];
                if (!conditionok || sil)
                {
                    if (!sil)
                    {
                        if (sub.ElemName == "else")
                        {
                            conditionok = true;
                        }
                        else if (sub.ElemName == "elif")
                        {
                            conditionok = this.ConditionSuccess(sub);
                        }
                    }

                    tag.SubElements.RemoveAt(i);
                    i--;
                    continue;
                }
                else
                {
                    if (sub.ElemName == "else" || sub.ElemName == "elif")
                    {
                        sil = true;
                        i--;
                        continue;
                    }
                    //sub.EvulateValue(0, 0, vars);
                    sub.Index  = tag.Parent.SubElements.Count;
                    sub.Parent = tag.Parent;
                    tag.Parent.SubElements.Add(sub);
                }
            }
            tag.Parent.SubElements.Remove(tag);
            result.Result = TextEvulateResultEnum.EVULATE_NOACTION;
            return(result);
        }
示例#14
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var         result    = new TextEvulateResult();
            var         condition = tag.GetAttribute("c");
            var         value     = this.EvulateText(condition);
            TextElement @default  = null;
            TextElement active    = null;

            for (int i = 0; i < tag.SubElementsCount; i++)
            {
                var elem = tag.SubElements[i];
                if (elem.ElemName == "default")
                {
                    @default = elem;
                    continue;
                }
                else if (elem.ElemName != "case")
                {
                    continue;
                }
                if (this.EvulateCase(elem, value?.ToString()))
                {
                    active = elem;
                    break;
                }
            }
            if (active == null)
            {
                active = @default;
            }
            if (active == null)
            {
                return(result);
            }
            var cresult = active.EvulateValue(0, 0, vars);

            result.TextContent += cresult.TextContent;
            if (cresult.Result == TextEvulateResultEnum.EVULATE_RETURN)
            {
                result.Result = TextEvulateResultEnum.EVULATE_RETURN;
                return(result);
            }
            result.Result = TextEvulateResultEnum.EVULATE_TEXT;
            return(result);
        }
示例#15
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var varname = tag.GetAttribute("var");
            var @in     = tag.GetAttribute("in");

            if (string.IsNullOrEmpty(varname) || @in == null)
            {
                return(null);
            }
            var inlist = this.EvulateText(@in);

            if (inlist == null || !(inlist is IEnumerable list))
            {
                return(null);
            }
            var svar = new KeyValues <object>();

            this.Evulator.LocalVariables.Add(svar);
            var result = new TextEvulateResult();

            foreach (var item in list)
            {
                svar[varname] = item;
                var cresult = tag.EvulateValue(0, 0, vars);
                if (cresult == null)
                {
                    continue;
                }
                result.TextContent += cresult.TextContent;
                if (cresult.Result == TextEvulateResultEnum.EVULATE_RETURN)
                {
                    result.Result = TextEvulateResultEnum.EVULATE_RETURN;
                    this.Evulator.LocalVariables.Remove(svar);
                    return(result);
                }
                else if (cresult.Result == TextEvulateResultEnum.EVULATE_BREAK)
                {
                    break;
                }
            }
            this.Evulator.LocalVariables.Remove(svar);
            result.Result = TextEvulateResultEnum.EVULATE_TEXT;
            return(result);
        }
示例#16
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            bool conditionok = this.ConditionSuccess(tag, "if");
            var  result      = new TextEvulateResult
            {
                Result = TextEvulateResultEnum.EVULATE_NOACTION
            };

            if (conditionok)
            {
                string defname = tag.GetAttribute("name");
                if (string.IsNullOrEmpty(defname))
                {
                    return(result);
                }
                this.Evulator.DefineParameters.Delete(defname);
            }
            return(result);
        }
示例#17
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            bool conditionok = this.ConditionSuccess(tag, "if");
            var  result      = new TextEvulateResult
            {
                Result = TextEvulateResultEnum.EVULATE_NOACTION
            };

            if (conditionok)
            {
                string defname = tag.GetAttribute("name");
                if (string.IsNullOrEmpty(defname) || !defname.All((c) => char.IsLetterOrDigit(c)))
                {
                    return(result);
                }
                string defvalue = tag.GetAttribute("value");
                this.Evulator.DefineParameters.Set(defname, this.EvulateText(defvalue));
            }
            return(result);
        }
 public override void RenderFinish(TextElement tag, object vars, TextEvulateResult latestResult)
 {
     //Render kısmında tamamlandıysa devam etmez.
     if (printed)
     {
         base.RenderFinish(tag, vars, latestResult);
         return;
     }
     if (customEvulatorHandler != null)
     {
         customEvulatorHandler.RenderFinish(tag, vars, latestResult);
     }
     else if (currentInfo != null && (currentInfo.Flags & BBCodeInfoFlags.InnerTextOnly) == 0 && currentInfo.Enabled)
     {
         var dict = this.GetDictionary(tag);
         dict["Text"] = latestResult.TextContent;
         var validateResult = currentInfo.Validate(dict, tag);
         if (validateResult != null && validateResult.Cancel)
         {
             latestResult.TextContent = null;
         }
         else
         {
             latestResult.TextContent = this.currentInfo.TagFormat.Apply(dict);
         }
     }
     else
     {
         //default
         if (tag.AutoClosed)
         {
             latestResult.TextContent = "[" + tag.ElemName + "]";
         }
         else
         {
             latestResult.TextContent = "[" + tag.ElemName + "]" + latestResult.TextContent + "[/" + tag.ElemName + "]";
         }
     }
     base.RenderFinish(tag, vars, latestResult);
 }
示例#19
0
 public override void RenderFinish(TextElement tag, object vars, TextEvulateResult latestResult)
 {
     if (this.Handler == null)
     {
         //default
         if (tag.AutoClosed)
         {
             latestResult.TextContent = "[" + tag.ElemName + "]";
         }
         else
         {
             latestResult.TextContent = "[" + tag.ElemName + "]" + latestResult.TextContent + "[/" + tag.ElemName + "]";
         }
         return;
     }
     if (this.Handler.Result.Handled)
     {
         base.RenderFinish(tag, vars, latestResult);
         return;
     }
     //Not continue if printed above.
     else
     {
         this.Handler.TagFinish(latestResult.TextContent);
         var data = this.GetData(tag);
         data.Text = this.Handler.Result.Text;
         var validateResult = this.Handler.BBCodeInfo.Validate(data, tag);
         if (validateResult != null && validateResult.Cancel)
         {
             latestResult.TextContent = null;
         }
         else
         {
             latestResult.TextContent = this.Handler.BBCodeInfo.TagFormat.Apply(data);
         }
     }
     base.RenderFinish(tag, vars, latestResult);
 }
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            this.bbCodeEvulator = this.Evulator.CustomDataSingle as BBCodeEvulator;
            TextEvulateResult result = new TextEvulateResult()
            {
                Result = TextEvulateResultEnum.EVULATE_DEPTHSCAN
            };
            var dict = this.GetDictionary(tag);

            currentInfo = this.bbCodeEvulator.GetTag(tag.ElemName);
            if (currentInfo == null)
            {
                return(result);
            }
            if (currentInfo.CustomEvulator != null)
            {
                customEvulatorHandler = Activator.CreateInstance(currentInfo.CustomEvulator) as BaseEvulator;
                customEvulatorHandler.SetEvulator(this.Evulator);
                result = customEvulatorHandler.Render(tag, vars);
            }
            else if ((currentInfo.Flags & BBCodeInfoFlags.InnerTextOnly) != 0 && currentInfo.Enabled && !tag.AutoClosed)
            {
                dict["Text"] = tag.InnerText();
                var validateResult = currentInfo.Validate(dict, tag);
                if (validateResult != null && validateResult.Cancel)
                {
                    result.TextContent = null;
                }
                else
                {
                    result.TextContent = currentInfo.TagFormat.Apply(dict);
                }

                result.Result = TextEvulateResultEnum.EVULATE_TEXT;
                printed       = true;
            }
            return(result);
        }
示例#21
0
        private TextEvulateResult Render_Default(TextElement tag, object vars)
        {
            var loc = tag.GetAttribute("name");

            loc = this.EvulateText(loc)?.ToString();
            var parse = tag.GetAttribute("parse", "true");

            if (!File.Exists(loc) || !this.ConditionSuccess(tag, "if"))
            {
                return(null);
            }
            var content = File.ReadAllText(loc);
            var result  = new TextEvulateResult();

            if (parse == "false")
            {
                result.Result      = TextEvulateResultEnum.EVULATE_TEXT;
                result.TextContent = content;
            }
            else
            {
                var tempelem = new TextElement
                {
                    ElemName     = "#document",
                    BaseEvulator = this.Evulator
                };
                var tempelem2 = new TextElement
                {
                    ElemName     = "#document",
                    BaseEvulator = this.Evulator
                };

                string xpath    = tag.GetAttribute("xpath");
                bool   xpathold = false;
                if (string.IsNullOrEmpty(xpath))
                {
                    xpath    = tag.GetAttribute("xpath_old");
                    xpathold = true;
                }

                this.Evulator.Parse(tempelem2, content);
                if (string.IsNullOrEmpty(xpath))
                {
                    tempelem = tempelem2;
                }
                else
                {
                    TextElements elems = null;
                    if (!xpathold)
                    {
                        elems = tempelem2.FindByXPath(xpath);
                    }
                    else
                    {
                        elems = tempelem2.FindByXPathOld(xpath);
                    }
                    for (int i = 0; i < elems.Count; i++)
                    {
                        elems[i].Parent = tempelem;
                        tempelem.SubElements.Add(elems[i]);
                    }
                }
                var cresult = tempelem.EvulateValue(0, 0, vars);
                result.TextContent += cresult.TextContent;
                if (cresult.Result == TextEvulateResultEnum.EVULATE_RETURN)
                {
                    result.Result = TextEvulateResultEnum.EVULATE_RETURN;
                    return(result);
                }
                result.Result = TextEvulateResultEnum.EVULATE_TEXT;
            }
            return(result);
        }
示例#22
0
 public override void RenderFinish(TextElement tag, object vars, TextEvulateResult latestResult)
 {
     latestResult.TextContent += "</div>";
     base.RenderFinish(tag, vars, latestResult);
 }
示例#23
0
        public override TextEvulateResult Render(TextElement tag, object vars)
        {
            var varname = tag.GetAttribute("var");
            var start   = tag.GetAttribute("start");
            var step    = tag.GetAttribute("step");

            if (string.IsNullOrEmpty(start))
            {
                start = "0";
            }
            if (step == null || step == "0")
            {
                step = "1";
            }
            var to = tag.GetAttribute("to");

            if (string.IsNullOrEmpty(varname) && string.IsNullOrEmpty(step) && string.IsNullOrEmpty(to))
            {
                return(null);
            }

            var startres = this.EvulateText(start);
            var stepres  = this.EvulateText(step);
            int startnum = 0;
            int stepnum  = 0;
            int tonum    = 0;

            if (!TypeUtil.IsNumericType(startres))
            {
                stepnum = 1;
            }
            else
            {
                stepnum = (int)Convert.ChangeType(stepres, TypeCode.Int32);
            }
            if (TypeUtil.IsNumericType(startres))
            {
                startnum = (int)Convert.ChangeType(startres, TypeCode.Int32);;
            }
            var tores = this.EvulateText(to);

            if (!TypeUtil.IsNumericType(tores))
            {
                return(null);
            }
            tonum = (int)Convert.ChangeType(tores, TypeCode.Int32);
            var result = new TextEvulateResult();
            var svar   = new KeyValues <object>();

            this.Evulator.LocalVariables.Add(svar);
            for (int i = startnum; i < tonum; i += stepnum)
            {
                svar[varname] = i;
                var cresult = tag.EvulateValue(0, 0, vars);
                if (cresult == null)
                {
                    continue;
                }
                result.TextContent += cresult.TextContent;
                if (cresult.Result == TextEvulateResultEnum.EVULATE_RETURN)
                {
                    result.Result = TextEvulateResultEnum.EVULATE_RETURN;
                    this.Evulator.LocalVariables.Remove(svar);
                    return(result);
                }
                else if (cresult.Result == TextEvulateResultEnum.EVULATE_BREAK)
                {
                    break;
                }
            }
            this.Evulator.LocalVariables.Remove(svar);
            result.Result = TextEvulateResultEnum.EVULATE_TEXT;
            return(result);
        }