/// <summary>
        /// Converts a UfDataNode structure into a very basic form HTML.
        /// </summary>
        /// <param name="node">Node</param>
        /// <param name="formatDescriber">Microformat format describer object</param>
        /// <returns>HTML string</returns>
        public string Convert(UfDataNode node, UfFormatDescriber formatDescriber)
        {
            string output = string.Empty;

            StringWriter       stringWriter     = new StringWriter();
            UfElementDescriber elementDescriber = formatDescriber.BaseElement;

            using (XhtmlTextWriter writer = new XhtmlTextWriter(stringWriter))
            {
                writer.WriteBeginTag("div");
                writer.WriteAttribute("class", "microformats");
                writer.Write(HtmlTextWriter.TagRightChar);

                foreach (UfDataNode child in node.Nodes)
                {
                    writer.WriteLine();
                    AddNode(child, elementDescriber, writer);
                }

                writer.WriteEndTag("div");
                writer.WriteLine();
            }

            return(stringWriter.ToString());
        }
        public bool Render(object o, string description, int depth, XhtmlTextWriter writer)
        {
            //there are two principal ways of rendering an object,
            // if it's an enumerable we render each object as a row in a table
            // if it's jut an object we render each property of the object as a row in a table

            if (!String.IsNullOrWhiteSpace(description))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.H3);
                writer.Write(description);
                writer.RenderEndTag();
                writer.WriteLine();
            }

            if (depth <= 0)
            {
                return(true);
            }

            if (o is IEnumerable && !(o is String))
            {
                return(RenderEnumerable((IEnumerable)o, depth, writer));
            }
            else
            {
                return(RenderObject(o, depth, writer));
            }
        }
        public bool RenderObject(object o, int depth, XhtmlTextWriter writer)
        {
            var objectType = o.GetType();

            if (IsSimpleType(objectType))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.P);
                writer.Write(o.ToString());
                writer.RenderEndTag();

                writer.WriteLine();
                return(true);
            }

            //get the members (fields and properties)
            var members = GetMembers(objectType);

            //create a two column table containing member and then value
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            //write a header containing the class name
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
            writer.RenderBeginTag(HtmlTextWriterTag.Th);
            writer.Write(objectType.Name);
            writer.RenderEndTag(); //th
            writer.RenderEndTag(); //tr

            foreach (var member in members)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "left");
                writer.RenderBeginTag(HtmlTextWriterTag.Th);
                writer.Write(member.Name);
                writer.RenderEndTag(); //th

                writer.RenderBeginTag(HtmlTextWriterTag.Td);
                RenderMember(member, o, depth, writer);
                writer.RenderEndTag(); //td
                writer.RenderEndTag(); //tr
            }

            writer.RenderEndTag(); //table

            writer.WriteLine();
            return(true);
        }
Esempio n. 4
0
        private void InitHeader()
        {
            writer.WriteLineNoTabs("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
            writer.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
            writer.AddAttribute("xml:lang", "en");
            writer.RenderBeginTag(HtmlTextWriterTag.Html);
            writer.RenderBeginTag(HtmlTextWriterTag.Head);

            writer.RenderBeginTag(HtmlTextWriterTag.Title);
            writer.Write("XhtmlDumper");
            writer.RenderEndTag();


            writer.AddAttribute("http-equiv", "content-type");
            writer.AddAttribute(HtmlTextWriterAttribute.Content, "text/html;charset=utf-8");
            writer.RenderBeginTag(HtmlTextWriterTag.Meta);
            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute(HtmlTextWriterAttribute.Name, "generator");
            writer.AddAttribute(HtmlTextWriterAttribute.Content, "XhtmlDumper");
            writer.RenderBeginTag(HtmlTextWriterTag.Meta);
            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute(HtmlTextWriterAttribute.Name, "description");
            writer.AddAttribute(HtmlTextWriterAttribute.Content, "Generated on: " + DateTime.Now);
            writer.RenderBeginTag(HtmlTextWriterTag.Meta);
            writer.RenderEndTag();
            writer.WriteLine();

            writer.AddAttribute("type", "text/css");
            writer.RenderBeginTag(HtmlTextWriterTag.Style);
            writer.WriteLineNoTabs(Resources.StyleSheet);
            writer.RenderEndTag(); // style

            writer.RenderEndTag(); // Head
            writer.WriteLine();

            writer.RenderBeginTag(HtmlTextWriterTag.Body);
        }
Esempio n. 5
0
        public Stream RenderPageEnd()
        {
            XhtmlTextWriter xhtmlWriter = new XhtmlTextWriter(Writer);

            xhtmlWriter.Indent = 3;

            // Flush writer contents to output.
            xhtmlWriter.Flush();

            if (ReportFooter != null && ReportFooter.Length > 0)
            {
                xhtmlWriter.RenderBeginTag("hr");
                xhtmlWriter.WriteEndTag("hr");

                //
                xhtmlWriter.AddAttribute("class", "footer");
                xhtmlWriter.RenderBeginTag("div");

                xhtmlWriter.Write(ReportFooter);
                xhtmlWriter.WriteEndTag("div");

                xhtmlWriter.RenderBeginTag("hr");
                xhtmlWriter.WriteEndTag("hr");

                xhtmlWriter.WriteLine(Writer.NewLine);
                // </h2>
            }
            //--------------------------------------------------------
            // No matter what state the Renderer left us in, close
            // off the <body> and <html> elements.
            //--------------------------------------------------------

            // </body>
            xhtmlWriter.WriteEndTag("body");

            // </html>
            xhtmlWriter.WriteEndTag("html");

            // Flush writer contents to output.
            xhtmlWriter.Flush();

            return(Writer.BaseStream);
        }
Esempio n. 6
0
        public virtual Stream Render(IDataSource dataSource)
        {
            XhtmlTextWriter xhtmlWriter = new XhtmlTextWriter(_writer);

            // <div class='core'>
            xhtmlWriter.AddAttribute("class", "core");
            xhtmlWriter.RenderBeginTag("div");
            xhtmlWriter.WriteLine(Writer.NewLine);


            //-----------------------------------------------------------------
            // If the 'Renderer' supports the ITextControl interface, we will
            // defer rendering of the 'Text' block to it. The assignment needs
            // to take place before 'DataBind' so the 'Renderer' can act
            // on the Text. (Maybe a token substitution will happen, perhaps!)
            //-----------------------------------------------------------------
            ITextControl _textControl = Renderer as ITextControl;

            if (_textControl != null)
            {
                _textControl.Text = Text;
            }

            // Bind the Data to the Renderer
            if (dataSource != null)
            {
                Renderer.DataSource = dataSource;
                Renderer.DataBind();
            }

            xhtmlWriter.Flush();

            // Render unto the Stream that which belongs to the Stream...
            Renderer.ID = ID;
            Renderer.RenderControl(xhtmlWriter);

            // </div>
            xhtmlWriter.WriteEndTag("div");

            xhtmlWriter.Flush();

            return(_writer.BaseStream);
        }
Esempio n. 7
0
        private string GenerateHtmlReport()
        {
            string htmlFullFilePath = Path.GetTempFileName() + Guid.NewGuid().ToString() + ".html";

            //_testsSummary = SummarizeRun();

            using (StreamWriter htmlStreamWriter = new StreamWriter(htmlFullFilePath))
            {
                using (System.Web.UI.XhtmlTextWriter writer = new XhtmlTextWriter(htmlStreamWriter, "  "))
                {
                    writer.WriteLine("<!DOCTYPE xhtml>");
                    writer.RenderBeginTag(HtmlTextWriterTag.Html); // Begin Html

                    //Write html Head:
                    writer.RenderBeginTag(HtmlTextWriterTag.Head); // Begin Head
                    writer.WriteLine(WriteHtmlReportHead());
                    writer.RenderEndTag();                         // End Head

                    //Write html Body:
                    using (HtmlGenericControl body = new HtmlGenericControl("body")) // Begin Body content
                    {
                        #region Header Creation
                        //body.Controls.Add(GenerateHeaderSection());
                        GenerateHeaderSection(body);
                        #endregion Header Creation

                        #region Navigation Creation
                        //body.Controls.Add(GenerateNavSection());
                        GenerateNavSection(body);
                        #endregion Navigator Creation

                        #region Article Creation
                        //body.Controls.Add(GenerateArticleSection());
                        GenerateArticleSection(body);
                        #endregion Article Creation

                        #region Modal Creation
                        using (HtmlGenericControl modal = new HtmlGenericControl("div"))
                        {
                            modal.Attributes.Add("id", "modal");
                            modal.Attributes.Add("class", "modal");
                            modal.Controls.Add(
                                new LiteralControl(
                                    "<span class=\"close\" onclick=\"closeModal()\">&times;</span>"));
                            modal.Controls.Add(
                                new LiteralControl("<img class=\"modal-content\" id=\"modalImg\">"));
                            modal.Controls.Add(new LiteralControl("<div id=\"caption\"></div>"));
                            body.Controls.Add(modal);
                        }
                        #endregion Modal Creation

                        #region footer Creation
                        using (HtmlGenericControl footer = new HtmlGenericControl("footer"))
                        {
                            body.Controls.Add(footer);
                        }
                        #endregion footer Creation

                        body.RenderControl(writer); // End Body content
                    }
                    writer.RenderEndTag();          // End Html
                }
            }

            return(htmlFullFilePath);
        }
        private void AddNode(UfDataNode node, UfElementDescriber elementDescriber, XhtmlTextWriter writer)
        {
            if (node.Name != string.Empty)
            {
                indentNum++;
                writer.Indent = indentNum;

                UfElementDescriber currentDescriber = elementDescriber;
                foreach (UfElementDescriber childElementDescriber in elementDescriber.Elements)
                {
                    if (node.Name == childElementDescriber.Name || node.Name == childElementDescriber.CompoundName)
                    {
                        currentDescriber = childElementDescriber;
                    }
                }

                if (currentDescriber.Attribute == "class")
                {
                    writer.WriteBeginTag("div");
                    if (currentDescriber.CompoundName == "")
                    {
                        writer.WriteAttribute("class", node.Name);
                    }
                    else
                    {
                        writer.WriteAttribute("class", node.Name + " " + currentDescriber.Name);
                    }

                    if (!string.IsNullOrEmpty(node.ElementId))
                    {
                        writer.WriteAttribute("id", node.ElementId);
                    }

                    writer.Write(HtmlTextWriter.TagRightChar);
                    writer.WriteEncodedText(node.Value);


                    foreach (UfDataNode child in node.Nodes)
                    {
                        writer.WriteLine();
                        AddNode(child, currentDescriber, writer);
                    }


                    if (node.Name != string.Empty)
                    {
                        writer.WriteEndTag("div");
                        writer.WriteLine();
                    }
                }

                if (currentDescriber.Attribute == "rel")
                {
                    writer.WriteBeginTag("a");
                    writer.WriteAttribute("href", node.DescendantValue("link"));
                    writer.WriteAttribute("rel", node.Name);
                    writer.Write(HtmlTextWriter.TagRightChar);

                    writer.WriteEncodedText(node.DescendantValue("text"));
                    writer.WriteEndTag("a");
                    writer.WriteLine();
                }

                indentNum--;
                writer.Indent = indentNum;
            }
        }
Esempio n. 9
0
        public Stream RenderPageBegin()
        {
            XhtmlTextWriter xhtmlWriter = new XhtmlTextWriter(Writer);

            xhtmlWriter.Indent = 3;

            xhtmlWriter.AddAttribute("xmlns", "http://www.w3.org/1999/xhtml");
            xhtmlWriter.RenderBeginTag("html");

            xhtmlWriter.RenderBeginTag("head");
            if (ReportHeading != null && ReportHeading.Length > 0)
            {
                xhtmlWriter.RenderBeginTag("title");
                xhtmlWriter.Write(ReportHeading);
                xhtmlWriter.WriteEndTag("title");
            }

            // <style type='text/css'>
            xhtmlWriter.WriteLine(Writer.NewLine);
            xhtmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
            xhtmlWriter.RenderBeginTag("style");
            foreach (var style in _styles)
            {
                xhtmlWriter.WriteLine(style.Key);
                xhtmlWriter.WriteLine("{");
                xhtmlWriter.WriteLine(style.Value);
                xhtmlWriter.WriteLine("}");
            }
            xhtmlWriter.WriteEndTag("style");
            xhtmlWriter.WriteLine(Writer.NewLine);
            // </style>

            xhtmlWriter.WriteEndTag("head");

            // <body>
            xhtmlWriter.RenderBeginTag("body");

            if (ReportHeading != null && ReportHeading.Length > 0)
            {
                // <h2 class='heading'>
                xhtmlWriter.AddAttribute("class", "heading");
                xhtmlWriter.RenderBeginTag("h2");
                xhtmlWriter.Write(ReportHeading);
                xhtmlWriter.WriteEndTag("h2");
                xhtmlWriter.WriteLine(Writer.NewLine);
                // </h2>
            }

            if (!(Renderer is ITextControl) && Text != null && Text.Length > 0)
            {
                // <p class='text'>
                xhtmlWriter.AddAttribute("class", "caption");
                xhtmlWriter.RenderBeginTag("p");
                xhtmlWriter.Write(Text);
                xhtmlWriter.WriteEndTag("p");
                xhtmlWriter.WriteLine(Writer.NewLine);
                // </p>
            }

            // Flush writer contents to output.
            xhtmlWriter.Flush();

            return(Writer.BaseStream);
        }
Esempio n. 10
0
 public bool Render(object o, string description, int depth, XhtmlTextWriter writer)
 {
     writer.WriteLine(o);
     return(true);
 }
        public bool RenderEnumerable(IEnumerable enumerable, int depth, XhtmlTextWriter writer)
        {
            var elementType = GetElementTypeOfEnumerable(enumerable);

            if (elementType == null)
            {
                return(false);
            }

            //get the members (fields and properties)
            var members = GetMembers(elementType);

            //write the headers and start the table
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            //if the element type is an element that needs to be rendered atomically we use a different method
            if (IsSimpleType(elementType))
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                writer.RenderBeginTag(HtmlTextWriterTag.Th);
                writer.Write(elementType.Name);
                writer.RenderEndTag();
                writer.RenderEndTag();

                foreach (var element in enumerable)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    writer.Write(element.ToString());
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                }
            }
            else
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                foreach (var member in members)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Th);
                    writer.Write(member.Name);
                    writer.RenderEndTag();
                }
                writer.RenderEndTag(); //tr
                writer.WriteLine();

                //write all the members
                foreach (var element in enumerable)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    foreach (var member in members)
                    {
                        writer.RenderBeginTag(HtmlTextWriterTag.Td);
                        RenderMember(member, element, depth, writer);
                        writer.RenderEndTag(); //td
                    }
                    writer.RenderEndTag();     //tr
                    writer.WriteLine();
                }
            }

            //end the table
            writer.RenderEndTag();

            writer.WriteLine();
            return(true);
        }