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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }