Example #1
0
        /// <summary>
        /// Create book packages index.
        /// </summary>
        /// <param name="bookGroup">
        /// The book Group associated with the book.
        /// </param>
        /// <param name="book">
        /// The book associated with the packages
        /// </param>
        /// <returns>
        /// The xml document text
        /// </returns>
        public static string CreateBookPackagesIndex(BookGroup bookGroup, Book book)
        {
            XDocument document = new XDocument(new XDeclaration("1.0", "utf-8", null), CreateElement("html", null, null));

            XElement headElement    = CreateElement("head", null, null);
            XElement metaDateElemet = CreateElement("meta", null, null);

            metaDateElemet.SetAttributeValue(XName.Get("http-equiv", string.Empty), "Date");
            metaDateElemet.SetAttributeValue(XName.Get("content", string.Empty), DateTime.Now.ToString("R", CultureInfo.InvariantCulture));
            headElement.Add(metaDateElemet);

            XElement bodyElement    = CreateElement("body", "book", null);
            XElement detailsElement = CreateElement("div", "details", null);

            XElement brandingPackageElement1 = CreateElement("a", "branding-package-link", null);
            XElement brandingPackageElement2 = CreateElement("a", "branding-package-link", null);
            XElement productLinkElement      = CreateElement("a", "product-link", null);

            productLinkElement.SetAttributeValue(XName.Get("href", string.Empty), Uri.EscapeDataString(bookGroup.CreateFileName()));

            detailsElement.Add(
                CreateElement("span", "name", book.Name),
                CreateElement("span", "description", book.Description),
                CreateElement("span", "vendor", "Microsoft"),
                CreateElement("span", "locale", book.Locale.Code),
                brandingPackageElement1,
                brandingPackageElement2);

            XElement packageListElement = CreateElement("div", "package-list", null);

            foreach (Package package in book.Packages)
            {
                XElement packageElement = CreateElement("div", "package", null);
                XElement linkElement    = CreateElement("a", "current-link", null);

                linkElement.SetAttributeValue(
                    XName.Get("href", string.Empty),
                    string.Format(CultureInfo.InvariantCulture, @"Packages\{0}", Uri.EscapeDataString(package.CreateFileName())));

                packageElement.Add(
                    CreateElement("span", "name", package.Name),
                    CreateElement("span", "deployed", "true"),
                    CreateElement("span", "package-etag", package.Tag),
                    CreateElement("span", "last-modified", package.LastModified.ToUniversalTime().ToString("O", CultureInfo.InvariantCulture)),
                    linkElement);

                packageListElement.Add(packageElement);
            }

            bodyElement.Add(detailsElement, packageListElement);
            if (document.Root != null)
            {
                document.Root.Add(headElement, bodyElement);
            }

            return(document.ToStringWithDeclaration());
        }
Example #2
0
        /// <summary>
        /// Create book packages index.
        /// </summary>
        /// <param name="bookGroup">
        /// The book Group associated with the book.
        /// </param>
        /// <param name="book">
        /// The book associated with the packages
        /// </param>
        /// <returns>
        /// The xml document text
        /// </returns>
        public static string CreateBookPackagesIndex( BookGroup bookGroup, Book book )
        {
            XDocument document = new XDocument( new XDeclaration( "1.0", "utf-8", null ), CreateElement( "html", null, null ) );

            XElement headElement = CreateElement( "head", null, null );
            XElement metaDateElemet = CreateElement( "meta", null, null );
            metaDateElemet.SetAttributeValue( XName.Get( "http-equiv", string.Empty ), "Date" );
            metaDateElemet.SetAttributeValue( XName.Get( "content", string.Empty ), DateTime.Now.ToString( "R", CultureInfo.InvariantCulture ) );
            headElement.Add( metaDateElemet );

            XElement bodyElement = CreateElement( "body", "book", null );
            XElement detailsElement = CreateElement( "div", "details", null );

            XElement brandingPackageElement1 = CreateElement( "a", "branding-package-link", null );
            XElement brandingPackageElement2 = CreateElement( "a", "branding-package-link", null );
            XElement productLinkElement = CreateElement( "a", "product-link", null );

            productLinkElement.SetAttributeValue( XName.Get( "href", string.Empty ), bookGroup.CreateFileName() );

            detailsElement.Add(
                CreateElement( "span", "name", book.Name ),
                CreateElement( "span", "description", book.Description ),
                CreateElement( "span", "vendor", "Microsoft" ),
                CreateElement( "span", "locale", book.Locale.Code ),
                brandingPackageElement1,
                brandingPackageElement2 );

            XElement packageListElement = CreateElement( "div", "package-list", null );

            foreach ( Package package in book.Packages )
            {
                XElement packageElement = CreateElement( "div", "package", null );
                XElement linkElement = CreateElement( "a", "current-link", null );

                linkElement.SetAttributeValue(
                    XName.Get( "href", string.Empty ),
                    string.Format( CultureInfo.InvariantCulture, @"Packages\{0}", package.CreateFileName() ) );

                packageElement.Add(
                    CreateElement( "span", "name", package.Name ),
                    CreateElement( "span", "deployed", "true" ),
                    CreateElement( "span", "package-etag", package.Tag ),
                    CreateElement( "span", "last-modified", package.LastModified.ToUniversalTime().ToString( "O", CultureInfo.InvariantCulture ) ),
                    linkElement );

                packageListElement.Add( packageElement );
            }

            bodyElement.Add( detailsElement, packageListElement );
            if ( document.Root != null )
            {
                document.Root.Add( headElement, bodyElement );
            }

            return document.ToStringWithDeclaration();
        }
Example #3
0
        /// <summary>
        /// Create book group books index.
        /// </summary>
        /// <param name="bookGroup">
        /// The book group to create the index for.
        /// </param>
        /// <returns>
        /// The xml document text
        /// </returns>
        public static string CreateBookGroupBooksIndex(BookGroup bookGroup)
        {
            XDocument document = new XDocument(new XDeclaration("1.0", "utf-8", null), CreateElement("html", null, null));

            XElement headElement    = CreateElement("head", null, null);
            XElement metaDateElemet = CreateElement("meta", null, null);

            metaDateElemet.SetAttributeValue(XName.Get("http-equiv", string.Empty), "Date");
            metaDateElemet.SetAttributeValue(XName.Get("content", string.Empty), DateTime.Now.ToString("R", CultureInfo.InvariantCulture));
            headElement.Add(metaDateElemet);

            XElement bodyElement    = CreateElement("body", "product", null);
            XElement detailsElement = CreateElement("div", "details", null);

            detailsElement.Add(
                CreateElement("span", "name", bookGroup.Name),
                CreateElement("span", "locale", bookGroup.Locale.Code),
                CreateElement("span", "description", bookGroup.Description));
            XElement bookListElement = CreateElement("div", "book-list", null);

            foreach (Book book in bookGroup.Books)
            {
                if (book.Wanted)
                {
                    XElement bookElement = CreateElement("div", "book", null);

                    XElement linkElement = CreateElement("a", "book-link", null);
                    linkElement.SetAttributeValue(XName.Get("href", string.Empty), book.CreateFileName());

                    bookElement.Add(
                        CreateElement("span", "name", book.Name),
                        CreateElement("span", "locale", book.Locale.Code),
                        CreateElement("span", "description", book.Description),
                        linkElement);

                    bookListElement.Add(bookElement);
                }
            }

            bodyElement.Add(detailsElement, bookListElement);
            if (document.Root != null)
            {
                document.Root.Add(headElement, bodyElement);
            }

            return(document.ToStringWithDeclaration());
        }
Example #4
0
        /// <summary>
        /// Create book group books index.
        /// </summary>
        /// <param name="bookGroup">
        /// The book group to create the index for.
        /// </param>
        /// <returns>
        /// The xml document text
        /// </returns>
        public static string CreateBookGroupBooksIndex( BookGroup bookGroup )
        {
            XDocument document = new XDocument( new XDeclaration( "1.0", "utf-8", null ), CreateElement( "html", null, null ) );

            XElement headElement = CreateElement( "head", null, null );
            XElement metaDateElemet = CreateElement( "meta", null, null );
            metaDateElemet.SetAttributeValue( XName.Get( "http-equiv", string.Empty ), "Date" );
            metaDateElemet.SetAttributeValue( XName.Get( "content", string.Empty ), DateTime.Now.ToString( "R", CultureInfo.InvariantCulture ) );
            headElement.Add( metaDateElemet );

            XElement bodyElement = CreateElement( "body", "product", null );
            XElement detailsElement = CreateElement( "div", "details", null );
            detailsElement.Add(
                CreateElement( "span", "name", bookGroup.Name ),
                CreateElement( "span", "locale", bookGroup.Locale.Code ),
                CreateElement( "span", "description", bookGroup.Description ) );
            XElement bookListElement = CreateElement( "div", "book-list", null );

            foreach ( Book book in bookGroup.Books )
            {
                if ( book.Wanted )
                {
                    XElement bookElement = CreateElement( "div", "book", null );

                    XElement linkElement = CreateElement( "a", "book-link", null );
                    linkElement.SetAttributeValue( XName.Get( "href", string.Empty ), book.CreateFileName() );

                    bookElement.Add(
                        CreateElement( "span", "name", book.Name ),
                        CreateElement( "span", "locale", book.Locale.Code ),
                        CreateElement( "span", "description", book.Description ),
                        linkElement );

                    bookListElement.Add( bookElement );
                }
            }

            bodyElement.Add( detailsElement, bookListElement );
            if ( document.Root != null )
            {
                document.Root.Add( headElement, bodyElement );
            }

            return document.ToStringWithDeclaration();
        }
Example #5
0
        /// <summary>
        /// Find the available book groups, books, and packages for the selected language
        /// </summary>
        /// <param name="data">
        /// The page data downloaded containing the book data
        /// </param>
        /// <returns>
        /// Collection of book groups for the help collection
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If data is null
        /// </exception>
        /// <exception cref="XmlException">
        /// If there was a error processing the xml data
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If there was a error processing the xml data
        /// </exception>
        public static ICollection<BookGroup> LoadBooks( byte[] data )
        {
            XDocument document;
            using ( MemoryStream stream = new MemoryStream( data ) )
            {
                document = XDocument.Load( stream );
            }

            if ( data == null )
            {
                throw new ArgumentNullException( "data" );
            }

            List<BookGroup> result = new List<BookGroup>();

            if ( document.Root != null )
            {
                IEnumerable<XElement> groups =
                    document.Root.Elements()
                            .Where( x => x.GetClassName() == "book-list" )
                            .Take( 1 )
                            .Single()
                            .Elements()
                            .Where( x => x.GetClassName() == "book-groups" )
                            .Take( 1 )
                            .Single()
                            .Elements()
                            .Where( x => x.GetClassName() == "book-group" );
                foreach ( XElement group in groups )
                {
                    BookGroup bookGroup = new BookGroup
                                        {
                                            Name = group.GetChildClassValue( "name" ),
                                            Code = group.GetChildClassValue( "id" ),
                                            Books = new List<Book>(),
                                            Locale = new Locale { Code = "en-us" },
                                            Description = group.GetChildClassValue( "name" )
                                        };

                    result.Add( bookGroup );

                    IEnumerable<XElement> books = group.Elements().Where( x => x.GetClassName() == "book" );
                    foreach ( XElement book in books )
                    {
                        XElement path =
                            book.Elements()
                                .Where( x => x.GetClassName() == "properties" )
                                .Take( 1 )
                                .Single()
                                .Elements()
                                .Where( x => x.GetClassName() == "paths" )
                                .Take( 1 )
                                .Single()
                                .Elements()
                                .Where( x => x.GetClassName() == "path" )
                                .Take( 1 )
                                .Single();
                        string bookPath = path.GetChildClassValue( "name" ).TrimStart( new[] { '\\' } );

                        Book b = new Book
                                    {
                                        Name = book.GetChildClassValue( "name" ),
                                        Description = book.GetChildClassValue( "description" ),
                                        Code = book.GetChildClassValue( "id" ),
                                        Packages = new List<Package>(),
                                        Locale = new Locale { Code = "en-us" },
                                        Category = bookPath
                                    };

                        bookGroup.Name = bookPath;
                        bookGroup.Books.Add( b );
                        IEnumerable<XElement> packages =
                            book.Elements()
                                .Where( x => x.GetClassName() == "packages" )
                                .Take( 1 )
                                .Single()
                                .Elements()
                                .Where( x => x.GetClassName() == "package" );
                        foreach ( XElement package in packages )
                        {
                            Package p = new Package
                                            {
                                                LastModified = DateTime.Parse( package.GetChildClassValue( "last-modified" ), CultureInfo.InvariantCulture ),
                                                Link = package.GetChildClassValue( "current-link" ),
                                                Tag = package.GetChildClassValue( "package-etag" ),
                                                Name = package.GetChildClassValue( "name" ),
                                                Size = long.Parse( package.GetChildClassValue( "package-size-bytes" ), CultureInfo.InvariantCulture )
                                            };

                            b.Packages.Add( p );
                        }
                    }
                }
            }
            else
            {
                throw new XmlException( "Missing document root" );
            }

            return result;
        }
Example #6
0
        /// <summary>
        /// Find the available book groups, books, and packages for the selected language
        /// </summary>
        /// <param name="data">
        /// The page data downloaded containing the book data
        /// </param>
        /// <returns>
        /// Collection of book groups for the help collection
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If data is null
        /// </exception>
        /// <exception cref="XmlException">
        /// If there was a error processing the xml data
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If there was a error processing the xml data
        /// </exception>
        public static ICollection <BookGroup> LoadBooks(byte[] data)
        {
            XDocument document;

            using (MemoryStream stream = new MemoryStream(data))
            {
                document = XDocument.Load(stream);
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            List <BookGroup> result = new List <BookGroup>();

            if (document.Root != null)
            {
                IEnumerable <XElement> groups =
                    document.Root.Elements()
                    .Where(x => x.GetClassName()?.Equals("book-list", StringComparison.OrdinalIgnoreCase) ?? false)
                    .Take(1)
                    .Single()
                    .Elements()
                    .Where(x => x.GetClassName()?.Equals("book-groups", StringComparison.OrdinalIgnoreCase) ?? false)
                    .Take(1)
                    .Single()
                    .Elements()
                    .Where(x => x.GetClassName()?.Equals("book-group", StringComparison.OrdinalIgnoreCase) ?? false);
                foreach (XElement group in groups)
                {
                    BookGroup bookGroup = new BookGroup
                    {
                        Name   = group.GetChildClassValue("name"),
                        Code   = group.GetChildClassValue("id"),
                        Books  = new List <Book>(),
                        Locale = new Locale {
                            Code = "en-us"
                        },
                        Description = group.GetChildClassValue("name")
                    };

                    result.Add(bookGroup);

                    IEnumerable <XElement> books = group.Elements().Where(x => x.GetClassName()?.Equals("book", StringComparison.OrdinalIgnoreCase) ?? false);
                    foreach (XElement book in books)
                    {
                        XElement path =
                            book.Elements()
                            .Where(x => x.GetClassName()?.Equals("properties", StringComparison.OrdinalIgnoreCase) ?? false)
                            .Take(1)
                            .Single()
                            .Elements()
                            .Where(x => x.GetClassName()?.Equals("paths", StringComparison.OrdinalIgnoreCase) ?? false)
                            .Take(1)
                            .Single()
                            .Elements()
                            .Where(x => x.GetClassName()?.Equals("path", StringComparison.OrdinalIgnoreCase) ?? false)
                            .Take(1)
                            .Single();
                        string bookPath = path.GetChildClassValue("name").TrimStart(new[] { '\\' });

                        Book b = new Book
                        {
                            Name        = book.GetChildClassValue("name"),
                            Description = book.GetChildClassValue("description"),
                            Code        = book.GetChildClassValue("id"),
                            Packages    = new List <Package>(),
                            Locale      = new Locale {
                                Code = "en-us"
                            },
                            Category = bookPath
                        };

                        bookGroup.Name = bookPath;
                        bookGroup.Books.Add(b);
                        IEnumerable <XElement> packages =
                            book.Elements()
                            .Where(x => x.GetClassName()?.Equals("packages", StringComparison.OrdinalIgnoreCase) ?? false)
                            .Take(1)
                            .Single()
                            .Elements()
                            .Where(x => x.GetClassName()?.Equals("package", StringComparison.OrdinalIgnoreCase) ?? false);
                        foreach (XElement package in packages)
                        {
                            Package p = new Package
                            {
                                LastModified = DateTime.Parse(package.GetChildClassValue("last-modified"), CultureInfo.InvariantCulture),
                                Link         = package.GetChildClassAttributeValue("current-link", "href"),
                                Tag          = package.GetChildClassValue("package-etag"),
                                Name         = package.GetChildClassValue("name"),
                                Size         = long.Parse(package.GetChildClassValue("package-size-bytes"), CultureInfo.InvariantCulture)
                            };

                            b.Packages.Add(p);
                        }
                    }
                }
            }
            else
            {
                throw new XmlException("Missing document root");
            }

            return(result);
        }