예제 #1
0
 internal override void ReadUnknownAttribute(MSBuildXmlReader reader, string lastAttr)
 {
     fromAttribute  = true;
     afterAttribute = lastAttr;
     name           = reader.LocalName;
     value          = unevaluatedValue = reader.Value;
 }
예제 #2
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            MSBuildObject ob = null;

            switch (reader.LocalName)
            {
            case "ItemGroup": ob = new MSBuildItemGroup(); break;

            case "PropertyGroup": ob = new MSBuildPropertyGroup(); break;

            case "ImportGroup": ob = new MSBuildImportGroup(); break;

            case "Import": ob = new MSBuildImport(); break;

            case "Target": ob = new MSBuildTarget(); break;

            case "Choose": ob = new MSBuildChoose(); break;

            case "ProjectExtensions": ob = new MSBuildProjectExtensions(); break;

            default: ob = new MSBuildXmlElement(); break;
            }
            if (ob != null)
            {
                ob.ParentNode = this;
                ob.Read(reader);
                ChildNodes = ChildNodes.Add(ob);
            }
            else
            {
                base.ReadChildElement(reader);
            }
        }
예제 #3
0
 internal override void Read(MSBuildXmlReader reader)
 {
     name   = reader.LocalName;
     ns     = reader.NamespaceURI;
     prefix = reader.Prefix;
     base.Read(reader);
 }
		internal override void Read (MSBuildXmlReader reader)
		{
			name = reader.LocalName;
			ns = reader.NamespaceURI;
			prefix = reader.Prefix;
			base.Read (reader);
		}
예제 #5
0
        public void SetProjectExtension(XmlElement value)
        {
            AssertCanModify();
            var sr = new StringReader(value.OuterXml);
            var xr = new XmlTextReader(sr);

            xr.MoveToContent();
            var cr = new MSBuildXmlReader {
                XmlReader = xr
            };
            var section = value.LocalName;

            MSBuildXmlElement elem = new MSBuildXmlElement();

            elem.Read(cr);

            int i = ChildNodes.FindIndex(n => (n is MSBuildXmlElement) && ((MSBuildXmlElement)n).Name == section);

            if (i == -1)
            {
                ChildNodes = ChildNodes.Add(elem);
            }
            else
            {
                ChildNodes = ChildNodes.RemoveAt(i);
                ChildNodes = ChildNodes.Insert(i, elem);
            }
            elem.ParentNode = this;
            elem.ResetIndent(false);
            NotifyChanged();
        }
		internal override void Read (MSBuildXmlReader reader)
		{
			if (reader.ForEvaluation)
				reader.Read ();
			else
				base.Read (reader);
		}
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			var item = new MSBuildItem ();
			item.ParentNode = this;
			item.Read (reader);
			ChildNodes = ChildNodes.Add (item);
		}
예제 #8
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            var item = new MSBuildItem();

            item.ParentNode = this;
            item.Read(reader);
            ChildNodes = ChildNodes.Add(item);
        }
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			if (reader.LocalName == "Import") {
				var item = new MSBuildImport ();
				item.ParentNode = this;
				item.Read (reader);
				ChildNodes = ChildNodes.Add (item);
			} else
				base.ReadChildElement (reader);
		}
예제 #10
0
        string ReadValue(MSBuildXmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                rawValue = EmptyElementMarker;
                reader.Skip();
                return(string.Empty);
            }

            MSBuildXmlElement elem = new MSBuildXmlElement();

            elem.ParentNode = this;
            elem.ReadContent(reader);

            if (elem.ChildNodes.Count == 0)
            {
                StartInnerWhitespace = elem.StartInnerWhitespace;
                EndInnerWhitespace   = elem.EndInnerWhitespace;
                rawValue             = elem.GetInnerXml();
                return(string.Empty);
            }

            if (elem.ChildNodes.Count == 1)
            {
                var node = elem.ChildNodes [0] as MSBuildXmlValueNode;
                if (node != null)
                {
                    StartInnerWhitespace = elem.StartInnerWhitespace;
                    StartInnerWhitespace = MSBuildWhitespace.AppendSpace(StartInnerWhitespace, node.StartWhitespace);
                    EndInnerWhitespace   = node.EndWhitespace;
                    EndInnerWhitespace   = MSBuildWhitespace.AppendSpace(EndInnerWhitespace, elem.EndInnerWhitespace);
                    if (node is MSBuildXmlTextNode)
                    {
                        textValue = node.Value;
                        return(node.Value.Trim());
                    }
                    else if (node is MSBuildXmlCDataNode)
                    {
                        rawValue = "<![CDATA[" + node.Value + "]]>";
                        return(node.Value);
                    }
                }
            }

            if (elem.ChildNodes.Any(n => n is MSBuildXmlElement))
            {
                return(elem.GetInnerXml());
            }
            else
            {
                rawValue = elem.GetInnerXml();
                return(elem.GetText());
            }
        }
예제 #11
0
 internal override void Read(MSBuildXmlReader reader)
 {
     if (reader.ForEvaluation)
     {
         reader.Read();
     }
     else
     {
         base.Read(reader);
     }
 }
예제 #12
0
        internal override void Read(MSBuildXmlReader reader)
        {
            StartWhitespace = reader.ConsumeWhitespace();
            Value           = reader.Value;
            reader.Read();

            while (reader.IsWhitespace)
            {
                reader.ReadAndStoreWhitespace();
            }

            EndWhitespace = reader.ConsumeWhitespaceUntilNewLine();
        }
예제 #13
0
 internal override void ReadChildElement(MSBuildXmlReader reader)
 {
     if (reader.LocalName == "Import")
     {
         var item = new MSBuildImport();
         item.ParentNode = this;
         item.Read(reader);
         ChildNodes = ChildNodes.Add(item);
     }
     else
     {
         base.ReadChildElement(reader);
     }
 }
예제 #14
0
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			MSBuildChooseOption op = null;
			switch (reader.LocalName) {
				case "When": op = new MSBuildChooseOption (); break;
				case "Otherwise": op = new MSBuildChooseOption (true); break;
			}
			if (op != null) {
				op.ParentNode = this;
				op.Read (reader);
				ChildNodes = ChildNodes.Add (op);
			} else
				base.ReadChildElement (reader);
		}
예제 #15
0
 internal virtual void ReadChildElement(MSBuildXmlReader reader)
 {
     if (reader.ForEvaluation && !ContentRequiredForEvaluation)
     {
         reader.Skip();
     }
     else
     {
         var n = new MSBuildXmlElement();
         n.Read(reader);
         n.ParentNode = this;
         ChildNodes   = ChildNodes.Add(n);
     }
 }
예제 #16
0
 internal void LoadXml(string xml, MSBuildXmlReader reader)
 {
     AssertCanModify();
     try {
         DisableChangeTracking();
         var xr = new XmlTextReader(new StringReader(xml));
         xr.WhitespaceHandling = WhitespaceHandling.All;
         xr.Normalization      = false;
         reader.XmlReader      = xr;
         LoadFromXml(reader);
     } finally {
         EnableChangeTracking();
     }
 }
예제 #17
0
        void LoadFromXml(MSBuildXmlReader reader)
        {
            AssertCanModify();
            DisposeMainInstance();
            ChildNodes            = ChildNodes.Clear();
            conditionedProperties = new ConditionedPropertyCollection();
            bestGroups            = null;
            hadXmlDeclaration     = false;
            initialWhitespace     = null;
            StartInnerWhitespace  = null;

            while (!reader.EOF && reader.NodeType != XmlNodeType.Element)
            {
                if (reader.NodeType == XmlNodeType.XmlDeclaration)
                {
                    initialWhitespace = reader.ConsumeWhitespace();
                    hadXmlDeclaration = true;
                    reader.Read();
                }
                else if (reader.IsWhitespace)
                {
                    reader.ReadAndStoreWhitespace();
                }
                else
                {
                    reader.Read();
                }
            }

            if (reader.EOF)
            {
                return;
            }

            Read(reader);

            while (!reader.EOF)
            {
                if (reader.IsWhitespace)
                {
                    reader.ReadAndStoreWhitespace();
                }
                else
                {
                    reader.Read();
                }
            }
        }
예제 #18
0
        internal virtual void ReadUnknownAttribute(MSBuildXmlReader reader, string lastAttr)
        {
            var ua = new UnknownAttribute {
                LocalName      = reader.LocalName,
                Prefix         = !string.IsNullOrEmpty(reader.Prefix) ? reader.Prefix : null,
                Namespace      = reader.NamespaceURI,
                Value          = reader.Value,
                AfterAttribute = lastAttr
            };

            if (unknownAttributes == null)
            {
                unknownAttributes = new List <UnknownAttribute> ();
            }
            unknownAttributes.Add(ua);
        }
예제 #19
0
        internal void Load(string file, MSBuildXmlReader reader)
        {
            AssertCanModify();
            try {
                this.file    = file;
                IsNewProject = false;
                format       = FileUtil.GetTextFormatInfo(file);

                // HACK: XmlStreamReader will fail if the file is encoded in UTF-8 but has <?xml version="1.0" encoding="utf-16"?>
                // To work around this, we load the XML content into a string and use XmlDocument.LoadXml() instead.
                string xml = File.ReadAllText(file);

                LoadXml(xml, reader);
            } finally {
                EnableChangeTracking();
            }
        }
예제 #20
0
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			MSBuildObject ob = null;
			switch (reader.LocalName) {
				case "ItemGroup": ob = new MSBuildItemGroup (); break;
				case "PropertyGroup": ob = new MSBuildPropertyGroup (); break;
				case "ImportGroup": ob = new MSBuildImportGroup (); break;
				case "Choose": ob = new MSBuildChoose (); break;
				default: ob = new MSBuildXmlElement (); break;
			}
			if (ob != null) {
				ob.ParentNode = this;
				ob.Read (reader);
				ChildNodes = ChildNodes.Add (ob);
			} else
				reader.Read ();
		}
예제 #21
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            MSBuildProperty prevSameName;

            if (properties.TryGetValue(reader.LocalName, out prevSameName))
            {
                prevSameName.Overwritten = true;
            }

            var prop = new MSBuildProperty();

            prop.ParentNode = PropertiesParent;
            prop.Owner      = this;
            prop.Read(reader);
            ChildNodes             = ChildNodes.Add(prop);
            properties [prop.Name] = prop;             // If a property is defined more than once, we only care about the last registered value
        }
예제 #22
0
        internal override void ReadUnknownAttribute(MSBuildXmlReader reader, string lastAttr)
        {
            MSBuildProperty prevSameName;

            if (properties.TryGetValue(reader.LocalName, out prevSameName))
            {
                prevSameName.Overwritten = true;
            }

            var prop = new MSBuildProperty();

            prop.ParentNode = PropertiesParent;
            prop.Owner      = this;
            prop.ReadUnknownAttribute(reader, lastAttr);
            ChildNodes = ChildNodes.Add(prop);
            properties = properties.SetItem(prop.Name, prop);             // If a property is defined more than once, we only care about the last registered value
            PropertiesAttributeOrder.Add(prop);
        }
예제 #23
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            MSBuildObject ob = null;

            switch (reader.LocalName)
            {
            case "ItemGroup": ob = new MSBuildItemGroup(); break;

            case "PropertyGroup": ob = new MSBuildPropertyGroup(); break;

            case "ImportGroup": ob = new MSBuildImportGroup(); break;

            case "Choose": ob = new MSBuildChoose(); break;

            default: ob = new MSBuildXmlElement(); break;
            }
            ob.ParentNode = this;
            ob.Read(reader);
            ChildNodes = ChildNodes.Add(ob);
        }
예제 #24
0
        void WriteValue(XmlWriter writer, WriteContext context, string value)
        {
            if (value == null)
            {
                value = string.Empty;
            }

            // This code is from Microsoft.Build.Internal.Utilities

            if (value.IndexOf('<') != -1)
            {
                // If the value looks like it probably contains XML markup ...
                try {
                    var sr   = new StringReader("<a>" + value + "</a>");
                    var elem = new MSBuildXmlElement();
                    using (var xr = new XmlTextReader(sr)) {
                        xr.MoveToContent();
                        var cr = new MSBuildXmlReader {
                            XmlReader = xr
                        };
                        elem.Read(cr);
                    }
                    elem.ParentNode = this;
                    elem.SetNamespace(Namespace);

                    elem.StartWhitespace = StartWhitespace;
                    elem.EndWhitespace   = EndWhitespace;
                    elem.ResetChildrenIndent();
                    elem.WriteContent(writer, context);
                    return;
                }
                catch (XmlException) {
                    // But that may fail, in the event that "value" is not really well-formed
                    // XML.  Eat the exception and fall through below ...
                }
            }

            // The value does not contain valid XML markup.  Write it as text, so it gets
            // escaped properly.
            writer.WriteValue(value);
        }
예제 #25
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            MSBuildChooseOption op = null;

            switch (reader.LocalName)
            {
            case "When": op = new MSBuildChooseOption(); break;

            case "Otherwise": op = new MSBuildChooseOption(true); break;
            }
            if (op != null)
            {
                op.ParentNode = this;
                op.Read(reader);
                ChildNodes = ChildNodes.Add(op);
            }
            else
            {
                base.ReadChildElement(reader);
            }
        }
		public void SetProjectExtension (XmlElement value)
		{
			AssertCanModify ();
			var sr = new StringReader (value.OuterXml);
			var xr = new XmlTextReader (sr);
			xr.MoveToContent ();
			var cr = new MSBuildXmlReader { XmlReader = xr };
			var section = value.LocalName;

			MSBuildXmlElement elem = new MSBuildXmlElement ();
			elem.Read (cr);

			int i = ChildNodes.FindIndex (n => (n is MSBuildXmlElement) && ((MSBuildXmlElement)n).Name == section);
			if (i == -1)
				ChildNodes = ChildNodes.Add (elem);
			else {
				ChildNodes = ChildNodes.RemoveAt (i);
				ChildNodes = ChildNodes.Insert (i, elem);
			}
			elem.ParentNode = this;
			elem.ResetIndent (false);
			NotifyChanged ();
		}
예제 #27
0
        internal override void ReadChildElement(MSBuildXmlReader reader)
        {
            MSBuildObject ob = null;

            switch (reader.LocalName)
            {
            case "ItemGroup": ob = new MSBuildItemGroup(); break;

            case "PropertyGroup": ob = new MSBuildPropertyGroup(); break;
            }
            if (ob != null)
            {
                ob.ParentNode = this;
                ob.Read(reader);
                ChildNodes = ChildNodes.Add(ob);
                return;
            }

            var task = new MSBuildTask();

            task.ParentNode = this;
            task.Read(reader);
            ChildNodes = ChildNodes.Add(task);
        }
예제 #28
0
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			metadata.ReadChildElement (reader);
		}
예제 #29
0
		internal override void Read (MSBuildXmlReader reader)
		{
			if (reader.ForEvaluation) {
				if (reader.MoveToFirstAttribute ()) {
					do {
						ReadAttribute (reader.LocalName, reader.Value);
					} while (reader.MoveToNextAttribute ());
				}
			} else {
				StartWhitespace = reader.ConsumeWhitespace ();

				if (reader.MoveToFirstAttribute ()) {
					var knownAtts = GetKnownAttributes ();
					int attOrderIndex = 0;
					int expectedKnownAttIndex = 0;
					bool attOrderIsUnexpected = false;
					List<UnknownAttribute> unknownAttsList = null;
					attributeOrder = new string [knownAtts.Length];
					string lastAttr = null;
					do {
						var attName = reader.LocalName;
						int i = Array.IndexOf (knownAtts, attName);
						if (i == -1) {
							if (attName == "xmlns")
								continue;
							
							#if ATTR_STATS
							UnknownAtts.Add (GetType ().Name + " " + attName);
							#endif

							var ua = new UnknownAttribute {
								LocalName = attName,
								Prefix = !string.IsNullOrEmpty (reader.Prefix) ? reader.Prefix : null,
								Namespace = reader.NamespaceURI,
								Value = reader.Value,
								AfterAttribute = lastAttr
							};
							if (unknownAttsList == null)
								unknownAttsList = new List<UnknownAttribute> ();
							unknownAttsList.Add (ua);
							lastAttr = null;
						} else {
							if (attOrderIndex >= attributeOrder.Length)
								throw new InvalidOperationException ("Attribute specified twice");
							attributeOrder [attOrderIndex++] = attName;
							ReadAttribute (attName, reader.Value);
							if (i < expectedKnownAttIndex) {
								// Attributes have an unexpected order
								attOrderIsUnexpected = true;
							}
							expectedKnownAttIndex = i + 1;
							lastAttr = attName;
						}
					} while (reader.MoveToNextAttribute ());

					if (unknownAttsList != null)
						unknownAttributes = unknownAttsList.ToArray ();
					if (!attOrderIsUnexpected)
						attributeOrder = null;
					else {
						// Fill the remaning slots in the attributeOrder array (known attributes that were not read)
						foreach (var a in knownAtts) {
							if (!attributeOrder.Contains (a)) {
								if (attOrderIndex >= attributeOrder.Length)
									throw new InvalidOperationException ("Attribute specified twice");
								attributeOrder [attOrderIndex++] = a;
							}
						}
					}

					#if ATTR_STATS
					var atts = GetType().Name + " - " + string.Join (", ", (attributeOrder ?? knownAtts));
					if (attributeOrder == null)
						atts += " *";
					KnownAttOrder.Add (atts);
					#endif
				}
			}
			reader.MoveToElement ();

			emptyElementMode = reader.IsEmptyElement ? EmptyElementMode.Empty : EmptyElementMode.NotEmpty;

			if (!string.IsNullOrEmpty (reader.Prefix) && !SupportsNamespacePrefixes)
				throw new MSBuildFileFormatException ("XML namespace prefixes are not supported for " + reader.LocalName + " elements");

			ReadContent (reader);

			while (reader.IsWhitespace)
				reader.ReadAndStoreWhitespace ();

			EndWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
		}
예제 #30
0
		internal virtual void ReadChildElement (MSBuildXmlReader reader)
		{
			if (reader.ForEvaluation)
				reader.Skip ();
			else {
				var n = new MSBuildXmlElement ();
				n.Read (reader);
				n.ParentNode = this;
				ChildNodes = ChildNodes.Add (n);
			}
		}
예제 #31
0
		internal virtual void ReadContent (MSBuildXmlReader reader)
		{
			if (reader.IsEmptyElement) {
				reader.Skip ();
				return;
			}
			var elemName = reader.LocalName;

			reader.Read ();
			bool childFound = false;

			while (reader.NodeType != XmlNodeType.EndElement) {
				if (reader.NodeType == XmlNodeType.Element) {
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					ReadChildElement (reader);
				} else if (reader.NodeType == XmlNodeType.Text) {
					if (!SupportsTextContent)
						throw new MSBuildFileFormatException ("Text content is not allowed inside a " + elemName + " element");
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					var tn = new MSBuildXmlTextNode ();
					tn.Read (reader);
					ChildNodes = ChildNodes.Add (tn);
				} else if (reader.NodeType == XmlNodeType.CDATA) {
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					var tn = new MSBuildXmlCDataNode ();
					tn.Read (reader);
					ChildNodes = ChildNodes.Add (tn);
				} else if (reader.NodeType == XmlNodeType.Comment) {
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					var tn = new MSBuildXmlCommentNode ();
					tn.Read (reader);
					ChildNodes = ChildNodes.Add (tn);
				} else if (reader.IsWhitespace) {
					reader.ReadAndStoreWhitespace ();
				} else if (reader.EOF)
					throw new InvalidOperationException ("Invalid XML");
				else
					reader.Read ();
			}
			reader.Read ();

			EndInnerWhitespace = reader.ConsumeWhitespace ();
		}
예제 #32
0
        internal virtual void ReadContent(MSBuildXmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return;
            }
            var elemName = reader.LocalName;

            reader.Read();
            bool childFound = false;

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    ReadChildElement(reader);
                }
                else if (reader.NodeType == XmlNodeType.Text)
                {
                    if (!SupportsTextContent)
                    {
                        throw new MSBuildFileFormatException("Text content is not allowed inside a " + elemName + " element");
                    }
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    var tn = new MSBuildXmlTextNode();
                    tn.Read(reader);
                    ChildNodes = ChildNodes.Add(tn);
                }
                else if (reader.NodeType == XmlNodeType.CDATA)
                {
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    var tn = new MSBuildXmlCDataNode();
                    tn.Read(reader);
                    ChildNodes = ChildNodes.Add(tn);
                }
                else if (reader.NodeType == XmlNodeType.Comment)
                {
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    var tn = new MSBuildXmlCommentNode();
                    tn.Read(reader);
                    ChildNodes = ChildNodes.Add(tn);
                }
                else if (reader.IsWhitespace)
                {
                    reader.ReadAndStoreWhitespace();
                }
                else if (reader.EOF)
                {
                    throw new InvalidOperationException("Invalid XML");
                }
                else
                {
                    reader.Read();
                }
            }
            reader.Read();

            EndInnerWhitespace = reader.ConsumeWhitespace();
        }
예제 #33
0
 internal override void ReadChildElement(MSBuildXmlReader reader)
 {
     metadata.ReadChildElement(reader);
 }
		internal override void ReadChildElement (MSBuildXmlReader reader)
		{
			MSBuildObject ob = null;
			switch (reader.LocalName) {
				case "ItemGroup": ob = new MSBuildItemGroup (); break;
				case "PropertyGroup": ob = new MSBuildPropertyGroup (); break;
			}
			if (ob != null) {
				ob.ParentNode = this;
				ob.Read (reader);
				ChildNodes = ChildNodes.Add (ob);
				return;
			}

			var task = new MSBuildTask ();
			task.ParentNode = this;
			task.Read (reader);
			ChildNodes = ChildNodes.Add (task);
		}
예제 #35
0
		internal void Load (string file, MSBuildXmlReader reader)
		{
			AssertCanModify ();
			try {
				this.file = file;
				IsNewProject = false;
				format = FileUtil.GetTextFormatInfo (file);

				// HACK: XmlStreamReader will fail if the file is encoded in UTF-8 but has <?xml version="1.0" encoding="utf-16"?>
				// To work around this, we load the XML content into a string and use XmlDocument.LoadXml() instead.
				string xml = File.ReadAllText (file);

				LoadXml (xml, reader);

			} finally {
				EnableChangeTracking ();
			}
		}
예제 #36
0
		internal void LoadXml (string xml, MSBuildXmlReader reader)
		{
			AssertCanModify ();
			try {
				DisableChangeTracking ();
				var xr = new XmlTextReader (new StringReader (xml));
				xr.WhitespaceHandling = WhitespaceHandling.All;
				xr.Normalization = false;
				reader.XmlReader = xr;
				LoadFromXml (reader);
			} finally {
				EnableChangeTracking ();
			}
		}
예제 #37
0
		void LoadFromXml (MSBuildXmlReader reader)
		{
			AssertCanModify ();
			DisposeMainInstance ();
			ChildNodes = ChildNodes.Clear ();
			conditionedProperties = new ConditionedPropertyCollection ();
			bestGroups = null;
			hadXmlDeclaration = false;
			initialWhitespace = null;
			StartInnerWhitespace = null;

			while (!reader.EOF && reader.NodeType != XmlNodeType.Element) {
				if (reader.NodeType == XmlNodeType.XmlDeclaration) {
					initialWhitespace = reader.ConsumeWhitespace ();
					hadXmlDeclaration = true;
					reader.Read ();
				}
				else if (reader.IsWhitespace)
					reader.ReadAndStoreWhitespace ();
				else
					reader.Read ();
			}

			if (reader.EOF)
				return;

			Read (reader);

			while (!reader.EOF) {
				if (reader.IsWhitespace)
					reader.ReadAndStoreWhitespace ();
				else
					reader.Read ();
			}
		}
예제 #38
0
 internal virtual void Read(MSBuildXmlReader reader)
 {
 }
예제 #39
0
		string ReadValue (MSBuildXmlReader reader)
		{
			if (reader.IsEmptyElement) {
				rawValue = EmptyElementMarker;
				reader.Skip ();
				return string.Empty;
			}

			MSBuildXmlElement elem = new MSBuildXmlElement ();
			elem.ParentNode = this;
			elem.ReadContent (reader);

			if (elem.ChildNodes.Count == 0) {
				StartInnerWhitespace = elem.StartInnerWhitespace;
				EndInnerWhitespace = elem.EndInnerWhitespace;
				rawValue = elem.GetInnerXml ();
				return string.Empty;
			}

			if (elem.ChildNodes.Count == 1) {
				var node = elem.ChildNodes [0] as MSBuildXmlValueNode;
				if (node != null) {
					StartInnerWhitespace = elem.StartInnerWhitespace;
					StartInnerWhitespace = MSBuildWhitespace.AppendSpace (StartInnerWhitespace, node.StartWhitespace);
					EndInnerWhitespace = node.EndWhitespace;
					EndInnerWhitespace = MSBuildWhitespace.AppendSpace (EndInnerWhitespace, elem.EndInnerWhitespace);
					if (node is MSBuildXmlTextNode) {
						textValue = node.Value;
						return node.Value.Trim ();
					} else if (node is MSBuildXmlCDataNode) {
						rawValue = "<![CDATA[" + node.Value + "]]>";
						return node.Value;
					}
				}
			}

			if (elem.ChildNodes.Any (n => n is MSBuildXmlElement))
				return elem.GetInnerXml ();
			else {
				rawValue = elem.GetInnerXml ();
				return elem.GetText ();
			}
		}
예제 #40
0
 internal override void ReadUnknownAttribute(MSBuildXmlReader reader, string lastAttr)
 {
     metadata.ReadUnknownAttribute(reader, lastAttr);
 }
예제 #41
0
 internal override void Read(MSBuildXmlReader reader)
 {
     name = reader.LocalName;
     base.Read(reader);
 }
		internal override void Read (MSBuildXmlReader reader)
		{
			StartWhitespace = reader.ConsumeWhitespace ();
			Value = reader.Value;
			reader.Read ();

			while (reader.IsWhitespace)
				reader.ReadAndStoreWhitespace ();

			EndWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
		}
예제 #43
0
        internal override void Read(MSBuildXmlReader reader)
        {
            if (reader.ForEvaluation && !ContentRequiredForEvaluation)
            {
                if (reader.MoveToFirstAttribute())
                {
                    do
                    {
                        ReadAttribute(reader.LocalName, reader.Value);
                    } while (reader.MoveToNextAttribute());
                }
            }
            else
            {
                StartWhitespace = reader.ConsumeWhitespace();

                if (reader.MoveToFirstAttribute())
                {
                    var  knownAtts             = GetKnownAttributes();
                    int  attOrderIndex         = 0;
                    int  expectedKnownAttIndex = 0;
                    bool attOrderIsUnexpected  = false;
                    List <UnknownAttribute> unknownAttsList = null;
                    attributeOrder = new string [knownAtts.Length];
                    string lastAttr = null;
                    do
                    {
                        var attName = reader.LocalName;
                        int i       = Array.IndexOf(knownAtts, attName);
                        if (i == -1)
                        {
                            if (attName == "xmlns")
                            {
                                continue;
                            }

                                                        #if ATTR_STATS
                            UnknownAtts.Add(GetType().Name + " " + attName);
                                                        #endif

                            var ua = new UnknownAttribute {
                                LocalName      = attName,
                                Prefix         = !string.IsNullOrEmpty(reader.Prefix) ? reader.Prefix : null,
                                Namespace      = reader.NamespaceURI,
                                Value          = reader.Value,
                                AfterAttribute = lastAttr
                            };
                            if (unknownAttsList == null)
                            {
                                unknownAttsList = new List <UnknownAttribute> ();
                            }
                            unknownAttsList.Add(ua);
                            lastAttr = null;
                        }
                        else
                        {
                            if (attOrderIndex >= attributeOrder.Length)
                            {
                                throw new InvalidOperationException("Attribute specified twice");
                            }
                            attributeOrder [attOrderIndex++] = attName;
                            ReadAttribute(attName, reader.Value);
                            if (i < expectedKnownAttIndex)
                            {
                                // Attributes have an unexpected order
                                attOrderIsUnexpected = true;
                            }
                            expectedKnownAttIndex = i + 1;
                            lastAttr = attName;
                        }
                    } while (reader.MoveToNextAttribute());

                    if (unknownAttsList != null)
                    {
                        unknownAttributes = unknownAttsList.ToArray();
                    }
                    if (!attOrderIsUnexpected)
                    {
                        attributeOrder = null;
                    }
                    else
                    {
                        // Fill the remaning slots in the attributeOrder array (known attributes that were not read)
                        foreach (var a in knownAtts)
                        {
                            if (!attributeOrder.Contains(a))
                            {
                                if (attOrderIndex >= attributeOrder.Length)
                                {
                                    throw new InvalidOperationException("Attribute specified twice");
                                }
                                attributeOrder [attOrderIndex++] = a;
                            }
                        }
                    }

                                        #if ATTR_STATS
                    var atts = GetType().Name + " - " + string.Join(", ", (attributeOrder ?? knownAtts));
                    if (attributeOrder == null)
                    {
                        atts += " *";
                    }
                    KnownAttOrder.Add(atts);
                                        #endif
                }
            }
            reader.MoveToElement();

            emptyElementMode = reader.IsEmptyElement ? EmptyElementMode.Empty : EmptyElementMode.NotEmpty;

            if (!string.IsNullOrEmpty(reader.Prefix) && !SupportsNamespacePrefixes)
            {
                throw new MSBuildFileFormatException("XML namespace prefixes are not supported for " + reader.LocalName + " elements");
            }

            ReadContent(reader);

            while (reader.IsWhitespace)
            {
                reader.ReadAndStoreWhitespace();
            }

            EndWhitespace = reader.ConsumeWhitespaceUntilNewLine();
        }
예제 #44
0
		internal override void ReadContent (MSBuildXmlReader reader)
		{
			value = unevaluatedValue = ReadValue (reader);
		}
		internal virtual void Read (MSBuildXmlReader reader)
		{
		}
예제 #46
0
		void WriteValue (XmlWriter writer, WriteContext context, string value)
		{
			if (value == null)
				value = string.Empty;

			// This code is from Microsoft.Build.Internal.Utilities

			if (value.IndexOf('<') != -1) {
				// If the value looks like it probably contains XML markup ...
				try {
					var sr = new StringReader ("<a>"+ value + "</a>");
					var elem = new MSBuildXmlElement ();
					using (var xr = new XmlTextReader (sr)) {
						xr.MoveToContent ();
						var cr = new MSBuildXmlReader { XmlReader = xr };
						elem.Read (cr);
					}
					elem.ParentNode = this;
					elem.SetNamespace (MSBuildProject.Schema);

					elem.StartWhitespace = StartWhitespace;
					elem.EndWhitespace = EndWhitespace;
					elem.ResetChildrenIndent ();
					elem.WriteContent (writer, context);
					return;
				}
				catch (XmlException) {
					// But that may fail, in the event that "value" is not really well-formed
					// XML.  Eat the exception and fall through below ...
				}
			}

			// The value does not contain valid XML markup.  Write it as text, so it gets 
			// escaped properly.
			writer.WriteValue (value);
		}
예제 #47
0
 internal override void ReadContent(MSBuildXmlReader reader)
 {
     value = unevaluatedValue = ReadValue(reader);
 }
예제 #48
0
		internal override void Read (MSBuildXmlReader reader)
		{
			name = reader.LocalName;
			base.Read (reader);
		}