Beispiel #1
0
        private void AddReferences(XPathNavigator nav, XPathExpression xpath, ScannedSourceFile sourceFile, ScannedSymbol symbol, ScanResult result)
        {
            XPathNodeIterator i = nav.Select(xpath);

            while (i.MoveNext())
            {
                XPathNavigator n  = i.Current;
                string         id = n.GetAttribute("Id", String.Empty);

                if (String.IsNullOrEmpty(id))
                {
                    this.OnMessage(ScannerMessageType.Warning, "Reference type: {0} in Symbol: {1} in {2} skipped because it is missing an Id.", n.LocalName, symbol.Key, sourceFile.Path);
                }
                else
                {
                    string type = n.LocalName;
                    if (type.EndsWith("Ref"))
                    {
                        type = type.Substring(0, n.LocalName.Length - 3);
                    }

                    result.Unresolved.Add(new ScannedUnresolvedReference(type, id, sourceFile, symbol));
                }
            }
        }
Beispiel #2
0
        private bool AddSymbols(ScanResult result, ScannedSourceFile sourceFile)
        {
            bool validWixSource = false;

            using (FileStream fs = new FileStream(sourceFile.Path, FileMode.Open, FileAccess.Read))
            {
                XPathDocument  doc = new XPathDocument(fs);
                XPathNavigator nav = doc.CreateNavigator();

                XmlNamespaceManager manager = new XmlNamespaceManager(nav.NameTable);
                manager.AddNamespace("wix", WixNamespace);

                XPathExpression   rootExpression = XPathExpression.Compile("/wix:Wix", manager);
                XPathNodeIterator rootnav        = nav.Select(rootExpression);
                if (rootnav.MoveNext() && rootnav.Current.NodeType == XPathNodeType.Element)
                {
                    validWixSource = true;

                    XPathExpression exp = XPathExpression.Compile("wix:Bundle|wix:Product|//wix:PackageGroup|//wix:PayloadGroup|//wix:Payload|//wix:Feature|//wix:ComponentGroup|//wix:Component|//wix:MsiPackage|//wix:MspPackage|//wix:MsuPackage|//wix:ExePackage", manager);
                    XPathExpression bundleReferenceExpression         = XPathExpression.Compile("wix:PayloadGroupRef|wix:Chain/wix:PackageGroupRef|wix:Chain/wix:MsiPackage|wix:Chain/wix:MspPackage|wix:Chain/wix:MsuPackage|wix:Chain/wix:ExePackage", manager);
                    XPathExpression packageGroupReferenceExpression   = XPathExpression.Compile("wix:PackageGroupRef|wix:MsiPackage|wix:MspPackage|wix:MsuPackage|wix:ExePackage", manager);
                    XPathExpression payloadGroupReferenceExpression   = XPathExpression.Compile("wix:PayloadGroupRef|wix:Payload", manager);
                    XPathExpression productReferenceExpression        = XPathExpression.Compile("wix:Feature|wix:FeatureRef", manager);
                    XPathExpression featureReferenceExpression        = XPathExpression.Compile("wix:Feature|wix:FeatureRef|wix:ComponentGroupRef|wix:ComponentRef|wix:Component", manager);
                    XPathExpression componentGroupReferenceExpression = XPathExpression.Compile("wix:ComponentGroupRef|wix:ComponentRef|wix:Component", manager);
                    //XPathExpression componentReferenceExpression = XPathExpression.Compile("wix:File|wix:ServiceInstall|wix:Shortcut", manager);

                    XPathNodeIterator i = rootnav.Current.Select(exp);
                    while (i.MoveNext())
                    {
                        XPathNavigator  node       = i.Current;
                        string          type       = node.LocalName;
                        string          id         = null;
                        XPathExpression references = null;

                        switch (type)
                        {
                        case "Bundle":
                            id         = node.GetAttribute("Name", String.Empty);
                            references = bundleReferenceExpression;
                            break;

                        case "PackageGroup":
                            id         = node.GetAttribute("Id", String.Empty);
                            references = packageGroupReferenceExpression;
                            break;

                        case "PayloadGroup":
                            id         = node.GetAttribute("Id", String.Empty);
                            references = payloadGroupReferenceExpression;
                            break;

                        case "Product":
                            id         = node.GetAttribute("Name", String.Empty);
                            references = productReferenceExpression;
                            break;

                        case "Payload":
                        case "ExePackage":
                        case "MsiPackage":
                        case "MspPackage":
                        case "MsuPackage":
                            id = node.GetAttribute("Id", String.Empty);
                            break;

                        case "Feature":
                            id         = node.GetAttribute("Id", String.Empty);
                            references = featureReferenceExpression;
                            break;

                        case "ComponentGroup":
                            id         = node.GetAttribute("Id", String.Empty);
                            references = componentGroupReferenceExpression;
                            break;

                        case "Component":
                            id = node.GetAttribute("Id", String.Empty);
                            //references = componentReferenceExpression;
                            break;
                        }

                        if (String.IsNullOrEmpty(id))
                        {
                            this.OnMessage(ScannerMessageType.Warning, "Symbol type: {0} in {1} skipped because it is missing an Id.", node.LocalName, sourceFile.Path);
                        }
                        else
                        {
                            ScannedSymbol symbol;
                            string        key = ScannedSymbol.CalculateKey(type, id);
                            if (!result.Symbols.TryGetValue(key, out symbol))
                            {
                                symbol = new ScannedSymbol(type, id);
                                result.Symbols.Add(symbol.Key, symbol);
                            }

                            sourceFile.TargetSymbols.Add(symbol);
                            symbol.SourceFiles.Add(sourceFile);
                            //result.SourceFileToSymbolReference.Add(new ScannedSourceFileSymbolReference() { SourceSourceFile = sourceFile, TargetSymbol = symbol });
                            if (references != null)
                            {
                                AddReferences(node, references, sourceFile, symbol, result);
                            }
                        }
                    }
                }
            }

            return(validWixSource);
        }