// XDocument // - from node without parent, from nodes with parent // - allowed types // - attributes // - Document // - doubled decl, root elem, doctype // - the same valid object instance multiple times // - array/IEnumerable of allowed types // - array/IEnumerable including not allowed types //[Variation(Priority = 0, Desc = "XDocument - adding element", Param = "XElement")] //[Variation(Priority = 1, Desc = "XDocument - adding PI", Param = "XPI")] //[Variation(Priority = 1, Desc = "XDocument - adding XmlDecl", Param = "XmlDecl")] //[Variation (Priority=1, Desc="XDocument - adding dot type")] //[Variation(Priority = 1, Desc = "XDocument - adding Comment", Param = "XComment")] //[Variation(Priority = 1, Desc = "XDocument - combination off allowed types in correct order", Param = "Mix1")] //[Variation(Priority = 1, Desc = "XDocument - combination off allowed types in correct order, without decl", Param = "Mix2")] //[Variation(Priority = 2, Desc = "XDocument - adding string/whitespace", Param = "Whitespace")] public void CreateXDocumentMixNoArrayConnected() { var doc1 = new XDocument(new XProcessingInstruction("PI", "data"), new XComment("comm1"), new XElement("root", new XAttribute("id", "a1")), new XComment("comm2")); var nodes = new XNode[4]; XNode nn = doc1.FirstNode; for (int i = 0; i < nodes.Length; i++) { nodes[i] = nn; nn = nn.NextNode; } var doc = new XDocument(nodes[0], nodes[1], nodes[2], nodes[3]); int nodeCounter = 0; for (XNode n = doc.FirstNode; n != null; n = n.NextNode) { TestLog.Compare(n != nodes[nodeCounter], "identity"); TestLog.Compare(XNode.DeepEquals(n, nodes[nodeCounter]), "Equals"); TestLog.Compare(nodes[nodeCounter].Document == doc1, "orig Document"); TestLog.Compare(n.Document == doc, "new Document"); nodeCounter++; } TestLog.Compare(nodeCounter, nodes.Length, "All nodes added"); }
// IFunctionResultToXElementMapper public bool TryMakeXEmbedable(FunctionContextContainer contextContainer, object resultObject, out XNode resultElement) { var control = resultObject as Control; if (control == null) { resultElement = null; return false; } string controlMarkerKey; lock (_controls) { controlMarkerKey = string.Format("[Composite.Function.Render.Asp.Net.Control.{0}]", _controls.Count); _controls.Add(controlMarkerKey, control); } resultElement = XElement.Parse(@"<c1marker:{0} xmlns:c1marker=""{1}"" key=""{2}"" />" .FormatWith(_markerElementName.LocalName, _markerElementName.Namespace, controlMarkerKey)); return true; }
public XNode ConvertHtmlEntityToXaml(XNode node) { if (node is XText) { return node; } var element = node as XElement; if (element == null) { return null; } string tagName = element.Name.LocalName; if (tagName == "br") { return new XElement("LineBreak"); } if (this._tagsToFunctionsMap.ContainsKey(tagName)) { var innerXaml = this.ConvertHtmlEntitiesToXaml(element.Nodes()); var result = this._tagsToFunctionsMap[tagName](element, innerXaml); return result; } return new XText(element.Value); }
private bool IsOSSIndexIgnored(XNode node) { if (node == null || node.PreviousNode == null) { return false; } switch (node.PreviousNode.NodeType) { case XmlNodeType.Whitespace: case XmlNodeType.Text: case XmlNodeType.None: { return IsOSSIndexIgnored(node.PreviousNode); } case XmlNodeType.Comment: { var commentValue = (node.PreviousNode as XComment).Value; if (commentValue.Replace(" ", string.Empty).Contains("@OSSIndexIgnore")) { return true; } return IsOSSIndexIgnored(node.PreviousNode); } default: { return false; } } }
private IEnumerable< XNode > _ProcessIteration(XElement element, XNode iterVal, string iterName) { XNode val = iterVal; IEnumerable< XNode > results = _Env.Call( () => { /* Bind the iterator symbolic name to the current value */ if ( val is XContainer ) /* Nodeset value */ { _Env.DefineNodesetSymbol( iterName, ( ( XContainer ) val ). Nodes() ); } else /* Text value */ { _Env.DefineTextSymbol( iterName, val. ToString () ); } /* Process loop body */ return _ProcessNodes( element.Nodes() ); } ); return results; }
private void addNodes(XNode root, TreeNode treeRoot) { TreeNode t; if (root.NodeType != XmlNodeType.Element) return; XElement e = root as XElement; switch (e.Name.LocalName) { case "topic": treeRoot.Text = e.Attributes().Where(attrib => attrib.Name.LocalName == "title").First().Value; if (e.Attributes().Where(attrib => attrib.Name.LocalName == "filename").Count() > 0) treeRoot.Tag = GetTextFile(e.Attributes().Where(attrib => attrib.Name.LocalName == "filename").First().Value); /*temp = .First().Value; if (temp != null && temp != "") treeRoot.Tag = temp;*/ foreach (XElement item in e.Nodes()) { t = new TreeNode(); treeRoot.Nodes.Add(t); addNodes(item, t); } break; case "section": treeRoot.Text = e.Attributes().Where(attrib => attrib.Name.LocalName == "title").First().Value; treeRoot.Tag = GetTextFile(e.Attributes().Where(attrib => attrib.Name.LocalName == "filename").First().Value); break; } //if (root.Name.LocalName }
private static object MergeAdjacentInstrText( XNode node) { XElement element = node as XElement; if (element != null) { if (element.Name == W.r && element.Elements(W.instrText).Any()) { var grouped = element.Elements().GroupAdjacent(e => e.Name == W.instrText); return new XElement(W.r, grouped.Select(g => { if (g.Key == false) return (object)g; string newInstrText = g.Select(i => (string)i).StringConcatenate(); return new XElement(W.instrText, newInstrText[0] == ' ' || newInstrText[newInstrText.Length - 1] == ' ' ? new XAttribute(XNamespace.Xml + "space", "preserve") : null, newInstrText); })); } return new XElement(element.Name, element.Attributes(), element.Nodes() .Select(n => MergeAdjacentInstrText(n))); } return node; }
public void Serialize(TextWriter writer, XNode node, MediaRange mediaType) { var element = node is XDocument ? ((XDocument)node).Root : node as XElement; if (element == null) throw new InvalidOperationException(); // Each element node is visited in document order, except non-relevant elements are skipped if the relevant // setting of the submission is true. Each visited element that has no child element nodes (i.e., each leaf // element node) is selected for inclusion, including those that have no value (no text node). Note that // attribute information is not preserved. var separ = false; var items = element .DescendantsAndSelf() .Where(i => !i.HasElements); foreach (var item in items) { // write separator on subsequent nodes if (separ) writer.Write(';'); // encode values writer.Write(Encode(item.Name.LocalName)); writer.Write('='); writer.Write(Encode(item.Value)); separ = true; } }
public override IEnumerable< XNode > Process(XNode node) { try { //Console.WriteLine("Processing {0}", node.ErrorContext()); switch ( node.NodeType ) { case XmlNodeType.Element: return _ProcessElement( ( XElement ) node ); /* PI,CDATA nodes are copied as-is */ case XmlNodeType.ProcessingInstruction: return new[] {new XProcessingInstruction( ( XProcessingInstruction ) node )}; case XmlNodeType.CDATA: return new[] {new XCData( ( XCData ) node )}; case XmlNodeType.Text: return _ProcessTextNode( ( XText ) node ); case XmlNodeType.Comment: return new[] {new XComment( ( XComment ) node )}; case XmlNodeType.DocumentType: case XmlNodeType.Entity: case XmlNodeType.EntityReference: return new[] { node }; default: throw new InvalidOperationException( "Unhandled Xml Node Type: " + node.NodeType ); } } catch ( PreprocessorException ) { throw; } }
public override IEnumerable< XNode > Process(XNode node) { XElement element = _AssumeElement( node ); string symbol_name = element.Name.LocalName; if ( !_Env.IsDefined( symbol_name ) ) throw InvalidMarkupException.CreateException( "[{0}] Undefined symbol '{1}' ", node.ErrorContext(), element.Name ); /* Evaluate the symbol on a new stack frame, since we may be defining local symbols * based on the attributes */ return _Env.Call( () => { /* Bind attributes as local symbolic definitions */ _DefineFromAttributes( element ); /* Bind any nested definition elements */ _ProcessNodes( element.Elements( _Env._Settings.Namespace.GetName("define") ).Select ( n => ( XNode ) n ) ); // Must materialize the deferred-execution nodeset // iterator before this method returns, otherwise // the evaluation stack will be wrong. Calling ToArray() // ensures this. return _Env.EvalSymbol( symbol_name ).ToArray(); //return _ProcessNodes( ret ); } ); }
public void Serialize(TextWriter writer, XNode node, MediaRange mediaType) { Contract.Requires<ArgumentNullException>(node != null); Contract.Requires<ArgumentNullException>(writer != null); Contract.Requires<ArgumentNullException>(mediaType != null); throw new System.NotImplementedException(); }
internal XNodeReader(XNode node, XmlNameTable nameTable, ReaderOptions options) { _source = node; _root = node; _nameTable = nameTable != null ? nameTable : CreateNameTable(); _omitDuplicateNamespaces = (options & ReaderOptions.OmitDuplicateNamespaces) != 0 ? true : false; }
public override void Close() { this.source = null; this.parent = null; this.root = null; this.state = System.Xml.ReadState.Closed; }
internal XNodeReader(XNode node, XmlNameTable nameTable, ReaderOptions options) { this.source = node; this.root = node; this.nameTable = (nameTable != null) ? nameTable : CreateNameTable(); this.omitDuplicateNamespaces = (options & ReaderOptions.OmitDuplicateNamespaces) != ReaderOptions.None; }
protected virtual void Apply(XNode node, JsonSerializer serializer, JObject obj) { Contract.Requires<ArgumentNullException>(node != null); Contract.Requires<ArgumentNullException>(serializer != null); Contract.Requires<ArgumentNullException>(obj != null); RemotesToObject(node.Interfaces<object>(), obj, serializer); }
private void VerifyOrder(XNode n1, XNode n2, int expected) { TestLog.Compare(XNode.DocumentOrderComparer.Compare(n1, n2), expected, "Comparison XNode"); TestLog.Compare(((IComparer)XNode.DocumentOrderComparer).Compare(n1, n2), expected, "Comparison interface"); TestLog.Compare(XNode.DocumentOrderComparer.Compare(n2, n1), -1 * expected, "Comparison XNode (-1*commutative)"); TestLog.Compare(((IComparer)XNode.DocumentOrderComparer).Compare(n2, n1), -1 * expected, "Comparison interface (-1*commutative)"); IsAfterBeforeConsistencyCheck(n1, n2); }
private void VerifyOrder(IEnumerable<XNode> nodes, XNode n1, XNode n2) { TestLog.Compare(XNode.DocumentOrderComparer.Compare(n1, n2), CompareInEnumeration(nodes, n1, n2), "Comparison XNode"); TestLog.Compare(((IComparer)XNode.DocumentOrderComparer).Compare(n1, n2), CompareInEnumeration(nodes, n1, n2), "Comparison interface"); TestLog.Compare(XNode.DocumentOrderComparer.Compare(n2, n1), -1 * CompareInEnumeration(nodes, n1, n2), "Comparison XNode (-1*commutative)"); TestLog.Compare(((IComparer)XNode.DocumentOrderComparer).Compare(n2, n1), -1 * CompareInEnumeration(nodes, n1, n2), "Comparison interface (-1*commutative)"); IsAfterBeforeConsistencyCheck(n1, n2); }
public RuntimeOrderPipelinesProcessorConfiguration(XNode xml) { if (xml == null) throw new ArgumentNullException("xml"); using (var r = xml.CreateReader()) { base.DeserializeElement(r, false); } }
public override IEnumerable< XNode > Process(XNode node) { XElement element = _AssumeElement( node ); Validation.RequireAttributes( element, AttrName.Expr ); var expr = ( string ) element.Attribute( AttrName.Expr ); return _ProcessConditional( element, _Env.EvalBool( _ProcessText( expr ).GetTextValue() ) ); }
public override IEnumerable< XNode > Process(XNode node) { XElement element = _AssumeElement( node ); Validation.RequireAttributes( element, AttrName.Name ); var name = ( string ) element.Attribute( AttrName.Name ); bool defined = _TestCondition( name ); return _ProcessConditional( element, defined ); }
public XmlConverter(XNode e) : this() { Contract.Requires(e != null); e.WriteTo(_writer); }
/// <summary> /// Dispatches the given event against the given node. /// </summary> /// <param name="node"></param> /// <param name="eventType"></param> void DispatchEvent(XNode node, string eventType) { Contract.Requires<ArgumentNullException>(node != null); Contract.Requires<ArgumentNullException>(node.Document != null); Contract.Requires<ArgumentNullException>(eventType != null); node.Interface<EventTarget>().Dispatch(CreateEvent(node, eventType)); }
/// <summary> /// Serializes the given <see cref="XNode"/> /// </summary> /// <param name="node"></param> /// <param name="serializer"></param> /// <returns></returns> JObject FromXNode(XNode node, JsonSerializer serializer) { // ignore empty text var text = node as XText; if (text != null) if (string.IsNullOrWhiteSpace(text.Value)) return null; return JObject.FromObject(node, serializer); }
public static String GetStringValue(XNode item) { if(item == null) throw new ArgumentNullException("item"); if (item is XElement) return ((XElement)item).Value; else throw new Exception(string.Format("Cannot handle '{0}'.", item.GetType())); }
private string CleanCData(XNode xNode) { if (xNode is XCData) { XCData xdata = (XCData)xNode; return StripDiv( xdata.Value ); } return xNode.ToString(); }
protected override void Apply(XNode node, JsonSerializer serializer, JObject obj) { var text = node as XText; if (text == null) throw new JsonException(); base.Apply(node, serializer, obj); obj["Type"] = "Text"; obj["Value"] = text.Value; }
public ViewModule( XNode node, [ImportMany] IEnumerable<IViewModuleDependencyProvider> providers) : base(node) { Contract.Requires<ArgumentNullException>(node != null); Contract.Requires<ArgumentNullException>(providers != null); this.providers = providers; }
protected override void Apply(XNode node, JsonSerializer serializer, JObject obj) { var comment = node as XComment; if (comment == null) throw new JsonException(); base.Apply(node, serializer, obj); obj["Type"] = "Comment"; obj["Value"] = comment.Value; }
public CanvasNodeContainer(XNode node, string left, string top, string right, string bottom) { Node = node; Left = left; Top = top; Right = right; Bottom = bottom; ParseValues(); }
public override IEnumerable<XNode> Process(XNode node) { // Scope causes a new stack frame for local definitions. return _Env.Call(() => { XElement element = _AssumeElement(node); /* Treat any attributes on the scope element as local symbol definitions */ _DefineFromAttributes(element); return _ProcessNodes(element.Nodes()); }); }
private void WriteNode(XNode n) { FlushElement(); n.WriteTo(_writer); }
internal virtual bool OnAddingObject(object o, bool rejectAttribute, XNode refNode, bool addFirst) { return(false); }
public Inserter(XContainer parent, XNode anchor) { _parent = parent; _previous = anchor; _text = null; }
public Inserter(XContainer parent, XNode anchor) { this.parent = parent; this.previous = anchor; this.text = null; }
internal override bool OnAddingObject(object obj, bool rejectAttribute, XNode refNode, bool addFirst) { VerifyAddedNode(obj, addFirst); return(false); }
/// <summary> /// Handles insignificant white spaces. /// There are 4 white spaces characters: carriage return '\r', linefeed '\n', tab '\t', and spacebar (' '). /// This handles xml:space = "preserve" that protects any text in an element or its /// descendants except inside any child with xml:space="default". /// </summary> /// <param name="this">This document.</param> /// <param name="actualTextProcessor"> /// Optional transformer for texts that are not entirely white spaces and for which white spaces /// are not preserved. The function is called with the current start line and the <see cref="StringBuilder"/> /// that can be changed: the function must return true if the content of the StringBuilder must be considered. /// </param> /// <returns>This document.</returns> public static XDocument Beautify(this XDocument @this, Func <string, StringBuilder, bool> actualTextProcessor = null) { bool?GetPreserve(XElement e) { var p = (string)e.Attribute(_xmlSpace); return(p == null ? (bool?)null : p == "preserve"); } string indent = " "; void Process(XElement e, bool preserve, string outerStartLine, int depth) { string startLine = outerStartLine + indent; if (preserve) { foreach (var child in e.Elements()) { Process(child, preserve, startLine, depth + 1); } return; } bool hasContent = false; var currentXText = new List <XText>(); var currentText = new StringBuilder(); XNode c = e.FirstNode; while (c != null) { if (c is XText t) { currentXText.Add(t); currentText.Append(t.Value); } else { hasContent = true; Debug.Assert(c is XElement || c is XComment || c is XCData || c is XProcessingInstruction); // Handling current collected XText, possibly replacing them with a unique XText. if (currentXText.Count == 0) { c.AddBeforeSelf(new XText(startLine)); } else { HandleCollectedXText(actualTextProcessor, startLine, currentXText, currentText, false); } if (c is XElement cE) { Process(cE, GetPreserve(cE) ?? preserve, startLine, depth + 1); } currentXText.Clear(); currentText.Clear(); } c = c.NextNode; } if (currentXText.Count == 0) { if (hasContent) { e.LastNode.AddAfterSelf(new XText(outerStartLine)); } } else { HandleCollectedXText(actualTextProcessor, outerStartLine, currentXText, currentText, !hasContent); } } Process(@this.Root, false, Environment.NewLine, 0); return(@this); }
public static bool DeepEquals(XNode n1, XNode n2) { return(eq_comparer.Equals(n1, n2)); }
public XNodeReader(XNode node) { this.node = node; start = node; }
public static void FetchForm(AbsoluteLayout Parent, System.Xml.Linq.XNode Nodes) { int cIndex = 0; int TabIndexes = ((System.Xml.Linq.XElement)Nodes).Elements().Count(); foreach (XElement C in ((System.Xml.Linq.XElement)Nodes).Elements()) { if (C.Name == "Object") { cIndex++; if (true) { if (C.Attribute("type").Value.StartsWith("System.Windows.Forms.PictureBox")) { var CP = new Image(); foreach (XElement V in C.Elements()) { if (V.Name == "Property") { switch (V.Attribute("name").Value) { case "Location": CP.ORect = new Rectangle(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)), CP.ORect.Width, CP.ORect.Height); CP.Layout(new Rectangle( Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY, CP.Width, CP.Height)); Point pt = new Point(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY); break; case "Size": CP.ORect = new Rectangle(CP.ORect.Left, CP.ORect.Top, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1))); CP.Layout(new Rectangle(CP.X, CP.Y, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY)); break; case "SizeMode": if (V.Value == "StretchImage") { CP.Aspect = Aspect.Fill; } else if (V.Value == "Zoom") { CP.Aspect = Aspect.AspectFill; } else if (V.Value == "Normal") { CP.Aspect = Aspect.AspectFit; } break; case "Image": string IMGData = String.Concat(V.Value); byte[] B = System.Convert.FromBase64String(IMGData); CP.Source = ImageSource.FromStream(() => new System.IO.MemoryStream(B)); break; case "BackColor": CP.BackgroundColor = ColorExtensions.GetXColor(String.Concat(V.Nodes())); break; case "Tag": CP.ClassId = String.Concat(V.Nodes()); break; } } } CP.Aspect = Aspect.AspectFill; Parent.Children.Add(CP, new Rectangle(CP.X, CP.Y, CP.Width, CP.Height), AbsoluteLayoutFlags.None); Parent.LowerChild(CP); } else if (C.Attribute("type").Value.StartsWith("System.Windows.Forms.Button")) { var CP = new Button(); foreach (XElement V in C.Elements()) { if (V.Name == "Property") { switch (V.Attribute("name").Value) { case "Location": CP.ORect = new Rectangle(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)), CP.ORect.Width, CP.ORect.Height); CP.Layout(new Rectangle( Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY, CP.Width, CP.Height)); Point pt = new Point(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY); break; case "Size": CP.ORect = new Rectangle(CP.ORect.Left, CP.ORect.Top, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1))); CP.Layout(new Rectangle(CP.X, CP.Y, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY)); break; case "Image": string IMGData = String.Concat(V.Value); byte[] B = System.Convert.FromBase64String(IMGData); var TempFile = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllBytes(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/" + System.IO.Path.GetFileName(TempFile), B); CP.Image = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "/" + System.IO.Path.GetFileName(TempFile); break; case "ForeColor": CP.TextColor = ColorExtensions.GetXColor(String.Concat(V.Nodes())); break; case "BackColor": CP.BackgroundColor = ColorExtensions.GetXColor(String.Concat(V.Nodes())); break; case "Caption": case "Text": CP.Text = String.Concat(V.Nodes()).Replace("##", "\r\n"); break; case "Tag": CP.ClassId = String.Concat(V.Nodes()); break; case "Font": string[] UFont = String.Concat(V.Nodes()).Replace("style=", "").Replace("Microsoft Sans Serif", "Helvetica").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); CP.FontFamily = UFont[0]; CP.FontSize = float.Parse(UFont[1].Replace("pt", "")); if (Array.IndexOf(UFont, " Bold") > -1) { CP.FontAttributes = CP.FontAttributes | FontAttributes.Bold; } if (Array.IndexOf(UFont, " Italic") > -1) { CP.FontAttributes = CP.FontAttributes | FontAttributes.Italic; } break; } } } Parent.Children.Add(CP, new Rectangle(CP.X, CP.Y, CP.Width, CP.Height), AbsoluteLayoutFlags.None); Parent.LowerChild(CP); } else if (C.Attribute("type").Value.StartsWith("System.Windows.Forms.TextBox")) { Point pt = Point.Zero; if (C.InnerXml().IndexOf("\"Multiline\">True") > -1) { var CP = new Editor(); foreach (XElement V in C.Elements()) { if (V.Name == "Property") { switch (V.Attribute("name").Value) { case "Tag": CP.ClassId = V.InnerText(); break; case "Location": CP.ORect = new Rectangle(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)), CP.ORect.Width, CP.ORect.Height); CP.Layout(new Rectangle( Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY, CP.Width, CP.Height)); pt = new Point(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY); break; case "Size": CP.ORect = new Rectangle(CP.ORect.Left, CP.ORect.Top, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1))); CP.Layout(new Rectangle(CP.X, CP.Y, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY)); break; } } } CP.InputTransparent = false; Parent.Children.Add(CP, new Rectangle(CP.X, CP.Y, CP.Width, CP.Height), AbsoluteLayoutFlags.None); Parent.LowerChild(CP); } else { var CP = new Entry(); foreach (XElement V in C.Elements()) { if (V.Name == "Property") { switch (V.Attribute("name").Value) { case "Tag": CP.ClassId = V.InnerText(); break; case "Location": CP.ORect = new Rectangle(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)), CP.ORect.Width, CP.ORect.Height); CP.Layout(new Rectangle( Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY, CP.Width, CP.Height)); pt = new Point(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY); break; case "Size": CP.ORect = new Rectangle(CP.ORect.Left, CP.ORect.Top, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1))); CP.Layout(new Rectangle(CP.X, CP.Y, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY)); break; } } } CP.InputTransparent = false; Parent.Children.Add(CP, new Rectangle(CP.X, CP.Y, CP.Width, CP.Height), AbsoluteLayoutFlags.None); Parent.LowerChild(CP); } //CP.li } else if (C.Attribute("type").Value.StartsWith("System.Windows.Forms.Label")) { var CP = new Label(); foreach (XElement V in C.Elements()) { if (V.Name == "Property") { switch (V.Attribute("name").Value) { case "ForeColor": CP.TextColor = ColorExtensions.GetXColor(String.Concat(V.Nodes())); break; case "BackColor": CP.BackgroundColor = ColorExtensions.GetXColor(String.Concat(V.Nodes())); break; case "Caption": case "Text": CP.Text = String.Concat(V.Nodes()).Replace("##", "\r\n"); break; case "Tag": CP.ClassId = String.Concat(V.Nodes()); break; case "Location": CP.ORect = new Rectangle(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)), CP.ORect.Width, CP.ORect.Height); CP.Layout(new Rectangle( Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY, CP.Width, CP.Height)); Point pt = new Point(Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY); break; case "Size": CP.ORect = new Rectangle(CP.ORect.Left, CP.ORect.Top, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))), Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1))); CP.Layout(new Rectangle(CP.X, CP.Y, Convert.ToInt32(String.Concat(V.Nodes()).Substring(0, String.Concat(V.Nodes()).IndexOf(","))) * App.ScaleFactorX, Convert.ToInt32(String.Concat(V.Nodes()).Substring(String.Concat(V.Nodes()).IndexOf(",") + 1)) * App.ScaleFactorY)); break; case "TabIndex": //CP.TabIndex = String.Concat(V.Nodes()); break; case "TextAlign": if (String.Concat(V.Nodes()).EndsWith("Center")) { CP.XAlign = TextAlignment.Center; } else if (String.Concat(V.Nodes()).EndsWith("Right")) { CP.XAlign = TextAlignment.End; } else { CP.XAlign = TextAlignment.Start; } if (String.Concat(V.Nodes()).StartsWith("Middle")) { CP.YAlign = TextAlignment.Center; } else if (String.Concat(V.Nodes()).EndsWith("Top")) { CP.YAlign = TextAlignment.Start; } else { CP.YAlign = TextAlignment.End; } break; case "Font": string[] UFont = String.Concat(V.Nodes()).Replace("style=", "").Replace("Microsoft Sans Serif", "Helvetica").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); CP.FontFamily = UFont[0]; CP.FontSize = float.Parse(UFont[1].Replace("pt", "")); if (Array.IndexOf(UFont, " Bold") > -1) { CP.FontAttributes = CP.FontAttributes | FontAttributes.Bold; } if (Array.IndexOf(UFont, " Italic") > -1) { CP.FontAttributes = CP.FontAttributes | FontAttributes.Italic; } break; case "BorderStyle": break; case "BorderWidth": break; case "Enabled": CP.IsEnabled = bool.Parse(String.Concat(V.Nodes())); break; } } else if (V.Name == "Object") { //FetchForm(CP, V.ParentNode); } } Parent.Children.Add(CP, new Rectangle(CP.X, CP.Y, CP.Width, CP.Height), AbsoluteLayoutFlags.None); Parent.LowerChild(CP); } } } } }
internal abstract bool DeepEquals(XNode node);
internal void ReadContentFrom(XmlReader r, LoadOptions o) { if ((o & (LoadOptions.SetBaseUri | LoadOptions.SetLineInfo)) == 0) { ReadContentFrom(r); return; } if (r.ReadState != ReadState.Interactive) throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive); XContainer c = this; XNode n = null; NamespaceCache eCache = new NamespaceCache(); NamespaceCache aCache = new NamespaceCache(); string baseUri = (o & LoadOptions.SetBaseUri) != 0 ? r.BaseURI : null; IXmlLineInfo li = (o & LoadOptions.SetLineInfo) != 0 ? r as IXmlLineInfo : null; do { string uri = r.BaseURI; switch (r.NodeType) { case XmlNodeType.Element: { XElement e = new XElement(eCache.Get(r.NamespaceURI).GetName(r.LocalName)); if (baseUri != null && baseUri != uri) { e.SetBaseUri(uri); } if (li != null && li.HasLineInfo()) { e.SetLineInfo(li.LineNumber, li.LinePosition); } if (r.MoveToFirstAttribute()) { do { XAttribute a = new XAttribute(aCache.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value); if (li != null && li.HasLineInfo()) { a.SetLineInfo(li.LineNumber, li.LinePosition); } e.AppendAttributeSkipNotify(a); } while (r.MoveToNextAttribute()); r.MoveToElement(); } c.AddNodeSkipNotify(e); if (!r.IsEmptyElement) { c = e; if (baseUri != null) { baseUri = uri; } } break; } case XmlNodeType.EndElement: { if (c.content == null) { c.content = string.Empty; } // Store the line info of the end element tag. // Note that since we've got EndElement the current container must be an XElement XElement e = c as XElement; Debug.Assert(e != null, "EndElement recieved but the current container is not an element."); if (e != null && li != null && li.HasLineInfo()) { e.SetEndElementLineInfo(li.LineNumber, li.LinePosition); } if (c == this) return; if (baseUri != null && c.HasBaseUri) { baseUri = c.parent.BaseUri; } c = c.parent; break; } case XmlNodeType.Text: case XmlNodeType.SignificantWhitespace: case XmlNodeType.Whitespace: if ((baseUri != null && baseUri != uri) || (li != null && li.HasLineInfo())) { n = new XText(r.Value); } else { c.AddStringSkipNotify(r.Value); } break; case XmlNodeType.CDATA: n = new XCData(r.Value); break; case XmlNodeType.Comment: n = new XComment(r.Value); break; case XmlNodeType.ProcessingInstruction: n = new XProcessingInstruction(r.Name, r.Value); break; case XmlNodeType.DocumentType: n = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value); break; case XmlNodeType.EntityReference: if (!r.CanResolveEntity) throw new InvalidOperationException(SR.InvalidOperation_UnresolvedEntityReference); r.ResolveEntity(); break; case XmlNodeType.EndEntity: break; default: throw new InvalidOperationException(SR.Format(SR.InvalidOperation_UnexpectedNodeType, r.NodeType)); } if (n != null) { if (baseUri != null && baseUri != uri) { n.SetBaseUri(uri); } if (li != null && li.HasLineInfo()) { n.SetLineInfo(li.LineNumber, li.LinePosition); } c.AddNodeSkipNotify(n); n = null; } } while (r.Read()); }
/// <summary> /// Determines if the current node appears before a specified node /// in terms of document order. /// </summary> /// <param name="node">The node to compare for document order.</param> /// <returns>True if this node appears before the specified node; false if not.</returns> public bool IsBefore(XNode node) { return(CompareDocumentOrder(this, node) < 0); }
/// <summary> /// Determines if the current node appears after a specified node /// in terms of document order. /// </summary> /// <param name="node">The node to compare for document order.</param> /// <returns>True if this node appears after the specified node; false if not.</returns> public bool IsAfter(XNode node) { return(CompareDocumentOrder(this, node) > 0); }
/// <summary> /// Compares two nodes to determine their relative XML document order. /// </summary> /// <param name="n1">First node to compare.</param> /// <param name="n2">Second node to compare.</param> /// <returns> /// 0 if the nodes are equal; -1 if n1 is before n2; 1 if n1 is after n2. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown if the two nodes do not share a common ancestor. /// </exception> public static int CompareDocumentOrder(XNode n1, XNode n2) { if (n1 == n2) { return(0); } if (n1 == null) { return(-1); } if (n2 == null) { return(1); } if (n1.parent != n2.parent) { int height = 0; XNode p1 = n1; while (p1.parent != null) { p1 = p1.parent; height++; } XNode p2 = n2; while (p2.parent != null) { p2 = p2.parent; height--; } if (p1 != p2) { throw new InvalidOperationException(SR.InvalidOperation_MissingAncestor); } if (height < 0) { do { n2 = n2.parent; height++; } while (height != 0); if (n1 == n2) { return(-1); } } else if (height > 0) { do { n1 = n1.parent; height--; } while (height != 0); if (n1 == n2) { return(1); } } while (n1.parent != n2.parent) { n1 = n1.parent; n2 = n2.parent; } } else if (n1.parent == null) { throw new InvalidOperationException(SR.InvalidOperation_MissingAncestor); } XNode n = (XNode)n1.parent.content; while (true) { n = n.next; if (n == n1) { return(-1); } if (n == n2) { return(1); } } }
internal override bool DeepEquals(XNode node) { XDocument other = node as XDocument; return(other != null && ContentsEqual(other)); }
extern public bool IsBefore(XNode node);
internal XNodeReader(XNode node, XmlNameTable?nameTable) : this(node, nameTable, (node.GetSaveOptionsFromAnnotations() & SaveOptions.OmitDuplicateNamespaces) != 0 ? ReaderOptions.OmitDuplicateNamespaces : ReaderOptions.None) { }
extern public bool IsAfter(XNode node);
void WriteNode(XNode n) { FlushElement(); n.WriteTo(writer); }
extern public static bool DeepEquals(XNode n1, XNode n2);
public static int CompareDocumentOrder(XNode n1, XNode n2) { return(order_comparer.Compare(n1, n2)); }
public XmlTranslator(XNode e) : this() { e.WriteTo(this._writer); }
internal static XNode GetXNodeFromJSNode(object node) { XNode result = null; if (Interop.IsRunningInTheSimulator) { // In the Simulator, we get the CSharp object associated to a DOM element by searching for the DOM element ID in the "INTERNAL_idsToUIElements" dictionary. #if RECYCLE_XNODES //This is useful for example when comparing two identical XNodes, so that it says that it is the same node. We commented it for performance reasons when running in the Simulator, to reduce the number if Interop calls. object jsId = Interop.ExecuteJavaScript("$0.nodeId", node); if (!IsNullOrUndefined(jsId)) { string id = Convert.ToString(jsId); if (XDocument.INTERNAL_idsToXNodes.ContainsKey(id)) { result = XDocument.INTERNAL_idsToXNodes[id]; } //else throw an exception ? } else { // generate a new id for the node #endif // get the type of the node (probably through node.nodeType, see the comment at the beginning of the XContainer class). // create the node // add the whole thing to the dictionary // result = nodeCreated string newId = Guid.NewGuid().ToString(); int nodeType = Convert.ToInt32(Interop.ExecuteJavaScript("$0.nodeType", node)); //nodeType = : 1 is XElement, 3 is XText, 8 is XComment, 9 is XDocument but is useless I think switch (nodeType) { case 1: //XElement result = new XElement(node); break; case 3: //Xtext result = new XText(node); result.INTERNAL_jsnode = node; break; case 8: //XComment break; case 9: //XDocument break; default: break; } #if RECYCLE_XNODES //This is useful for example when comparing two identical XNodes, so that it says that it is the same node. We commented it for performance reasons when running in the Simulator, to reduce the number if Interop calls. XDocument.INTERNAL_idsToXNodes.Add(newId, result); Interop.ExecuteJavaScriptAsync("$0.nodeId = $1", node, newId); } #endif } else { #if RECYCLE_XNODES //This is useful for example when comparing two identical XNodes, so that it says that it is the same node. We commented it for performance reasons when running in the Simulator, to reduce the number if Interop calls. // In JavaScript, we get the CSharp object associated to a DOM element by reading the "associatedUIElement" property: object associatedXNode = Interop.ExecuteJavaScript("$0.associatedXNode", node); if (!IsNullOrUndefined(associatedXNode)) { result = (XNode)associatedXNode; } else { #endif // get the type of the node (probably through node.nodeType, see the comment at the beginning of the XContainer class). // create the Xnode // set the XNode to node.associatedXNode //result = nodeCreated int nodeType = Convert.ToInt32(Interop.ExecuteJavaScript("$0.nodeType", node)); //nodeType = : 1 is XElement, 3 is XText, 8 is XComment, 9 is XDocument but is useless I think switch (nodeType) { case 1: //XElement result = new XElement(node); break; case 3: //Xtext result = new XText(node); result.INTERNAL_jsnode = node; break; case 8: //XComment break; case 9: //XDocument break; default: break; } #if RECYCLE_XNODES //This is useful for example when comparing two identical XNodes, so that it says that it is the same node. We commented it for performance reasons when running in the Simulator, to reduce the number if Interop calls. //todo: shouldn't it be ".associatedXNode" instead of ".nodeId" below? Interop.ExecuteJavaScript("$0.nodeId = $1", node, result); } #endif } return(result); }
// Validate insertion of the given node. previous is the node after which insertion // will occur. previous == null means at beginning, previous == this means at end. internal virtual void ValidateNode(XNode node, XNode previous) { }
public override void MoveToRoot() { node = node.Owner; attr = null; }
public XNodeNavigator(XNodeNavigator other) { this.node = other.node; this.attr = other.attr; this.name_table = other.name_table; }
public XNodeNavigator(XNode node, XmlNameTable nameTable) { this.node = node; this.name_table = nameTable; }
extern public static int CompareDocumentOrder(XNode n1, XNode n2);
public override bool Read() { // clear attribute state on element/xmldecl/dtd. attr = -1; attr_value = false; switch (state) { case ReadState.Initial: state = ReadState.Interactive; XDocument doc = node as XDocument; if (doc != null) { if (doc.Declaration != null) { return(true); } } else { return(true); // any other root } break; case ReadState.Interactive: break; default: return(false); } // when positioned on xmldecl, move to children if (node is XDocument) { XDocument doc = node as XDocument; node = doc.FirstNode; if (node == null) { state = ReadState.EndOfFile; return(false); } node = doc.FirstNode; return(true); } XElement c = node as XElement; if (c != null && !end_element) { if (c.FirstNode != null) { node = c.FirstNode; return(true); } else if (!c.IsEmpty) { // empty but full EndElement end_element = true; return(true); } } end_element = false; if (node.NextNode != null && node != start) { node = node.NextNode; return(true); } if (node.Parent == null || node == start) { state = ReadState.EndOfFile; return(false); } node = node.Parent; end_element = true; return(true); }
internal override bool DeepEquals(XNode node) { XProcessingInstruction other = node as XProcessingInstruction; return(other != null && target == other.target && data == other.data); }