Пример #1
0
 internal Product(XmlNode node, string code, ProductValidationResults validationResults, string copyAll)
 {
     _node = node;
     _packages = new PackageCollection();
     _includes = new ProductCollection();
     _dependencies = new List<List<Product>>();
     _missingDependencies = new ArrayList();
     _productCode = code;
     _validationResults = validationResults;
     _cultures = new Hashtable();
     if (copyAll == "IfNotHomeSite")
         _copyAllPackageFiles = CopyAllFilesType.CopyAllFilesIfNotHomeSite;
     else if (copyAll == "false")
         _copyAllPackageFiles = CopyAllFilesType.CopyAllFilesFalse;
     else
         _copyAllPackageFiles = CopyAllFilesType.CopyAllFilesTrue;
 }
Пример #2
0
 internal Product(XmlNode node, string code, ProductValidationResults validationResults, string copyAll)
 {
     Node                = node;
     Packages            = new PackageCollection();
     Includes            = new ProductCollection();
     Dependencies        = new List <List <Product> >();
     MissingDependencies = new List <List <string> >();
     ProductCode         = code;
     ValidationResults   = validationResults;
     if (copyAll == "IfNotHomeSite")
     {
         CopyAllPackageFiles = CopyAllFilesType.CopyAllFilesIfNotHomeSite;
     }
     else if (copyAll == "false")
     {
         CopyAllPackageFiles = CopyAllFilesType.CopyAllFilesFalse;
     }
     else
     {
         CopyAllPackageFiles = CopyAllFilesType.CopyAllFilesTrue;
     }
 }
 internal Product(XmlNode node, string code, ProductValidationResults validationResults, string copyAll)
 {
     this.node = node;
     this.packages = new PackageCollection();
     this.includes = new ProductCollection();
     this.dependencies = new List<List<Product>>();
     this.missingDependencies = new ArrayList();
     this.productCode = code;
     this.validationResults = validationResults;
     this.cultures = new Hashtable();
     if (copyAll == "IfNotHomeSite")
     {
         this.copyAllPackageFiles = CopyAllFilesType.CopyAllFilesIfNotHomeSite;
     }
     else if (copyAll == "false")
     {
         this.copyAllPackageFiles = CopyAllFilesType.CopyAllFilesFalse;
     }
     else
     {
         this.copyAllPackageFiles = CopyAllFilesType.CopyAllFilesTrue;
     }
 }
Пример #4
0
 internal Product(XmlNode node, string code, ProductValidationResults validationResults, string copyAll)
 {
     _node                = node;
     _packages            = new PackageCollection();
     _includes            = new ProductCollection();
     _dependencies        = new List <List <Product> >();
     _missingDependencies = new ArrayList();
     _productCode         = code;
     _validationResults   = validationResults;
     _cultures            = new Hashtable();
     if (copyAll == "IfNotHomeSite")
     {
         _copyAllPackageFiles = CopyAllFilesType.CopyAllFilesIfNotHomeSite;
     }
     else if (copyAll == "false")
     {
         _copyAllPackageFiles = CopyAllFilesType.CopyAllFilesFalse;
     }
     else
     {
         _copyAllPackageFiles = CopyAllFilesType.CopyAllFilesTrue;
     }
 }
Пример #5
0
        private void ExploreDirectory(string strSubDirectory, XmlElement rootElement)
        {
            try
            {
                string packagePath = PackagePath;
                string strSubDirectoryFullPath = System.IO.Path.Combine(packagePath, strSubDirectory);

                // figure out our product file paths based on the directory full path
                string strBaseManifestFilename = System.IO.Path.Combine(strSubDirectoryFullPath, ROOT_MANIFEST_FILE);
                string strBaseManifestSchemaFileName = System.IO.Path.Combine(SchemaPath, MANIFEST_FILE_SCHEMA);

                ProductValidationResults productValidationResults = new ProductValidationResults(strBaseManifestFilename);

                // open the XmlDocument for this product.xml
                XmlDocument productDoc = LoadAndValidateXmlDocument(strBaseManifestFilename, false, strBaseManifestSchemaFileName, BOOTSTRAPPER_NAMESPACE, productValidationResults);
                if (productDoc != null)
                {
                    bool packageAdded = false;

                    XmlNode baseNode = productDoc.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":Product", _xmlNamespaceManager);
                    if (baseNode != null)
                    {
                        // Get the ProductCode attribute for this product
                        XmlAttribute productCodeAttribute = (XmlAttribute)(baseNode.Attributes.GetNamedItem("ProductCode"));
                        if (productCodeAttribute != null)
                        {
                            // now add it to our full document if it's not already present
                            XmlNode productNode = rootElement.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":Product[@ProductCode='" + productCodeAttribute.Value + "']", _xmlNamespaceManager);
                            if (productNode == null)
                            {
                                productNode = CreateProductNode(baseNode);
                            }
                            else
                            {
                                productValidationResults = (ProductValidationResults)_validationResults[productCodeAttribute];
                            }

                            // Fix-up the <PackageFiles> of the base node to include the SourcePath and TargetPath
                            XmlNode packageFilesNode = baseNode.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":PackageFiles", _xmlNamespaceManager);
                            XmlNode checksNode = baseNode.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":InstallChecks", _xmlNamespaceManager);
                            XmlNode commandsNode = baseNode.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":Commands", _xmlNamespaceManager);

                            // if there was a packageFiles node, then add it in to our full document with the rest
                            if (packageFilesNode != null)
                            {
                                UpdatePackageFileNodes(packageFilesNode, System.IO.Path.Combine(packagePath, strSubDirectory), strSubDirectory);

                                ReplacePackageFileAttributes(checksNode, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                                ReplacePackageFileAttributes(commandsNode, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                                ReplacePackageFileAttributes(baseNode, EULA_ATTRIBUTE, packageFilesNode, "PackageFile", "OldName", "SourcePath");
                            }

                            foreach (string strLanguageDirectory in Directory.GetDirectories(strSubDirectoryFullPath))
                            {
                                // The base node would get destroyed as we build-up this new node.
                                // Thus, we want to use a copy of the baseNode
                                XmlElement baseElement = (XmlElement)(_document.ImportNode(baseNode, true));

                                string strLangManifestFilename = System.IO.Path.Combine(strLanguageDirectory, CHILD_MANIFEST_FILE);
                                string strLangManifestSchemaFileName = System.IO.Path.Combine(SchemaPath, MANIFEST_FILE_SCHEMA);

                                if (File.Exists(strLangManifestFilename))
                                {
                                    // Load Package.xml
                                    XmlValidationResults packageValidationResults = new XmlValidationResults(strLangManifestFilename);
                                    XmlDocument langDoc = LoadAndValidateXmlDocument(strLangManifestFilename, false, strLangManifestSchemaFileName, BOOTSTRAPPER_NAMESPACE, packageValidationResults);

                                    Debug.Assert(langDoc != null, "we couldn't load package.xml in '" + strLangManifestFilename + "'...?");
                                    if (langDoc == null)
                                        continue;

                                    XmlNode langNode = langDoc.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":Package", _xmlNamespaceManager);
                                    Debug.Assert(langNode != null, string.Format(CultureInfo.CurrentCulture, "Unable to find a package node in {0}", strLangManifestFilename));
                                    if (langNode != null)
                                    {
                                        XmlElement langElement = (XmlElement)(_document.ImportNode(langNode, true));
                                        XmlElement mergeElement = _document.CreateElement("Package", BOOTSTRAPPER_NAMESPACE);

                                        // Update the "PackageFiles" section to reflect this language subdirectory
                                        XmlNode packageFilesNodePackage = langElement.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":PackageFiles", _xmlNamespaceManager);
                                        checksNode = langElement.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":InstallChecks", _xmlNamespaceManager);
                                        commandsNode = langElement.SelectSingleNode(BOOTSTRAPPER_PREFIX + ":Commands", _xmlNamespaceManager);

                                        if (packageFilesNodePackage != null)
                                        {
                                            int nStartIndex = packagePath.Length;

                                            if ((strLanguageDirectory.ToCharArray())[nStartIndex] == System.IO.Path.DirectorySeparatorChar)
                                                nStartIndex++;
                                            UpdatePackageFileNodes(packageFilesNodePackage, strLanguageDirectory, strSubDirectory);

                                            ReplacePackageFileAttributes(checksNode, "PackageFile", packageFilesNodePackage, "PackageFile", "OldName", "Name");
                                            ReplacePackageFileAttributes(commandsNode, "PackageFile", packageFilesNodePackage, "PackageFile", "OldName", "Name");
                                            ReplacePackageFileAttributes(langElement, EULA_ATTRIBUTE, packageFilesNodePackage, "PackageFile", "OldName", "SourcePath");
                                        }

                                        if (packageFilesNode != null)
                                        {
                                            ReplacePackageFileAttributes(checksNode, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                                            ReplacePackageFileAttributes(commandsNode, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                                            ReplacePackageFileAttributes(langElement, EULA_ATTRIBUTE, packageFilesNode, "PackageFile", "OldName", "SourcePath");
                                        }

                                        // in general, we prefer the attributes of the language document over the 
                                        //  attributes of the base document.  Copy attributes from the lang to the merged,
                                        //  and then merge all unique elements into merge
                                        foreach (XmlAttribute attribute in langElement.Attributes)
                                        {
                                            mergeElement.Attributes.Append((XmlAttribute)(mergeElement.OwnerDocument.ImportNode(attribute, false)));
                                        }

                                        foreach (XmlAttribute attribute in baseElement.Attributes)
                                        {
                                            XmlAttribute convertedAttribute = (XmlAttribute)(mergeElement.OwnerDocument.ImportNode(attribute, false));
                                            MergeAttribute(mergeElement, convertedAttribute);
                                        }

                                        // And append all of the nodes
                                        //  There is a well-known set of nodes which may have inherit children
                                        //  When merging these nodes, there may be subnodes taken from both the lang element and the base element.
                                        //  There will never be multiple nodes with the same name in the same manifest
                                        //  The function which performs this action is CombineElements(...)
                                        CombineElements(langElement, baseElement, "Commands", "PackageFile", mergeElement);
                                        CombineElements(langElement, baseElement, "InstallChecks", "Property", mergeElement);
                                        CombineElements(langElement, baseElement, "PackageFiles", "Name", mergeElement);
                                        CombineElements(langElement, baseElement, "Schedules", "Name", mergeElement);
                                        CombineElements(langElement, baseElement, "Strings", "Name", mergeElement);

                                        ReplaceStrings(mergeElement);
                                        CorrectPackageFiles(mergeElement);

                                        AppendNode(baseElement, "RelatedProducts", mergeElement);

                                        // Create a unique identifier for this package
                                        XmlAttribute cultureAttribute = (XmlAttribute)mergeElement.Attributes.GetNamedItem("Culture");
                                        if (cultureAttribute != null && !String.IsNullOrEmpty(cultureAttribute.Value))
                                        {
                                            string packageCode = productCodeAttribute.Value + "." + cultureAttribute.Value;
                                            AddAttribute(mergeElement, "PackageCode", packageCode);

                                            if (productValidationResults != null && packageValidationResults != null)
                                            {
                                                productValidationResults.AddPackageResults(cultureAttribute.Value, packageValidationResults);
                                            }

                                            // Only add this package if there is a culture apecified.
                                            productNode.AppendChild(mergeElement);
                                            packageAdded = true;
                                        }
                                    }
                                }
                            }
                            if (packageAdded)
                            {
                                rootElement.AppendChild(productNode);
                                if (!_validationResults.Contains(productCodeAttribute.Value))
                                {
                                    _validationResults.Add(productCodeAttribute.Value, productValidationResults);
                                }
                                else
                                {
                                    Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Validation results already added for Product Code '{0}'", productCodeAttribute));
                                }
                            }
                        }
                    }
                }
            }
            catch (XmlException ex)
            {
                Debug.Fail(ex.Message);
            }
            catch (System.IO.IOException ex)
            {
                Debug.Fail(ex.Message);
            }
            catch (ArgumentException ex)
            {
                Debug.Fail(ex.Message);
            }
        }
 private void ExploreDirectory(string strSubDirectory, XmlElement rootElement)
 {
     try
     {
         string packagePath = this.PackagePath;
         string str2 = System.IO.Path.Combine(packagePath, strSubDirectory);
         string filePath = System.IO.Path.Combine(str2, "product.xml");
         string schemaPath = System.IO.Path.Combine(this.SchemaPath, "package.xsd");
         ProductValidationResults results = new ProductValidationResults(filePath);
         XmlDocument document = this.LoadAndValidateXmlDocument(filePath, false, schemaPath, "http://schemas.microsoft.com/developer/2004/01/bootstrapper", results);
         if (document != null)
         {
             bool flag = false;
             XmlNode node = document.SelectSingleNode("bootstrapper:Product", this.xmlNamespaceManager);
             if (node != null)
             {
                 XmlAttribute namedItem = (XmlAttribute) node.Attributes.GetNamedItem("ProductCode");
                 if (namedItem != null)
                 {
                     XmlNode newChild = rootElement.SelectSingleNode("bootstrapper:Product[@ProductCode='" + namedItem.Value + "']", this.xmlNamespaceManager);
                     if (newChild == null)
                     {
                         newChild = this.CreateProductNode(node);
                     }
                     else
                     {
                         results = (ProductValidationResults) this.validationResults[namedItem];
                     }
                     XmlNode packageFilesNode = node.SelectSingleNode("bootstrapper:PackageFiles", this.xmlNamespaceManager);
                     XmlNode targetNodes = node.SelectSingleNode("bootstrapper:InstallChecks", this.xmlNamespaceManager);
                     XmlNode node5 = node.SelectSingleNode("bootstrapper:Commands", this.xmlNamespaceManager);
                     if (packageFilesNode != null)
                     {
                         this.UpdatePackageFileNodes(packageFilesNode, System.IO.Path.Combine(packagePath, strSubDirectory), strSubDirectory);
                         this.ReplacePackageFileAttributes(targetNodes, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                         this.ReplacePackageFileAttributes(node5, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                         this.ReplacePackageFileAttributes(node, "LicenseAgreement", packageFilesNode, "PackageFile", "OldName", "SourcePath");
                     }
                     foreach (string str5 in Directory.GetDirectories(str2))
                     {
                         XmlElement baseElement = (XmlElement) this.document.ImportNode(node, true);
                         string path = System.IO.Path.Combine(str5, "package.xml");
                         string str7 = System.IO.Path.Combine(this.SchemaPath, "package.xsd");
                         if (File.Exists(path))
                         {
                             XmlValidationResults results2 = new XmlValidationResults(path);
                             XmlDocument document2 = this.LoadAndValidateXmlDocument(path, false, str7, "http://schemas.microsoft.com/developer/2004/01/bootstrapper", results2);
                             if (document2 != null)
                             {
                                 XmlNode node6 = document2.SelectSingleNode("bootstrapper:Package", this.xmlNamespaceManager);
                                 if (node6 != null)
                                 {
                                     XmlElement element2 = (XmlElement) this.document.ImportNode(node6, true);
                                     XmlElement targetNode = this.document.CreateElement("Package", "http://schemas.microsoft.com/developer/2004/01/bootstrapper");
                                     XmlNode node7 = element2.SelectSingleNode("bootstrapper:PackageFiles", this.xmlNamespaceManager);
                                     targetNodes = element2.SelectSingleNode("bootstrapper:InstallChecks", this.xmlNamespaceManager);
                                     node5 = element2.SelectSingleNode("bootstrapper:Commands", this.xmlNamespaceManager);
                                     if (node7 != null)
                                     {
                                         int length = packagePath.Length;
                                         if (str5.ToCharArray()[length] == System.IO.Path.DirectorySeparatorChar)
                                         {
                                             length++;
                                         }
                                         this.UpdatePackageFileNodes(node7, str5, strSubDirectory);
                                         this.ReplacePackageFileAttributes(targetNodes, "PackageFile", node7, "PackageFile", "OldName", "Name");
                                         this.ReplacePackageFileAttributes(node5, "PackageFile", node7, "PackageFile", "OldName", "Name");
                                         this.ReplacePackageFileAttributes(element2, "LicenseAgreement", node7, "PackageFile", "OldName", "SourcePath");
                                     }
                                     if (packageFilesNode != null)
                                     {
                                         this.ReplacePackageFileAttributes(targetNodes, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                                         this.ReplacePackageFileAttributes(node5, "PackageFile", packageFilesNode, "PackageFile", "OldName", "Name");
                                         this.ReplacePackageFileAttributes(element2, "LicenseAgreement", packageFilesNode, "PackageFile", "OldName", "SourcePath");
                                     }
                                     foreach (XmlAttribute attribute2 in element2.Attributes)
                                     {
                                         targetNode.Attributes.Append((XmlAttribute) targetNode.OwnerDocument.ImportNode(attribute2, false));
                                     }
                                     foreach (XmlAttribute attribute3 in baseElement.Attributes)
                                     {
                                         XmlAttribute attribute = (XmlAttribute) targetNode.OwnerDocument.ImportNode(attribute3, false);
                                         this.MergeAttribute(targetNode, attribute);
                                     }
                                     this.CombineElements(element2, baseElement, "Commands", "PackageFile", targetNode);
                                     this.CombineElements(element2, baseElement, "InstallChecks", "Property", targetNode);
                                     this.CombineElements(element2, baseElement, "PackageFiles", "Name", targetNode);
                                     this.CombineElements(element2, baseElement, "Schedules", "Name", targetNode);
                                     this.CombineElements(element2, baseElement, "Strings", "Name", targetNode);
                                     this.ReplaceStrings(targetNode);
                                     this.CorrectPackageFiles(targetNode);
                                     this.AppendNode(baseElement, "RelatedProducts", targetNode);
                                     XmlAttribute attribute5 = (XmlAttribute) targetNode.Attributes.GetNamedItem("Culture");
                                     if ((attribute5 != null) && !string.IsNullOrEmpty(attribute5.Value))
                                     {
                                         string attributeValue = namedItem.Value + "." + attribute5.Value;
                                         this.AddAttribute(targetNode, "PackageCode", attributeValue);
                                         if ((results != null) && (results2 != null))
                                         {
                                             results.AddPackageResults(attribute5.Value, results2);
                                         }
                                         newChild.AppendChild(targetNode);
                                         flag = true;
                                     }
                                 }
                             }
                         }
                     }
                     if (flag)
                     {
                         rootElement.AppendChild(newChild);
                         if (!this.validationResults.Contains(namedItem.Value))
                         {
                             this.validationResults.Add(namedItem.Value, results);
                         }
                     }
                 }
             }
         }
     }
     catch (XmlException)
     {
     }
     catch (IOException)
     {
     }
     catch (ArgumentException)
     {
     }
 }