예제 #1
0
        void ReadTag(Token lessThanToken)
        {
            var tagName = ReadNameToken();

            if (tagName == null)
            {
                return;
            }

            var oldXmlNamespaces = xmlNamespaces;

            try {
                xmlNamespaces = new XmlNamespaces(xmlNamespaces);
                Debug.Assert(xmlNamespaceReferences.Count == 0);
                ReadAttributes();
                SaveReference(tagName.Value, false);
                SaveXmlNamespaceReferences();

                var token = GetNextToken();
                switch (token.Kind)
                {
                case TokenKind.EOF:
                    return;

                case TokenKind.SlashGreaterThan:
                    SaveBraceInfo(Span.FromBounds(lessThanToken.Span.Start, tagName.Value.Span.End), token.Span, CodeBracesRangeFlags.OtherBraces);
                    break;

                case TokenKind.GreaterThan:
                    var firstGreaterThan = token;
                    ReadTagContents(false);
                    token = GetNextToken();
                    Debug.Assert(token.Kind == TokenKind.EOF || token.Kind == TokenKind.LessThanSlash);
                    if (token.Kind != TokenKind.LessThanSlash)
                    {
                        return;
                    }
                    var tagEndName = ReadNameToken();
                    if (tagEndName == null)
                    {
                        return;
                    }
                    var greaterThanToken = GetNextToken();
                    if (greaterThanToken.Kind != TokenKind.GreaterThan)
                    {
                        return;
                    }
                    SaveBraceInfo(Span.FromBounds(lessThanToken.Span.Start, tagName.Value.Span.End == firstGreaterThan.Span.Start ? firstGreaterThan.Span.End : tagName.Value.Span.End), Span.FromBounds(token.Span.Start, greaterThanToken.Span.End), CodeBracesRangeFlags.OtherBlockBraces);
                    SaveReference(tagEndName.Value, true);
                    break;

                default:
                    Debug.Assert(token.Kind == TokenKind.EOF);
                    return;
                }
            }
            finally {
                xmlNamespaces = oldXmlNamespaces;
            }
        }
        private bool GetRequestedExecutionLevel(out string requestedExecutionLevel)
        {
            bool flag;

            requestedExecutionLevel = "asInvoker";
            if (((base.InputManifest == null) || string.IsNullOrEmpty(base.InputManifest.ItemSpec)) || (string.CompareOrdinal(base.InputManifest.ItemSpec, "NoManifest") == 0))
            {
                return(false);
            }
            try
            {
                using (Stream stream = File.Open(base.InputManifest.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(stream);
                    XmlNamespaceManager namespaceManager = XmlNamespaces.GetNamespaceManager(document.NameTable);
                    XmlNode             node             = (XmlElement)document.SelectSingleNode("/asmv1:assembly/asmv2:trustInfo/asmv2:security/asmv3:requestedPrivileges/asmv3:requestedExecutionLevel", namespaceManager);
                    if (node != null)
                    {
                        XmlAttribute namedItem = (XmlAttribute)node.Attributes.GetNamedItem("level");
                        if (namedItem != null)
                        {
                            requestedExecutionLevel = namedItem.Value;
                        }
                    }
                    flag = true;
                }
            }
            catch (Exception exception)
            {
                base.Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", new object[] { base.InputManifest.ItemSpec, exception.Message });
                flag = false;
            }
            return(flag);
        }
예제 #3
0
 public XmlParser(string text)
 {
     if (text == null)
     {
         throw new ArgumentNullException(nameof(text));
     }
     this.text              = text;
     references             = new List <ReferenceInfo>();
     bracesInfo             = new List <CodeBracesRange>();
     xmlNamespaceReferences = new List <XmlNamespaceReference>();
     xmlNamespaces          = new XmlNamespaces(null);
 }
예제 #4
0
 public XmlParser(string text, bool isXaml)
 {
     this.text              = text ?? throw new ArgumentNullException(nameof(text));
     xamlAttributeParser    = isXaml ? new XamlAttributeParser(this) : null;
     blockFlags             = isXaml ? CodeBracesRangeFlags.XamlBlockBraces : CodeBracesRangeFlags.XmlBlockBraces;
     references             = new List <ReferenceInfo>();
     bracesInfo             = new List <CodeBracesRange>();
     xmlNamespaceReferences = new List <XmlNamespaceReference>();
     subStringDict          = new Dictionary <SubString, string>(EqualityComparer <SubString> .Default);
     lineSeparators         = new List <int>();
     xmlNamespaces          = new XmlNamespaces();
     xmlNamespaces.Initialize(null);
 }
예제 #5
0
 public XmlParser(string text, bool isXaml)
 {
     if (text == null)
     {
         throw new ArgumentNullException(nameof(text));
     }
     this.text = text;
     this.xamlAttributeParser = isXaml ? new XamlAttributeParser(this) : null;
     references             = new List <ReferenceInfo>();
     bracesInfo             = new List <CodeBracesRange>();
     xmlNamespaceReferences = new List <XmlNamespaceReference>();
     subStringDict          = new Dictionary <SubString, string>(EqualityComparer <SubString> .Default);
     xmlNamespaces          = new XmlNamespaces();
     xmlNamespaces.Initialize(null);
 }
예제 #6
0
        XmlNamespaces GetCachedXmlNamespaces(XmlNamespaces previous)
        {
            XmlNamespaces newInst;

            if (cachedXmlNamespaces.Count == 0)
            {
                newInst = new XmlNamespaces();
            }
            else
            {
                int index = cachedXmlNamespaces.Count - 1;
                newInst = cachedXmlNamespaces[index];
                cachedXmlNamespaces.RemoveAt(index);
            }
            newInst.Initialize(previous);
            return(newInst);
        }
예제 #7
0
		public static void ModifyNodeValueByXPath(string xmlPath, string xPath, string newValue, XmlNamespaces xmlNamespaces, bool preserveWhitespace = false)
		{
			XmlDocument doc = XmlService.LoadDocument(xmlPath, preserveWhitespace);
			XmlNamespaceManager xmlnsManager = new XmlNamespaceManager(doc.NameTable);
			if (xmlNamespaces != null)
			{
				foreach (XmlNamespace nms in xmlNamespaces.XmlNamespace)
				{
					xmlnsManager.AddNamespace(nms.Prefix, nms.UniformResourceIdentifier);
				}
			}
			XPathNavigator node = doc.CreateNavigator().SelectSingleNode(xPath, xmlnsManager);
			if (node != null)
			{
				node.SetValue(newValue);
				doc.Save(xmlPath);
			}
		}
예제 #8
0
        private bool GetRequestedExecutionLevel(out string requestedExecutionLevel)
        {
            requestedExecutionLevel = Constants.UACAsInvoker;  // For backwards compatibility we assume asInvoker to begin with.

            if (InputManifest == null || String.IsNullOrEmpty(InputManifest.ItemSpec) || String.CompareOrdinal(InputManifest.ItemSpec, "NoManifest") == 0)
            {
                return(false);
            }

            try
            {
                using (Stream s = File.Open(InputManifest.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    XmlDocument       document   = new XmlDocument();
                    XmlReaderSettings xrSettings = new XmlReaderSettings();
                    xrSettings.DtdProcessing = DtdProcessing.Ignore;
                    using (XmlReader xr = XmlReader.Create(s, xrSettings))
                    {
                        document.Load(xr);

                        //Create an XmlNamespaceManager for resolving namespaces.
                        XmlNamespaceManager nsmgr = XmlNamespaces.GetNamespaceManager(document.NameTable);

                        XmlNode node = (XmlElement)document.SelectSingleNode(XPaths.requestedExecutionLevelPath, nsmgr);
                        if (node != null)
                        {
                            XmlAttribute attr = (XmlAttribute)(node.Attributes.GetNamedItem("level"));
                            if (attr != null)
                            {
                                requestedExecutionLevel = attr.Value;
                            }
                        }
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", InputManifest.ItemSpec, ex.Message);
                return(false);
            }
        }
예제 #9
0
        //<QueryItemsResult xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/ClientServices/03">
        //  <ItemSet>
        //    <QueryPath>$/</QueryPath>
        //    <Items>
        //      <Item cs="1" date="2006-12-15T16:16:26.95Z" enc="-3" type="Folder" itemid="1" item="$/" />
        internal static ItemSet FromXml(XElement element)
        {
            ItemSet     itemSet = new ItemSet();
            List <Item> items   = new List <Item>();

            var patternElement = element.Element(XmlNamespaces.GetMessageElementName("Pattern"));

            itemSet.pattern = patternElement != null ? patternElement.Value : string.Empty;

            var queryPathElement = element.Element(XmlNamespaces.GetMessageElementName("QueryPath"));

            itemSet.queryPath = queryPathElement != null ? queryPathElement.Value : string.Empty;

            var itemElements = element.Element(XmlNamespaces.GetMessageElementName("Items")).Elements(XmlNamespaces.GetMessageElementName("Item"));

            items.AddRange(itemElements.Select(it => Item.FromXml(it)));

            items.Sort();
            itemSet.items = items.ToArray();
            return(itemSet);
        }
        //          <ExtendedItem lver="int" did="int" latest="int" type="Any or Folder or File" enc="int" itemid="int" local="string" titem="string" sitem="string" chg="None or Add or Edit or Encoding or Rename or Delete or Undelete or Branch or Merge or Lock or Rollback or SourceRename or Property" chgEx="int" ochg="boolean" lock="None or Checkin or CheckOut or Unchanged" lowner="string" lownerdisp="string" date="dateTime">
        //            <IsBranch>boolean</IsBranch>
        //            <PropertyValues xsi:nil="true" />
        //          </ExtendedItem>
        //        <s:complexType name="ExtendedItem">
        //            <s:sequence>
        //                <s:element minOccurs="0" maxOccurs="1" default="false" name="IsBranch" type="s:boolean"/>
        //                <s:element minOccurs="0" maxOccurs="1" name="PropertyValues" type="tns:ArrayOfPropertyValue"/>
        //            </s:sequence>
        //            <s:attribute default="0" name="lver" type="s:int"/>
        //            <s:attribute default="0" name="did" type="s:int"/>
        //            <s:attribute default="0" name="latest" type="s:int"/>
        //            <s:attribute default="Any" name="type" type="tns:ItemType"/>
        //            <s:attribute default="-3" name="enc" type="s:int"/>
        //            <s:attribute default="0" name="itemid" type="s:int"/>
        //            <s:attribute name="local" type="s:string"/>
        //            <s:attribute name="titem" type="s:string"/>
        //            <s:attribute name="sitem" type="s:string"/>
        //            <s:attribute default="None" name="chg" type="tns:ChangeType"/>
        //            <s:attribute default="0" name="chgEx" type="s:int"/>
        //            <s:attribute default="false" name="ochg" type="s:boolean"/>
        //            <s:attribute default="None" name="lock" type="tns:LockLevel"/>
        //            <s:attribute name="lowner" type="s:string"/>
        //            <s:attribute name="lownerdisp" type="s:string"/>
        //            <s:attribute name="date" type="s:dateTime" use="required"/>
        //        </s:complexType>
        internal static ExtendedItem FromXml(XElement element)
        {
            ExtendedItem item = new ExtendedItem
            {
                ChangeType            = ChangeType.None,
                VersionLocal          = 0,
                DeletionId            = 0,
                VersionLatest         = 0,
                ItemType              = ItemType.Any,
                Encoding              = -3,
                ItemId                = 0,
                HasOtherPendingChange = false,
                LockStatus            = LockLevel.None
            };

            item.ChangeType            = EnumHelper.ParseChangeType(element.GetAttribute("chg"));
            item.HasOtherPendingChange = GeneralHelper.XmlAttributeToBool(element.GetAttribute("ochg"));
            item.LockStatus            = EnumHelper.ParseLockLevel(element.GetAttribute("lock"));
            item.LockOwner             = element.GetAttribute("lowner");
            item.LocalItem             = TfsPath.ToPlatformPath(element.GetAttribute("local"));
            item.TargetServerItem      = element.GetAttribute("titem");
            item.SourceServerItem      = element.GetAttribute("sitem");
            item.ItemType      = EnumHelper.ParseItemType(element.GetAttribute("type"));
            item.ItemId        = GeneralHelper.XmlAttributeToInt(element.GetAttribute("itemid"));
            item.Encoding      = GeneralHelper.XmlAttributeToInt(element.GetAttribute("enc"));
            item.VersionLocal  = GeneralHelper.XmlAttributeToInt(element.GetAttribute("lver"));
            item.VersionLatest = GeneralHelper.XmlAttributeToInt(element.GetAttribute("latest"));
            item.DeletionId    = GeneralHelper.XmlAttributeToInt(element.GetAttribute("did"));
            item.CheckinDate   = GeneralHelper.XmlAttributeToDate(element.GetAttribute("date"));

            if (element.Element(XmlNamespaces.GetMessageElementName("IsBranch")) != null &&
                !string.IsNullOrEmpty(element.Element(XmlNamespaces.GetMessageElementName("IsBranch")).Value))
            {
                item.IsBranch = GeneralHelper.XmlAttributeToBool(element.Element(XmlNamespaces.GetMessageElementName("IsBranch")).Value);
            }

            return(item);
        }
예제 #11
0
        void ReadTag(Token lessThanToken)
        {
            var tagName = ReadNameToken();

            if (tagName == null)
            {
                return;
            }

            var oldXmlNamespaces = xmlNamespaces;

            try {
                xmlNamespaces = GetCachedXmlNamespaces(xmlNamespaces);
                Debug.Assert(xmlNamespaceReferences.Count == 0);
                SaveReference(tagName.Value, XmlNameReferenceKind.Tag, findDefsOnly: false);
                ReadAttributes();
                SaveXmlNamespaceReferences();

                var token     = GetNextToken();
                int endTagPos = -1;
                switch (token.Kind)
                {
                case TokenKind.EOF:
                    return;

                case TokenKind.SlashGreaterThan:
                    SaveBraceInfo(Span.FromBounds(lessThanToken.Span.Start, tagName.Value.Span.End), token.Span, blockFlags);
                    endTagPos = token.Span.Start;
                    break;

                case TokenKind.GreaterThan:
                    var firstGreaterThan = token;
                    ReadTagContents(false);
                    token = GetNextToken();
                    Debug.Assert(token.Kind == TokenKind.EOF || token.Kind == TokenKind.LessThanSlash);
                    if (token.Kind != TokenKind.LessThanSlash)
                    {
                        return;
                    }
                    var tagEndName = ReadNameToken();
                    if (tagEndName == null)
                    {
                        return;
                    }
                    var greaterThanToken = GetNextToken();
                    if (greaterThanToken.Kind != TokenKind.GreaterThan)
                    {
                        return;
                    }
                    SaveBraceInfo(Span.FromBounds(lessThanToken.Span.Start, tagName.Value.Span.End == firstGreaterThan.Span.Start ? firstGreaterThan.Span.End : tagName.Value.Span.End), Span.FromBounds(token.Span.Start, greaterThanToken.Span.End), blockFlags);
                    SaveReference(tagEndName.Value, XmlNameReferenceKind.Tag, findDefsOnly: true);
                    endTagPos = greaterThanToken.Span.Start;
                    break;

                default:
                    Debug.Assert(token.Kind == TokenKind.EOF);
                    return;
                }
                if (endTagPos >= 0 && recursionCounter == 2)
                {
                    lineSeparators.Add(endTagPos);
                }
            }
            finally {
                FreeXmlNamespaces(xmlNamespaces);
                xmlNamespaces = oldXmlNamespaces;
            }
        }
예제 #12
0
 void FreeXmlNamespaces(XmlNamespaces xmlNamespaces)
 {
     xmlNamespaces.Clear();
     cachedXmlNamespaces.Add(xmlNamespaces);
 }
예제 #13
0
 public override void Visit(XmlNamespaces node) { this.action(node); }
 public override void ExplicitVisit(XmlNamespaces fragment)
 {
     _fragments.Add(fragment);
 }
예제 #15
0
 public void Clear()
 {
     previous = null;
     namespaces.Clear();
 }
예제 #16
0
 public void Initialize(XmlNamespaces previous) =>
 this.previous = previous;
예제 #17
0
 public XmlNamespaces(XmlNamespaces previous)
 {
     this.previous = previous;
     namespaces    = new Dictionary <string, XmlNamespaceDefinition>(StringComparer.Ordinal);
 }