Beispiel #1
0
        //pass in the filename without
        // File: <catalogPath>\ContentStore\installedBooks.5.xml
        private void ReadFile_InstalledBooksXml()
        {
            String baseFilePath = Path.Combine(CatalogLocation, "ContentStore", "installedBooks.xml");
            String path = FileUtility.GetFileName(baseFilePath);  //Returns the actualy (latest version) filename
            if (!File.Exists(path))
                return;

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            XmlNode nodeInstalledBooks = xmlDoc.SelectSingleNode("//installed-books");      //root node
            if (nodeInstalledBooks == null)
                return;

            this._installedBooks = new InstalledBooks();

            //Check version -- Should be 1.0
            if (nodeInstalledBooks.Attributes["version"] != null)
            {
                _installedBooks.version = nodeInstalledBooks.Attributes["version"].InnerXml;
            }

            //<installed-books>
            //  <branding-packages>
            //    <brandingpackage locale="EN-US" vendorname="MICROSOFT" package="VISUALSTUDIO_2011_BRANDING_EN-US" />
            //  </branding-packages>
            //</installed-books>

            XmlNode nodeBrandingPackages = nodeInstalledBooks.SelectSingleNode("//branding-packages");
            if (nodeBrandingPackages != null && nodeBrandingPackages.HasChildNodes)
            {
                foreach (XmlNode n in nodeBrandingPackages.ChildNodes)
                {
                    if (n.Name == "brandingpackage"
                        && n.Attributes["locale"] != null
                        && n.Attributes["vendorname"] != null
                        && n.Attributes["package"] != null)
                    {
                        _installedBooks.brandingPackages.Add(new BrandingPackage(
                            n.Attributes["locale"].InnerXml,
                            n.Attributes["vendorname"].InnerXml,
                            n.Attributes["package"].InnerXml));
                    }
                }
            }

            //<installed-books version="3">
            //  <locale-membership>
            //     <locale name="EN-US">
            //     </locale>
            //     ...
            //  </locale-membership>
            //</installed-books>

            XmlNode nodeLocaleMembership = nodeInstalledBooks.SelectSingleNode("//locale-membership");
            if (nodeLocaleMembership == null || !nodeLocaleMembership.HasChildNodes)
                return;
            foreach (XmlNode n in nodeLocaleMembership.ChildNodes)   // <locale name="EN-US">... <locale name="fr-fr"> etc
            {
                if (n.Name == "locale" && n.Attributes["name"] != null)
                {
                    LocaleListItem localeItem = new LocaleListItem(n.Attributes["name"].InnerXml);
                    _installedBooks.localeList.Add(localeItem);

                    // Get Locale Book Lists
                    GetBookList(localeItem, n);

                }
            }
        }
Beispiel #2
0
        //<installed-books version="3">
        //  <locale-membership>
        //     <locale name="EN-US">   <---- nodeLocale
        //        <book-list>
        //           <book ref="urn:852e209f-1bdd-1349-13ba-eed3c6d86c9f" vendorname="Microsoft" displayname=".NET Framework 4" source="http://b25ddepxvm17.redmond.corp.microsoft.com:202/catalogs/visualstudio11/en-us" kind="Microsoft" productname="" productgroupname="" path="\Visual Studio\Visual Studio 2011\Visual Studio 2011 Ultimate" />
        //           ..
        //        </book-list>
        //        <book-membership>
        //           <book ref="urn:852e209f-1bdd-1349-13ba-eed3c6d86c9f">
        //              <package ref="VISUAL_STUDIO_21800791_VS_100_EN-US_2" />
        //              ..
        //           </book>
        //           ..
        //        </book-membership>
        //     </locale>
        //     ...
        //  </locale-membership>
        //</installed-books>
        private void GetBookList(LocaleListItem localeItem, XmlNode nodeLocale)
        {
            // Get Book List

            XmlNode nodeBookList = nodeLocale.SelectSingleNode("//book-list");  // <locale name="EN-US"><book-list>
            if (nodeBookList == null || !nodeBookList.HasChildNodes)
                return;

            foreach (XmlNode n in nodeBookList.ChildNodes)
            {
                if (n.Name == "book" && n.Attributes["ref"] != null)    // <book ref="urn:852e209f-1bdd-1349-13ba-eed3c6d86c9f" ...
                {
                    BookListItem bookListItem = new BookListItem(n.Attributes["ref"].InnerXml);
                    if (n.Attributes["vendorname"] != null)
                        bookListItem.vendorname = n.Attributes["vendorname"].InnerXml;
                    if (n.Attributes["displayname"] != null)
                        bookListItem.displayname = n.Attributes["displayname"].InnerXml;
                    if (n.Attributes["source"] != null)
                        bookListItem.source = n.Attributes["source"].InnerXml;
                    if (n.Attributes["kind"] != null)
                        bookListItem.kind = n.Attributes["kind"].InnerXml;
                    if (n.Attributes["productname"] != null)
                        bookListItem.productname = n.Attributes["productname"].InnerXml;
                    if (n.Attributes["productgroupname"] != null)
                        bookListItem.productgroupname = n.Attributes["productgroupname"].InnerXml;
                    if (n.Attributes["path"] != null)
                        bookListItem.path = n.Attributes["path"].InnerXml;

                    localeItem.bookList.Add(bookListItem);
                }
            }

            // Get Book Packages

            XmlNode nodeBookMembership = nodeLocale.SelectSingleNode("//book-membership");   // <locale name="EN-US"><book-membership>
            if (nodeBookMembership == null || !nodeBookMembership.HasChildNodes)
                return;

            foreach (XmlNode nodeBook in nodeBookMembership.ChildNodes)
            {
                if (nodeBook.Name == "book" && nodeBook.Attributes["ref"] != null)  // <book ref="urn:852e209f-1bdd-1349-13ba-eed3c6d86c9f">
                {
                    String BookRef = nodeBook.Attributes["ref"].InnerXml;

                    //Build a package list
                    String[] packageList = new String[nodeBook.ChildNodes.Count];
                    int x = 0;
                    foreach (XmlNode nodePackage in nodeBook.ChildNodes)
                    {
                        packageList[x] = nodePackage.Attributes["ref"].InnerXml;    //  <book ..><package ref="VISUAL_STUDIO_21800791_VS_100_EN-US_2" />...
                        x++;
                    }

                    // Insert this list into the appropriate BookListItem that we created above
                    // First find the linkNode using the ref member

                    for (int i = 0; i < localeItem.bookList.Count; i++)
                    {
                        if (localeItem.bookList[i].ref_ == BookRef)
                        {
                            localeItem.bookList[i].packageList = packageList;
                            break;
                        }
                    }
                }
            }
        }