DebugReportHtmlFormatter.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Common » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Common » DebugReportHtmlFormatter.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace SokoSolve.Common{
    /// <summary>
    /// Format a calculation report into an HTML report
    /// <see cref="DebugReport"/>
    /// </summary>
  public class DebugReportHtmlFormatter : DebugReportFormatter
  {
        /// <summary>
        /// Header for the calculation report
        /// </summary>
        /// <param name="report">context</param>
        /// <returns>HTML</returns>
    public override string Header(DebugReport report)
    {
      return @"<html xmlns=""http://www.w3.org/1999/xhtml"" >
<head>
    <title>Untitled Page</title>
</head>
<body style=""font-family: Arial; font-size: 10pt;"">";
    }

        /// <summary>
        /// Footer for the calculation report
        /// </summary>
        /// <param name="report">context</param>
        /// <returns>HTML</returns>
    public override string Footer(DebugReport report)
    {
      return @"</body>
</html>";
    }

        /// <summary>
        /// Helper Genric. Return the previous item in the list or null.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="item"></param>
        /// <returns></returns>
    public static T Previous<T>(IList<T> source, T item)
    {
      if (source == null || source.Count == 0) return default(T);
      int idx = source.IndexOf(item);
      if (idx == 0) return default(T);
      return source[idx - 1];
    }

        /// <summary>
        /// Helper Generic. Return the next item in the list or null.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="item"></param>
        /// <returns></returns>
    public static T Next<T>(IList<T> source, T item)
    {
      if (source == null || source.Count == 0) return default(T);
      int idx = source.IndexOf(item);
      if (idx >= source.Count-1) return default(T);
      return source[idx + 1];
    }

        /// <summary>
        /// Render a report line as HTML
        /// </summary>
        /// <param name="report">context</param>
        /// <param name="line">current line to render</param>
        /// <returns>HTML</returns>
    public override string SetMarkUp(DebugReport report, DebugReport.ReportLine line)
    {
      if (string.IsNullOrEmpty(line.Text))
      {
        line.TextMarkUp = "<br/>";
        return line.TextMarkUp;
      }

      if (HasHint(line, "H1"))
      {
        line.TextMarkUp = string.Format("<h1>{0}</h1>{1}", line.Text, Environment.NewLine);
        return line.TextMarkUp;
      }

      if (HasHint(line, "H2"))
      {
        line.TextMarkUp = string.Format("<h2>{0}</h2>{1}", line.Text, Environment.NewLine);
        return line.TextMarkUp;
      }

      if (HasHint(line, "H3"))
      {
        line.TextMarkUp = string.Format("<h3>{0}</h3>{1}", line.Text, Environment.NewLine);
        return line.TextMarkUp;
      }

      if (HasHint(line, "H4"))
      {
        line.TextMarkUp = string.Format("<h4>{0}</h4>{1}", line.Text, Environment.NewLine);
        return line.TextMarkUp;
      }

      if (HasHint(line, "LI"))
      {
        string final = "";
        
        DebugReport.ReportLine before = Previous<DebugReport.ReportLine>(report.Report, line);
        if (!HasHint(before, "LI")) final = string.Format("<ul  style=\"text-indent: {0}px;\">", line.Depth * pixelIndent) + Environment.NewLine;


        final += string.Format("  <li>{0}</li>{1}", line.Text, Environment.NewLine);

        DebugReport.ReportLine after = Next<DebugReport.ReportLine>(report.Report, line);
        if (!HasHint(after, "LI")) final += "</ul>" + Environment.NewLine;

        return final;
      }
      

      if (HasHint(line, "LB"))
      {
        int idx = line.Text.IndexOf(": ");
        string label = line.Text.Substring(0, idx);
        string txt = line.Text.Substring(idx + 2, line.Text.Length - idx - 2);
        line.TextMarkUp = string.Format("<p style=\"text-indent: {3}px;\"><b>{0}</b> : {1}</p>{2}", label, txt, Environment.NewLine, line.Depth * pixelIndent);
        return line.TextMarkUp;
      }

      if (HasHint(line, "W"))
      {
        line.TextMarkUp = string.Format("<p style=\"color:red;\">WARNING</p>{0}{1}",  line.Text, Environment.NewLine);
        return line.TextMarkUp;
      }

      line.TextMarkUp = string.Format("<p style=\"text-indent: {2}px;\">{0}</p>{1}", line.Text, Environment.NewLine, line.Depth * pixelIndent);
      return line.TextMarkUp;
    }

        private int pixelIndent = 15;  
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.