Esempio n. 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));
                }
            }
        }
Esempio n. 2
0
        private void ProcessSourceFile(ProcessPath process, ScanResult result)
        {
            ScannedSourceFile sourceFile = null;
            string            fileKey    = ScannedSourceFile.CalculateKey(process.Path, process.Properties);

            if (!result.SourceFiles.TryGetValue(fileKey, out sourceFile) && !result.UnknownFiles.Contains(process.Path))
            {
                try
                {
                    sourceFile = new ScannedSourceFile(process.Path, process.Properties);
                    if (this.AddSymbols(result, sourceFile))
                    {
                        result.SourceFiles.Add(sourceFile.Key, sourceFile);
                    }
                    else
                    {
                        result.UnknownFiles.Add(process.Path);
                    }
                }
                catch (Exception e)
                {
                    this.OnMessage(ScannerMessageType.Warning, "Skipping non-XML file: {0} - reason: {1}", process.Path, e.Message);
                    result.UnknownFiles.Add(process.Path);
                }
            }

            if (sourceFile != null && process.Project != null)
            {
                process.Project.SourceFiles.Add(sourceFile);
                sourceFile.SourceProjects.Add(process.Project);
                //result.ProjectToSourceFileReferences.Add(new ScannedProjectSourceFileReference() { SourceProject = process.Project, TargetSourceFile = sourceFile });
            }
        }
        public ScannedUnresolvedReference(string typeName, string id, ScannedSourceFile sourceFile, ScannedSymbol symbol)
        {
            this.Id = id;
            this.SourceFile = sourceFile;
            this.SourceSymbol = symbol;
            this.Type = (ScannedSymbolType)Enum.Parse(typeof(ScannedSymbolType), typeName);

            this.TargetSymbol = String.Concat(this.Type, ":", this.Id);
        }
Esempio n. 4
0
        public ScannedUnresolvedReference(string typeName, string id, ScannedSourceFile sourceFile, ScannedSymbol symbol)
        {
            this.Id           = id;
            this.SourceFile   = sourceFile;
            this.SourceSymbol = symbol;
            this.Type         = (ScannedSymbolType)Enum.Parse(typeof(ScannedSymbolType), typeName);

            this.TargetSymbol = String.Concat(this.Type, ":", this.Id);
        }
        public ScannedSourceFile(string path, IDictionary <string, string> preprocessorDefines)
        {
            StringBuilder keyBuilder = new StringBuilder();

            keyBuilder.Append(path.ToLowerInvariant());

            this.Path = path;

            this.PreprocessorDefines = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            if (null != preprocessorDefines)
            {
                foreach (KeyValuePair <string, string> kvp in preprocessorDefines)
                {
                    this.PreprocessorDefines.Add(kvp.Key, kvp.Value);
                }
            }

            this.Key            = ScannedSourceFile.CalculateKey(this.Path, this.PreprocessorDefines);
            this.SourceProjects = new List <ScannedProject>();
            this.TargetSymbols  = new List <ScannedSymbol>();
        }
Esempio n. 6
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));
                }
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
0
        private void ProcessSourceFile(ProcessPath process, ScanResult result)
        {
            ScannedSourceFile sourceFile = null;
            string fileKey = ScannedSourceFile.CalculateKey(process.Path, process.Properties);
            if (!result.SourceFiles.TryGetValue(fileKey, out sourceFile) && !result.UnknownFiles.Contains(process.Path))
            {
                try
                {
                    sourceFile = new ScannedSourceFile(process.Path, process.Properties);
                    if (this.AddSymbols(result, sourceFile))
                    {
                        result.SourceFiles.Add(sourceFile.Key, sourceFile);
                    }
                    else
                    {
                        result.UnknownFiles.Add(process.Path);
                    }
                }
                catch (Exception e)
                {
                    this.OnMessage(ScannerMessageType.Warning, "Skipping non-XML file: {0} - reason: {1}", process.Path, e.Message);
                    result.UnknownFiles.Add(process.Path);
                }
            }

            if (sourceFile != null && process.Project != null)
            {
                process.Project.SourceFiles.Add(sourceFile);
                sourceFile.SourceProjects.Add(process.Project);
                //result.ProjectToSourceFileReferences.Add(new ScannedProjectSourceFileReference() { SourceProject = process.Project, TargetSourceFile = sourceFile });
            }
        }
Esempio n. 9
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);
        }