public RuntimeOrderPipelinesProcessorConfiguration(XNode xml)
 {
     if (xml == null) throw new ArgumentNullException("xml");
     using (var r = xml.CreateReader())
     {
         base.DeserializeElement(r, false);
     }
 }
Exemple #2
0
        static void Transform(string resourceName, XNode xml, ITaskItem outputFile)
        {
            var xmlTransform = new XslCompiledTransform();

            using (var writer = XmlWriter.Create(outputFile.GetMetadata("FullPath"), new XmlWriterSettings { Indent = true }))
            using (var xsltReader = XmlReader.Create(typeof(xunit).Assembly.GetManifestResourceStream("Xunit.Runner.MSBuild." + resourceName)))
            using (var xmlReader = xml.CreateReader())
            {
                xmlTransform.Load(xsltReader);
                xmlTransform.Transform(xmlReader, writer);
            }
        }
Exemple #3
0
        ///// <summary>
        ///// Parses an XML file to a QuicDocument object.
        ///// </summary>
        ///// <param name="filePath"></param>
        ///// <returns></returns>
        //public static QuicDocument ParseFile/*change to Load*/(string filePath)
        //{
        //    try
        //    {
        //        XmlDocument xmlDoc = new XmlDocument();
        //        xmlDoc.Load(filePath); 
                
        //        QuicDocument doc = new QuicDocument();
        //        doc.SourcePath = filePath;
        //        doc.internalXmlDoc = xmlDoc;
        //        Environment.CurrentDirectory = new FileInfo(doc.SourcePath).Directory.FullName;

        //        //add default property provider
        //        PropertyVP pp = new PropertyVP();
        //        //pp.Key = "$";
        //        pp.Document = doc;
        //        doc.resDic.Add("$", pp);
        //        doc.resList.Add(pp);

        //        XmlElement quicTag = null;
        //        XmlNodeList allQuicTags = doc.internalXmlDoc.GetElementsByTagName("Quic");
        //        if (allQuicTags.Count > 1)
        //        {
        //            throw new QuicException("Document cannot have more than one <Quic> tag.", doc.SourcePath);
        //        }
        //        else if (allQuicTags.Count == 1)
        //        {
        //            quicTag = (XmlElement)allQuicTags[0];
        //        }
        //        if (quicTag != null) 
        //        {
        //            //UnknownAttri...
        //            if (quicTag.HasAttribute("AllowUnknownAttributes"))
        //            {
        //                string allowAttri = quicTag.GetAttribute("AllowUnknownAttributes");
        //                doc.OutputOptions.AllowUnknownAttributes = (bool)BoolVP.Singleton().Evaluate(allowAttri);
        //            }

        //            //UnknownTag
        //            if (quicTag.HasAttribute("AllowUnknownTags"))
        //            {
        //                string allowTag = quicTag.GetAttribute("AllowUnknownTags");
        //                doc.OutputOptions.AllowUnknownTags = (bool)BoolVP.Singleton().Evaluate(allowTag);
        //            }

        //            //UnknownAttri...
        //            if (quicTag.HasAttribute("IgnoreAttributeCase"))
        //            {
        //                string ignoreAttri = quicTag.GetAttribute("IgnoreAttributeCase");
        //                doc.OutputOptions.IgnoreAttributeCase = (bool)BoolVP.Singleton().Evaluate(ignoreAttri);
        //            }

        //            //UnknownTag
        //            if (quicTag.HasAttribute("IgnoreTagCase"))
        //            {
        //                string ignoreTag = quicTag.GetAttribute("IgnoreTagCase");
        //                doc.OutputOptions.IgnoreTagCase = (bool)BoolVP.Singleton().Evaluate(ignoreTag);
        //            }
        //        }

        //        //parse resources
        //        XmlElement rsrcsTag = null;
        //        XmlNodeList allRscrsTags = xmlDoc.GetElementsByTagName("Resources");
        //        if (allRscrsTags.Count > 1)
        //        {
        //            throw new QuicException("Document cannot have more than one <Resources> tag.", filePath);
        //        }
        //        else if (allRscrsTags.Count == 1)
        //        {
        //            rsrcsTag = (XmlElement)allRscrsTags[0];
        //        }
        //        if (rsrcsTag != null)
        //        {
        //            foreach (XmlNode resTag in rsrcsTag.ChildNodes)
        //            {
        //                var resElement = (ResourceElement)doc.BuildElement(resTag);
        //                if (!string.IsNullOrWhiteSpace(resElement.Key))
        //                    doc.resDic.Add(resElement.Key, resElement);
        //                doc.resList.Add(resElement);
        //            }
        //        }

        //        //parse ui
        //        XmlElement uiTag = null;
        //        XmlNodeList allUiTags = xmlDoc.GetElementsByTagName("UI");
        //        if (allUiTags.Count > 1)
        //        {
        //            throw new QuicException("Document cannot have more than one <UI> tag.", filePath);
        //        }
        //        else if (allUiTags.Count == 1)
        //        {
        //            uiTag = (XmlElement)allUiTags[0];
        //        }
        //        if (uiTag != null)
        //        {
        //            foreach (XmlNode tag in uiTag.ChildNodes)
        //            {
        //                var uiElement = (UIElement)doc.BuildElement(tag);
        //                doc.uiElements.Add(uiElement);
        //            }
        //        }

        //        return doc;
        //    }
        //    catch (QuicException) 
        //    {
        //        throw;
        //    }
        //    catch (Exception ex) 
        //    {
        //        throw new QuicException(ex.Message, filePath, ex);
        //    }
        //}

        /// <summary>
        /// Builds an instance of Quic.IQuicElement from an instance of System.Xml.XmlNode.
        /// If the Quic.IQuicElement object has a name, it is added to dictionary of named objects.
        /// The Quic.IQuicElement object is NOT added to either the resource dictionary or the UI tree of the document.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        Element BuildElement(XNode node) 
        {
            var lineInfo = (IXmlLineInfo)node;

            if (node is XText)
            {
                Text txt = new Text();
                txt.Document = this;
                txt.Line = lineInfo.LineNumber;
                txt.Column = lineInfo.LinePosition;
                txt.SetProperty("Content", ((XText)node).Value);
                return txt;
            }
            else if (node is XProcessingInstruction)
            {
                Text txt = new Text();
                txt.Document = this;
                txt.Line = lineInfo.LineNumber;
                txt.Column = lineInfo.LinePosition;
                var tgt = ((XProcessingInstruction)node).Target;
                var data = ((XProcessingInstruction)node).Data;
                txt.SetProperty("Content", string.Format("<?{0}\n{1} ?>", tgt, data));
                return txt;
            }
            else if (node is XComment)
            {
                Comment comm = new Comment();
                comm.Document = this;
                comm.Line = lineInfo.LineNumber;
                comm.Column = lineInfo.LinePosition;
                string comment = ((XComment)node).Value.Trim();
                if (comment.ToLower().StartsWith("cdata:"))
                {
                    comment = comment.Substring(6);
                    comm.IsCData = true;
                }
                else if (comment.ToLower().StartsWith("out:"))
                {
                    comment = comment.Substring(4);
                    comm.ToBeOutput = true;
                }
                //comm.SetProperty("Content", comment); //dont call this method so that the comment is not "formatted"
                comm.Content = comment;
                return comm;
            }
            else if (node.NodeType == XmlNodeType.None || node.NodeType == XmlNodeType.Attribute ||
                //node.NodeType == XmlNodeType.ProcessingInstruction || 
                node.NodeType == XmlNodeType.Entity ||
                node.NodeType == XmlNodeType.Document || node.NodeType == XmlNodeType.DocumentFragment ||
                node.NodeType == XmlNodeType.DocumentType || node.NodeType == XmlNodeType.Notation ||
                node.NodeType == XmlNodeType.Whitespace || node.NodeType == XmlNodeType.EndElement ||
                node.NodeType == XmlNodeType.EndEntity || node.NodeType == XmlNodeType.XmlDeclaration
                || node.NodeType == XmlNodeType.SignificantWhitespace)
            {
                Nothing nothing = new Nothing();
                nothing.Document = this;
                nothing.Line = lineInfo.LineNumber;
                nothing.Column = lineInfo.LinePosition;
                return nothing;
            }

            if (!(node is XElement))
                throw new QuicException(string.Format("Unrecognized XML node '{0}'", node), 
                    this.SourcePath, lineInfo.LineNumber, lineInfo.LinePosition);
            XElement elementNode = (XElement)node;
            Element element = null;
            try
            {
                element = (Element)BuildObject(elementNode.Name.LocalName, elementNode.GetPrefixOfNamespace(elementNode.Name.Namespace));
                element.Document = this; //just in case I delete it from BuildObject(...) by mistake
            }
            catch (TypeLoadException ex)
            {
                if (this.OutputOptions.AllowUnknownTags)
                {
                    element = new UnknownElement();
                    element.Document = this;
                    var prefix = elementNode.GetPrefixOfNamespace(elementNode.Name.Namespace);
                    ((UnknownElement)element).Tag = (string.IsNullOrWhiteSpace(prefix) ? "" : prefix + ":") + elementNode.Name.LocalName;
                    ((UnknownElement)element).IsEmptyTag = elementNode.IsEmpty;
                }
                else
                {
                    throw new QuicException(ex.Message, this.SourcePath, lineInfo.LineNumber, lineInfo.LinePosition, ex);
                }
            }
            catch (QuicException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new QuicException(ex.Message, this.SourcePath, lineInfo.LineNumber, lineInfo.LinePosition, ex);
            }
            element.Line = lineInfo.LineNumber;
            element.Column = lineInfo.LinePosition;

            //set its properties
            foreach (XAttribute attri in elementNode.Attributes())
            {
                //try
                //{
                if (!attri.IsNamespaceDeclaration)
                    element.SetProperty(attri.Name.LocalName, attri.Value);
                //}
                //catch (Exception ex)
                //{
                //    var attriLineInfo = (IXmlLineInfo)attri;
                //    throw new QuicException(ex.Message, this.SourcePath, attriLineInfo.LineNumber, attriLineInfo.LinePosition, ex);
                //}
            }
            //record the element if it has a name
            if (element.Name != null)
            {
                if (namedElements.ContainsKey(element.Name))
                    throw new QuicException(string.Format("An element with the name '{0}' already exists.", element.Name),
                        this.SourcePath, element.Line, element.Column);
                namedElements.Add(element.Name, element);
            }
            //child tags
            if ((element).IsContainer)
            {
                foreach (XNode child in elementNode.Nodes())
                {
                    var uiElement = BuildElement(child);
                    (element).Elements.Add(uiElement);
                }
            }
            else
            {
                var reader = node.CreateReader();
                reader.MoveToContent();
                string innerXml = reader.ReadInnerXml();
                //((UIElement)element).Content = innerXml;
                element.SetProperty("Content", innerXml);
            }

            return element;
        }
 public XmlOutput(XNode element)
 {
     navigator = new XPathDocument(element.CreateReader()).CreateNavigator();
     manager = new XmlNamespaceManager(navigator.NameTable);
     manager.AddNamespace("r", Namespaces.ShopSchema.NamespaceName);
     manager.AddNamespace("x", Namespaces.XForms.NamespaceName);
 }
 private void WriteToFile( XNode doc, StreamWriter file )
 {
     try
     {
         XmlReader xr = doc.CreateReader( ) ;
         Stylesheet.Transform( xr, null, file.BaseStream ) ;
     }
     catch ( XsltException e )
     {
         Trace.TraceError( e.Message ) ;
         throw ;
     }
 }
 private string GetContentToEncrypt(XNode element)
 {
     var reader = element.CreateReader();
     reader.MoveToContent();
     return reader.ReadInnerXml();
 }
        public ConstantExpression(XNode value)
            : this(value, DbType.AnsiStringFixedLength)
        {
            if (value == null) {
                throw new ArgumentNullException(
                    "value",
                    "The value passed to a constant XNode expression must not be null");
            }

            // TODO reader is IDisposable remove that from here
            this.Value = new SqlXml(value.CreateReader());
            this.DbType = DbType.Xml;
        }