Ejemplo n.º 1
0
        /// <summary>
        /// Internally parses tag and returns it from point when open bracket (&lt;) was found
        /// </summary>
        /// <returns>Chunk</returns>
        HTMLchunk GetNextTag()
        {
            //iCurPos++;

            oChunk = oTP.ParseTag(ref iCurPos);

            // for backwards compatibility mark closed tags with params as open
            if (oChunk.iParams > 0 && bAutoMarkClosedTagsWithParamsAsOpen && oChunk.oType == HTMLchunkType.CloseTag)
            {
                oChunk.oType = HTMLchunkType.OpenTag;
            }

            //                    012345
            // check for start of script
            if (oChunk.sTag.Length == 6 && oChunk.sTag[0] == 's' && oChunk.sTag == "script")
            {
                if (!oChunk.bClosure)
                {
                    oChunk.oType = HTMLchunkType.Script;
                    oChunk       = oTP.ParseScript(ref iCurPos);
                    return(oChunk);
                }
            }

            oChunk.iChunkLength = iCurPos - oChunk.iChunkOffset;

            if (bKeepRawHTML)
            {
                oChunk.oHTML = oEnc.GetString(bHTML, oChunk.iChunkOffset, oChunk.iChunkLength);
            }

            return(oChunk);
        }
Ejemplo n.º 2
0
        public Question PeackAnswer(int index)
        {
            if (index >= _currentQuestion.Answers.Length)
            {
                return(null);
            }

            Answer ans = _currentQuestion.Answers[index];

            if (ans.Tag.Length > 0)
            {
                ExecutePramsAnswer pramsAnswer = new ExecutePramsAnswer();
                pramsAnswer.state  = StateTag.OnPicked;
                pramsAnswer.answer = ans;
                pramsAnswer.ui     = null;
                tagParser.ParseTag(ans.Tag, pramsAnswer);
            }

            _currentQuestion = ans.Question;

            if (_currentQuestion != null)
            {
                OnQuestionChangedChanged?.Invoke(_currentQuestion);
            }

            return(_currentQuestion);
        }
Ejemplo n.º 3
0
        private void GnerateAnsers()
        {
            ClearPrevAnswers();
            int index = 0;

            foreach (var answer in _question.Answers)
            {
                if (answer == null)
                {
                    continue;
                }

                GameObject uiObj    = Instantiate(answerPrefab, transform);
                AnswerUI   answerUi = uiObj.GetComponent <AnswerUI>();
                answerUi.Init(index, answer.Text);
                answerUi.apearDelay = index * .3f;
                answerUi.OnPeacked += OnAnswePeacked;
                index++;

                if (answer.Tag.Length > 0)
                {
                    ExecutePramsAnswer pramsAnswer = new ExecutePramsAnswer();
                    pramsAnswer.state  = StateTag.OnShow;
                    pramsAnswer.answer = answer;
                    pramsAnswer.ui     = answerUi;
                    tagParser.ParseTag(answer.Tag, pramsAnswer);
                }
            }
        }
Ejemplo n.º 4
0
        public Tag ExecuteParseTag(string text)
        {
            var browseText = new BrowseText(text);
            var tagParser  = new TagParser(browseText);

            return(tagParser.ParseTag());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a readitem from a given Tag
        /// </summary>
        /// <param name="tag">Format:  [Area].[Offset],[Type],[Number Of Items  or in Case of bytes and strings the length of them]</param>
        /// <returns></returns>
        public static ReadItem CreateFromTag(string tag)
        {
            var tr       = TagParser.ParseTag(tag);
            var readItem = BuildReadItemFromTagResult(ref tr);

            EnsureSupportedType(readItem);
            return(readItem);
        }
Ejemplo n.º 6
0
        private static void ExtractStepInfo(Guide aGuide, Step aStep, string aFileContents, string aStepDirectory)
        {
            aStep.IsValid = true;

            bool validTitleFound      = false;
            bool validStepNumberFound = false;
            bool wasNewLine           = true;

            for (int index = 0; index < aFileContents.Length; index++)
            {
                var character = aFileContents[index];
                if (wasNewLine && character == '#')
                {
                    continue;
                }

                wasNewLine = character == '\r' || character == '\n';
                if (TagParser.ParseTag(aFileContents, ref index, out var tag, out var tagContent, out var attributes, isIncrementIndex: true))
                {
                    if (SimpleTags.IsTag(SimpleTags.Tag.Title, tag))
                    {
                        aStep.Title     = SimpleTags.GetContent <string>(tagContent);
                        validTitleFound = !string.IsNullOrEmpty(aStep.Title);
                    }
                    else if (SimpleTags.IsTag(SimpleTags.Tag.Image, tag))
                    {
                        ClassEnum classEnum = ClassEnum.All;
                        if (attributes.ContainsKey("class")) //TODO make hard reference
                        {
                            classEnum = SimpleTags.GetContent <ClassEnum>(attributes["class"]);
                        }

                        aStep.ImageSources[classEnum] = Path.Combine(aStepDirectory, SimpleTags.GetContent <string>(tagContent));
                    }
                    else if (SimpleTags.IsTag(SimpleTags.Tag.StepNumber, tag))
                    {
                        aStep.StepNumber     = SimpleTags.GetContent <int>(tagContent);
                        validStepNumberFound = true;
                    }
                    else if (SimpleTags.IsTag(SimpleTags.Tag.SubStep, tag))
                    {
                        SubStep subStep = SubStep.Parse(aGuide, aStep, attributes, tagContent);
                        if (subStep.IsValid)
                        {
                            aStep.SubSteps.Add(subStep);
                        }
                    }
                }
            }

            aStep.ValidateImageSources();
            if (!validTitleFound || !validStepNumberFound)
            {
                aStep.IsValid = false;
            }
        }
Ejemplo n.º 7
0
        public void ParseDbIntWithSpecificLength()
        {
            var result = TagParser.ParseTag("DB1.10000,di,10");

            Assert.Equal(PlcArea.DB, result.Area);
            Assert.Equal(10000, result.Offset);
            Assert.Equal(10, result.Length);
            Assert.Equal(typeof(int[]), result.ResultType);
            Assert.Equal(typeof(int), result.VarType);
        }
Ejemplo n.º 8
0
        public void ParseDbUIntWithLength()
        {
            var result = TagParser.ParseTag("DB1.10000,dw,1");

            Assert.Equal(PlcArea.DB, result.Area);
            Assert.Equal(10000, result.Offset);
            Assert.Equal(1, result.Length);
            Assert.Equal(typeof(uint), result.ResultType);
            Assert.Equal(typeof(uint), result.VarType);
        }
Ejemplo n.º 9
0
        public void ParseDbShortWithoutLength()
        {
            var result = TagParser.ParseTag("DB1.10000,i");

            Assert.Equal(PlcArea.DB, result.Area);
            Assert.Equal(10000, result.Offset);
            Assert.Equal(1, result.Length);
            Assert.Equal(typeof(short), result.ResultType);
            Assert.Equal(typeof(short), result.VarType);
        }
Ejemplo n.º 10
0
        public void ParseDbBitWithLength()
        {
            var result = TagParser.ParseTag("DB1.10000,x0,1");

            Assert.Equal(PlcArea.DB, result.Area);
            Assert.Equal(80000, result.Offset);
            Assert.Equal(1, result.Length);
            Assert.Equal(typeof(bool), result.ResultType);
            Assert.Equal(typeof(bool), result.VarType);
        }
Ejemplo n.º 11
0
        public void ParseExceptions()
        {
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("DB.10000,di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("1.10000,di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("i1.10000,di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("e1.10000,di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("m1.10000,di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("q1.10000,di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("M1.10000,di,10"));

            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("M1.di,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("M.1,10"));
            Assert.Throws <Dacs7TagParserException>(() => TagParser.ParseTag("M.1,10"));
        }
Ejemplo n.º 12
0
        public Control[] CreateControls(Page page, List <HtmlChunk> chunks)
        {
            List <System.Web.UI.Control> controls = new List <System.Web.UI.Control>();

            foreach (HtmlChunk chunk in chunks)
            {
                switch (chunk.ChunkType)
                {
                case HtmlChunkType.Tag:
                    //This is a tag for a custom control
                    controls.Add(TagParser.ParseTag(page, (HtmlTag)chunk));
                    //TODO: Change Tag System!!!
                    break;

                case HtmlChunkType.Region:
                    //make sure its a base:Region!
                    //TODO: Make sure we pass the attributes somehow so that we can merge properly
                    BmlRegion         region = (BmlRegion)chunk;
                    RegionPlaceHolder plc    = new RegionPlaceHolder();
                    //Set the Region ID for any merging that may take place at a later stage
                    plc.RegionID = region.Id;
                    //optionally add innertext if any
                    if (region.IsSelfClosing)
                    {
                        //TODO: Add content if any
                    }
                    //This is a tag for a custom control
                    controls.Add(plc);
                    break;

                case HtmlChunkType.Literal:
                    System.Web.UI.WebControls.Literal lit = new System.Web.UI.WebControls.Literal();
                    lit.Text = chunk.Value;
                    controls.Add(lit);
                    break;

                default:
                    throw new BASEGenericException("Invalid Chunk");
                    break;
                }
            }

            return(controls.ToArray());
        }
Ejemplo n.º 13
0
        public static Guide Parse(string aDirectory)
        {
            Guide result     = new Guide();
            bool  titleFound = false;
            bool  classFound = false;

            if (!File.Exists(Path.Combine(aDirectory, GuideInfoFile)))
            {
                return(result);
            }

            string guideFileContent = File.ReadAllText(Path.Combine(aDirectory, GuideInfoFile));

            foreach (var line in guideFileContent.Split(Environment.NewLine.ToCharArray()).Select(l => l.Trim()).Where(l => !string.IsNullOrEmpty(l)))
            {
                int index = 0;
                if (TagParser.ParseTag(line, ref index, out string tag, out string tagContent, out var attributes, isIncrementIndex: false))
                {
                    if (SimpleTags.IsTag(SimpleTags.Tag.Title, tag))
                    {
                        result.Title = SimpleTags.GetContent <string>(tagContent);
                        titleFound   = true;
                    }
                    else if (SimpleTags.IsTag(SimpleTags.Tag.Class, tag))
                    {
                        result.Classes = SimpleTags.GetContent <ClassEnum>(tagContent);
                        classFound     = true;
                    }
                }
            }

            result.IsValid = titleFound && classFound;
            if (result.IsValid)
            {
                ParseSteps(result, aDirectory);
            }

            return(result);
        }
Ejemplo n.º 14
0
        private void AddText(string aText, ref bool isQuestChanges, Span aCurrentSpan = null, string aCurrentText = null, bool isUnderline = false)
        {
            var textLines = aText.Split(Environment.NewLine.ToCharArray());

            if (aCurrentSpan == null)
            {
                aCurrentSpan = new Span();
                _paragraph.Inlines.Add(aCurrentSpan);
            }

            if (aCurrentText == null)
            {
                aCurrentText = string.Empty;
            }

            string[] realLines = textLines.Where(t => !t.Trim().StartsWith("#") && !string.IsNullOrEmpty(t.Trim())).ToArray();
            for (int i = 0; i < realLines.Length; i++)
            {
                string line = realLines[i];
                for (int charInde = 0; charInde < line.Length; charInde++)
                {
                    if (line[charInde] == '\t')
                    {
                        aCurrentText += "      ";
                        continue;
                    }

                    if (TagParser.ParseTag(line, ref charInde, out var tag, out var tagContent, out var attributes))
                    {
                        //Regular text
                        if (!string.IsNullOrEmpty(aCurrentText))
                        {
                            aCurrentSpan.Inlines.Add(GetText(aCurrentText, isUnderline));
                            aCurrentText = string.Empty;
                        }

                        if (SimpleTags.IsTag(SimpleTags.Tag.Legend, tag))
                        {
                            var legendColor = SimpleTags.GetContent <Color>(tagContent);
                            aCurrentSpan.Inlines.Add(CreateLegendRectangle(legendColor));
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.TLoc, tag))
                        {
                            var tloc = SimpleTags.GetContent <Point>(tagContent);
                            if (double.IsNaN(tloc.X) || double.IsNaN(tloc.Y))
                            {
                                aCurrentSpan.Inlines.Add(GetText("(error)", isUnderline));
                            }
                            else
                            {
                                var tlocRun = new TLocInline(this, tloc, tagContent);
                                aCurrentSpan.Inlines.Add(tlocRun);
                            }
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.Bold, tag))
                        {
                            var boldSpan = new Span();
                            boldSpan.FontWeight = FontWeights.Bold;
                            aCurrentSpan.Inlines.Add(boldSpan);

                            AddText(tagContent, ref isQuestChanges, aCurrentSpan: boldSpan, aCurrentText: aCurrentText, isUnderline: isUnderline);
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.Place, tag)) //Maybe do something else for this, same as bold atm
                        {
                            var boldSpan = new Span();
                            boldSpan.FontWeight = FontWeights.Bold;
                            aCurrentSpan.Inlines.Add(boldSpan);

                            AddText(tagContent, ref isQuestChanges, aCurrentSpan: boldSpan, aCurrentText: aCurrentText, isUnderline: isUnderline);
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.Italic, tag))
                        {
                            var italicSpan = new Span();
                            italicSpan.FontStyle = FontStyles.Italic;
                            aCurrentSpan.Inlines.Add(italicSpan);

                            AddText(tagContent, ref isQuestChanges, aCurrentSpan: italicSpan, aCurrentText: aCurrentText, isUnderline: isUnderline);
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.Underline, tag))
                        {
                            AddText(tagContent, ref isQuestChanges, aCurrentSpan: aCurrentSpan, aCurrentText: aCurrentText, isUnderline: true);
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.DONTFORGET, tag))
                        {
                            var empesizedSpan = new Span();
                            empesizedSpan.FontStyle  = FontStyles.Italic;
                            empesizedSpan.FontWeight = FontWeights.ExtraBold;
                            empesizedSpan.FontSize   = aCurrentSpan.FontSize + 5;
                            aCurrentSpan.Inlines.Add(empesizedSpan);
                            AddText(tagContent, ref isQuestChanges, aCurrentSpan: empesizedSpan, aCurrentText: aCurrentText, isUnderline: isUnderline);
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.Picture, tag))
                        {
                            string url = string.Empty;
                            attributes.TryGetValue("url", out url); { //TODO make hard reference
                                url = System.IO.Path.Combine(_stepDirectory, url);
                                aCurrentSpan.Inlines.Add(new PictureLinkInline(this, url, tagContent));
                            }
                        }
                        else if (SimpleTags.IsTag(SimpleTags.Tag.LineBreak, tag))
                        {
                            //aCurrentSpan.Inlines.Add(new LineBreak());
                        }
                        else
                        {
                            var tagType   = SimpleTags.GetTagFromString(tag);
                            var colorSpan = new Span();
                            colorSpan.Foreground = new SolidColorBrush(TextColors.GetColorFromTag(tagType));

                            if (IsQuestTag(tagType))
                            {
                                isQuestChanges = true;
                                tagContent     = HandleQuestTags(tagType, tagContent, attributes);
                            }

                            aCurrentSpan.Inlines.Add(colorSpan);
                            if (attributes.Any(a => a.Key == "isTargetLink".ToLower() && bool.TryParse(a.Value, out bool isTargetLink) && isTargetLink))
                            {
                                colorSpan.Inlines.Add(new CopyToClipboardInline(this, tagContent, $"/targetexact {tagContent}"));
                            }