Best NBi code snippet using NBi.UI.Genbi.View.TestSuiteGenerator.XmlEditor.XmlFoldStart.XmlFoldStart
XmlFoldingStrategy.cs
Source:XmlFoldingStrategy.cs
...10{11 /// <summary>12 /// Holds information about the start of a fold in an xml string.13 /// </summary>14 public class XmlFoldStart15 {16 #region Fields1718 int col = 0;19 string foldText = String.Empty;20 int line = 0;21 string name = String.Empty;22 string prefix = String.Empty;2324 #endregion Fields2526 #region Constructors2728 public XmlFoldStart(string prefix, string name, int line, int col)29 {30 this.line = line;31 this.col = col;32 this.prefix = prefix;33 this.name = name;34 }3536 #endregion Constructors3738 #region Properties3940 /// <summary>41 /// The column where the fold should start. Columns start from 0.42 /// </summary>43 public int Column44 {45 get46 {47 return col;48 }49 }5051 /// <summary>52 /// The text to be displayed when the item is folded.53 /// </summary>54 public string FoldText55 {56 get57 {58 return foldText;59 }6061 set62 {63 foldText = value;64 }65 }6667 /// <summary>68 /// The line where the fold should start. Lines start from 0.69 /// </summary>70 public int Line71 {72 get73 {74 return line;75 }76 }7778 /// <summary>79 /// The name of the xml item with its prefix if it has one.80 /// </summary>81 public string Name82 {83 get84 {85 if (prefix.Length > 0)86 {87 return String.Concat(prefix, ":", name);88 }89 else90 {91 return name;92 }93 }94 }9596 #endregion Properties97 }9899 /// <summary>100 /// Determines folds for an xml string in the editor.101 /// </summary>102 public class XmlFoldingStrategy : IFoldingStrategy103 {104 #region Fields105106 /// <summary>107 /// Flag indicating whether attributes should be displayed on folded108 /// elements.109 /// </summary>110 private readonly bool showAttributesWhenFolded = false;111112 #endregion Fields113114 #region Constructors115116 public XmlFoldingStrategy()117 {118 }119120 #endregion Constructors121122 #region Methods123124 /// <summary>125 /// Adds folds to the text editor around each start-end element pair.126 /// </summary>127 /// <remarks>128 /// <para>If the xml is not well formed then no folds are created.</para>129 /// <para>Note that the xml text reader lines and positions start130 /// from 1 and the SharpDevelop text editor line information starts131 /// from 0.</para>132 /// </remarks>133 public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)134 {135 //showAttributesWhenFolded = XmlEditorAddInOptions.ShowAttributesWhenFolded;136137 List<FoldMarker> foldMarkers = new List<FoldMarker>();138 Stack stack = new Stack();139140 try141 {142 string xml = document.TextContent;143 XmlTextReader reader = new XmlTextReader(new StringReader(xml));144 while (reader.Read())145 {146 switch (reader.NodeType)147 {148 case XmlNodeType.Element:149 if (!reader.IsEmptyElement)150 {151 XmlFoldStart newFoldStart = CreateElementFoldStart(reader);152 stack.Push(newFoldStart);153 }154 break;155156 case XmlNodeType.EndElement:157 XmlFoldStart foldStart = (XmlFoldStart)stack.Pop();158 CreateElementFold(document, foldMarkers, reader, foldStart);159 break;160161 case XmlNodeType.Comment:162 CreateCommentFold(document, foldMarkers, reader);163 break;164 }165 }166 }167 catch (Exception)168 {169 // If the xml is not well formed keep the foldings170 // that already exist in the document.171 return new List<FoldMarker>(document.FoldingManager.FoldMarker);172 }173174 return foldMarkers;175 }176177 /// <summary>178 /// Xml encode the attribute string since the string returned from179 /// the XmlTextReader is the plain unencoded string and .NET180 /// does not provide us with an xml encode method.181 /// </summary>182 static string XmlEncodeAttributeValue(string attributeValue, char quoteChar)183 {184 StringBuilder encodedValue = new StringBuilder(attributeValue);185186 encodedValue.Replace("&", "&");187 encodedValue.Replace("<", "<");188 encodedValue.Replace(">", ">");189190 if (quoteChar == '"')191 {192 encodedValue.Replace("\"", """);193 }194 else195 {196 encodedValue.Replace("'", "'");197 }198199 return encodedValue.ToString();200 }201202 /// <summary>203 /// Creates a comment fold if the comment spans more than one line.204 /// </summary>205 /// <remarks>The text displayed when the comment is folded is the first206 /// line of the comment.</remarks>207 void CreateCommentFold(IDocument document, List<FoldMarker> foldMarkers, XmlTextReader reader)208 {209 if (reader.Value != null)210 {211 string comment = reader.Value.Replace("\r\n", "\n");212 string[] lines = comment.Split('\n');213 if (lines.Length > 1)214 {215216 // Take off 5 chars to get the actual comment start (takes217 // into account the <!-- chars.218219 int startCol = reader.LinePosition - 5;220 int startLine = reader.LineNumber - 1;221222 // Add 3 to the end col value to take into account the '-->'223 int endCol = lines[lines.Length - 1].Length + startCol + 3;224 int endLine = startLine + lines.Length - 1;225 string foldText = String.Concat("<!--", lines[0], "-->");226 FoldMarker foldMarker = new FoldMarker(document, startLine, startCol, endLine, endCol, FoldType.TypeBody, foldText);227 foldMarkers.Add(foldMarker);228 }229 }230 }231232 /// <summary>233 /// Create an element fold if the start and end tag are on234 /// different lines.235 /// </summary>236 void CreateElementFold(IDocument document, List<FoldMarker> foldMarkers, XmlTextReader reader, XmlFoldStart foldStart)237 {238 int endLine = reader.LineNumber - 1;239 if (endLine > foldStart.Line)240 {241 int endCol = reader.LinePosition + foldStart.Name.Length;242 FoldMarker foldMarker = new FoldMarker(document, foldStart.Line, foldStart.Column, endLine, endCol, FoldType.TypeBody, foldStart.FoldText);243 foldMarkers.Add(foldMarker);244 }245 }246247 /// <summary>248 /// Creates an XmlFoldStart for the start tag of an element.249 /// </summary>250 XmlFoldStart CreateElementFoldStart(XmlTextReader reader)251 {252 // Take off 2 from the line position returned253 // from the xml since it points to the start254 // of the element name and not the beginning255 // tag.256 XmlFoldStart newFoldStart = new XmlFoldStart(reader.Prefix, reader.LocalName, reader.LineNumber - 1, reader.LinePosition - 2);257258 if (showAttributesWhenFolded && reader.HasAttributes)259 {260 newFoldStart.FoldText = String.Concat("<", newFoldStart.Name, " ", GetAttributeFoldText(reader), ">");261 }262 else263 {264 newFoldStart.FoldText = String.Concat("<", newFoldStart.Name, ">");265 }266267 return newFoldStart;268 }269270 /// <summary>
...
XmlFoldStart
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using ICSharpCode.AvalonEdit.Document;7using ICSharpCode.AvalonEdit.Folding;8{9 {10 public XmlFoldStart()11 {12 }13 public XmlFoldStart(int startOffset, int endOffset)14 : base(startOffset, endOffset)15 {16 }17 public XmlFoldStart(int startOffset, int endOffset, string name)18 : base(startOffset, endOffset, name)19 {20 }21 public XmlFoldStart(int startOffset, int endOffset, FoldType foldType)22 : base(startOffset, endOffset, foldType)23 {24 }25 public XmlFoldStart(int startOffset, int endOffset, string name, FoldType foldType)26 : base(startOffset, endOffset, name, foldType)27 {28 }29 public XmlFoldStart(int startOffset, int endOffset, string name, FoldType foldType, bool isDefaultCollapsed)30 : base(startOffset, endOffset, name, foldType, isDefaultCollapsed)31 {32 }33 public XmlFoldStart(int startOffset, int endOffset, string name, FoldType foldType, bool isDefaultCollapsed, bool isFolded)34 : base(startOffset, endOffset, name, foldType, isDefaultCollapsed, isFolded)35 {36 }37 public XmlFoldStart(int startOffset, int endOffset, string name, FoldType foldType, bool isDefaultCollapsed, bool isFolded, bool isFoldable)38 : base(startOffset, endOffset, name, foldType, isDefaultCollapsed, isFolded, isFoldable)39 {40 }41 public XmlFoldStart(int startOffset, int endOffset, string name, FoldType foldType, bool isDefaultCollapsed, bool isFolded, bool isFoldable, object tag)42 : base(startOffset, endOffset, name, foldType, isDefaultCollapsed, isFolded, isFoldable, tag)43 {
XmlFoldStart
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using System.Windows.Forms;7using ICSharpCode.TextEditor;8using ICSharpCode.TextEditor.Document;9using ICSharpCode.TextEditor.Actions;10using ICSharpCode.TextEditor.Gui.CompletionWindow;11using ICSharpCode.TextEditor.Gui.InsightWindow;12using ICSharpCode.TextEditor.Gui;13using ICSharpCode.TextEditor.Util;14using ICSharpCode.TextEditor.Undo;15using ICSharpCode.TextEditor.Document.HighlightingStrategy;16using ICSharpCode.TextEditor.Document.LineManager;17{18 {19 public override void Execute(TextArea textArea)20 {21 if (textArea.Document.FoldingManager.FoldMarker == null)22 {23 textArea.Document.FoldingManager.FoldMarker = new XmlFoldMarker(textArea.Caret.Line);24 textArea.Document.FoldingManager.UpdateFoldings(null, null);25 }26 }27 }28}29using System;30using System.Collections.Generic;31using System.Linq;32using System.Text;33using System.Threading.Tasks;34using System.Windows.Forms;35using ICSharpCode.TextEditor;36using ICSharpCode.TextEditor.Document;37using ICSharpCode.TextEditor.Actions;38using ICSharpCode.TextEditor.Gui.CompletionWindow;39using ICSharpCode.TextEditor.Gui.InsightWindow;40using ICSharpCode.TextEditor.Gui;41using ICSharpCode.TextEditor.Util;42using ICSharpCode.TextEditor.Undo;43using ICSharpCode.TextEditor.Document.HighlightingStrategy;44using ICSharpCode.TextEditor.Document.LineManager;45{46 {47 public override void Execute(TextArea textArea)48 {49 if (textArea.Document.FoldingManager.FoldMarker != null)50 {51 textArea.Document.FoldingManager.FoldMarker.EndLine = textArea.Caret.Line;52 textArea.Document.FoldingManager.UpdateFoldings(null, null);53 }54 }55 }56}
XmlFoldStart
Using AI Code Generation
1using System;2using System.Windows.Forms;3using ICSharpCode.TextEditor.Document;4using ICSharpCode.TextEditor;5using System.Drawing;6using ICSharpCode.TextEditor.Actions;7using System.Collections;8using System.Collections.Generic;9using System.Text;10using System.IO;11using System.Xml;12using System.Xml.XPath;13using System.Xml.Xsl;14using ICSharpCode.TextEditor.Util;15using System.Text.RegularExpressions;16using System.Xml.Schema;17using System.Xml.Serialization;18using System.ComponentModel;19using System.Reflection;20using System.Collections.Specialized;21using System.Globalization;22using System.Threading;23using System.Diagnostics;24using System.Runtime.InteropServices;25using System.Security.Permissions;26using System.Security;27using System.Resources;28using System.Runtime.Serialization;29using System.Runtime.Serialization.Formatters;30using System.Runtime.Serialization.Formatters.Binary;31using System.Runtime.Serialization.Formatters.Soap;32using System.Runtime.Serialization.Formatters.Soap;33using System.Collections.ObjectModel;34using System.Security.Cryptography;35using System.Security.Cryptography.X509Certificates;36using System.Security.Principal;37using System.Security.Policy;38using System.Security.Permissions;39using System.Security.AccessControl;40using System.Security.Authentication;41using System.Security.Authentication.ExtendedProtection;42using System.Security.Authentication.ExtendedProtection.Configuration;43using System.Security.Authentication.ExtendedProtection.Configuration;44using System.Security.Cryptography;45using System.Security.Cryptography.X509Certificates;46using System.Security.Cryptography.Xml;47using System.Security.Cryptography.Pkcs;
XmlFoldStart
Using AI Code Generation
1using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 using System.Windows.Forms;7 using System.Drawing;8 using System.Text.RegularExpressions;9 using ICSharpCode.TextEditor;10 using ICSharpCode.TextEditor.Document;11 using ICSharpCode.TextEditor.Gui.CompletionWindow;12{13 {14 public void UpdateFoldings(FoldingManager manager, TextDocument document)15 {16 List <FoldingSection> foldings = new List<FoldingSection>();17 int currentFoldStart = 0 ;18 int currentFoldEnd = 0 ;19 int currentFoldLevel = 0 ;20 int currentLine = 0 ;21 Regex regEx = new Regex( @"^(\s*)<\w+" );22 foreach (LineSegment line in document.LineSegmentCollection)23 {24 Match match = regEx.Match(document.GetText(line.Offset, line.Length));25 if (match.Success)26 {27 int level = match.Groups[ 1 ].Length / 4 ;28 if (level > currentFoldLevel)29 {30 currentFoldStart = currentLine;31 currentFoldLevel = level;32 }33 else if (level < currentFoldLevel)34 {35 currentFoldEnd = currentLine - 1 ;36 currentFoldLevel = level;37 foldings.Add( new FoldingSection(currentFoldStart, currentFoldEnd));38 }39 }40 currentLine++;41 }42 if (currentFoldEnd == 0 )43 if (currentFoldStart != currentLine - 1 )44 foldings.Add( new FoldingSection(currentFoldStart, currentLine - 1 ));45 manager.UpdateFoldings(foldings, - 1 );46 }47 }48}
XmlFoldStart
Using AI Code Generation
1{2 {3 public XmlFoldStart(int offset) : base(offset)4 {5 }6 public override void UpdateFoldings(List<NewFolding> foldings, string document)7 {8 var startOffset = Offset;9 var endOffset = document.IndexOf("</", startOffset, StringComparison.Ordinal);10 if (endOffset > -1)11 {12 endOffset = document.IndexOf(">", endOffset, StringComparison.Ordinal) + 1;13 if (endOffset > -1)14 {15 foldings.Add(new NewFolding(startOffset, endOffset));16 }17 }18 }19 }20}21{22 {23 public XmlFoldEnd(int offset) : base(offset)24 {25 }26 public override void UpdateFoldings(List<NewFolding> foldings, string document)27 {28 var endOffset = Offset + 1;29 var startOffset = document.LastIndexOf(">", endOffset, StringComparison.Ordinal);30 if (startOffset > -1)31 {32 startOffset = document.LastIndexOf("<", startOffset, StringComparison.Ordinal);33 if (startOffset > -1)34 {35 foldings.Add(new NewFolding(startOffset, endOffset));36 }37 }38 }39 }40}41{42 {43 public int Offset { get; }44 protected XmlFoldMarker(int offset)45 {46 Offset = offset;47 }48 public abstract void UpdateFoldings(List<NewFolding> foldings, string document);49 }50}
XmlFoldStart
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using ICSharpCode.AvalonEdit.Document;7using ICSharpCode.AvalonEdit.Folding;8using ICSharpCode.AvalonEdit.Highlighting;9using ICSharpCode.AvalonEdit.Rendering;10using NBi.UI.Genbi.View.TestSuiteGenerator.XmlEditor;11using System.Windows.Media;12using System.Windows;13using System.Windows.Controls;14using System.Windows.Input;15using ICSharpCode.AvalonEdit.Editing;16{17 {18 public static readonly XmlFoldStart Instance = new XmlFoldStart();19 public override int GetFirstInterestedOffset(int startOffset)20 {21 var document = CurrentContext.Document;22 var line = document.GetLineByOffset(startOffset);23 for (int i = line.Offset; i < line.EndOffset; i++)24 {25 if (document.GetCharAt(i) == '<')26 {27 return i;28 }29 }30 return -1;31 }32 public override VisualLineElement ConstructElement(int offset)33 {34 var document = CurrentContext.Document;35 var line = document.GetLineByOffset(offset);36 var text = document.GetText(line);37 if (text.StartsWith("<"))38 {39 return new XmlFoldStartElement(text);40 }41 return null;42 }43 }44 {45 private readonly string text;46 public XmlFoldStartElement(string text)47 {48 this.text = text;49 this.IsVisualLineElement = true;50 }51 public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)52 {53 var foldingManager = FoldingManager.GetFoldingManager(context.VisualLine.FirstDocumentLine.TextDocument);54 var folding = foldingManager.GetNextFolding(context.VisualLine.FirstDocumentLine.Offset);55 if (folding != null && folding.StartOffset == context.VisualLine.FirstDocumentLine.Offset)56 {57 return new XmlFoldStartTextRun(text, folding);58 }59 return null;60 }61 }62 {
XmlFoldStart
Using AI Code Generation
1XmlFoldStart xmlFoldStart = new XmlFoldStart();2xmlFoldStart.XmlFoldStart();3XmlFoldEnd xmlFoldEnd = new XmlFoldEnd();4xmlFoldEnd.XmlFoldEnd();5XmlFoldEnd xmlFoldEnd = new XmlFoldEnd();6xmlFoldEnd.XmlFoldEnd();7XmlFoldEnd xmlFoldEnd = new XmlFoldEnd();8xmlFoldEnd.XmlFoldEnd();9XmlFoldEnd xmlFoldEnd = new XmlFoldEnd();10xmlFoldEnd.XmlFoldEnd();11XmlFoldEnd xmlFoldEnd = new XmlFoldEnd();12xmlFoldEnd.XmlFoldEnd();13XmlFoldEnd xmlFoldEnd = new XmlFoldEnd();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!