DebugReportFormatter.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 » DebugReportFormatter.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace SokoSolve.Common{

    /// <summary>
    /// Format a calculation report into a fixed-width debug style text-only report.
    /// <see cref="DebugReport"/>
    /// </summary>
  public class DebugReportFormatter
  {    
        /// <summary>
        /// Render a line as final markup
        /// </summary>
        /// <param name="report">Report source</param>
        /// <param name="line">The current line to format</param>
        /// <returns>final string including markup</returns>
    public virtual string SetMarkUp(DebugReport report, DebugReport.ReportLine line)
    {
      if (HasHint(line, "H1"))
      {
        line.TextMarkUp = MakeLineMulti(line, new object[] {"", "=========================================", line.Text, "=========================================" });
        return line.TextMarkUp;
      }

      if (HasHint(line, "H2"))
      {
                line.TextMarkUp = MakeLineMulti(line, new object[] { "", "----------------------------------------------------------------------------", line.Text, "----------------------------------------------------------------------------" });
        return line.TextMarkUp;
      }

      if (HasHint(line, "H3"))
      {
        line.TextMarkUp = MakeLine(line, "====== {0} ======", line.Text);
        return line.TextMarkUp;
      }

      if (HasHint(line, "H4"))
      {
        line.TextMarkUp = MakeLine(line, "---- {0} ----", line.Text);
        return line.TextMarkUp;
      }

      if (HasHint(line, "LI"))
      {
        line.TextMarkUp = MakeLine(line, "{0} o {1}", indent, line.Text);
        return line.TextMarkUp;
      }

      if (HasHint(line, "LB"))
      {
        line.TextMarkUp = MakeLine(line, line.Text);
        return line.TextMarkUp;
      }

      if (HasHint(line, "W"))
      {
        line.TextMarkUp = MakeLine(line, "*** WARNING *** {0}", line.Text);
        return line.TextMarkUp;
      }

      return MakeLine(line, line.Text);
    }

        /// <summary>
        /// Content block (markup) at the top of the report
        /// </summary>
        /// <param name="report">context</param>
        /// <returns>markup</returns>
        public virtual string Header(DebugReport report)
        {
            return string.Empty;
        }

        /// <summary>
        /// Content block (markup) at the foot of the report
        /// </summary>
        /// <param name="report">context</param>
        /// <returns>markup</returns>
        public virtual string Footer(DebugReport report)
        {
            return string.Empty;
        }


        /// <summary>
        /// Helper function
        /// </summary>
        /// <param name="reportLine">line in question</param>
        /// <param name="format">string.format literal</param>
        /// <param name="args">parameters</param>
        /// <returns>markup text</returns>
    string MakeLine(DebugReport.ReportLine reportLine, string format, params  object [] args)
    {
      return MakeLineMulti(reportLine, format == null ? new object[] { "" } : new object[] { string.Format(format, args) } );
    }

        /// <summary>
        /// Helper funcation
        /// </summary>
        /// <param name="reportLine">line in question</param>
        /// <param name="parm">a numer of lines to add as a single line</param>
        /// <returns>markup text</returns>
    string MakeLineMulti(DebugReport.ReportLine reportLine,  object [] parm)
    {
      StringBuilder sb = new StringBuilder();
      foreach(object line in parm)
      {
        // Add indent
        for (int cc = 0; cc < reportLine.Depth; cc++) sb.Append(indent);

        // Add text
        if (line != null) sb.Append(line.ToString());

        // Add linebreak
        //if (parm.Length > 0 && line != parm[parm.Length-1])
        
        sb.Append(Environment.NewLine);
        
      }
      return sb.ToString();
    }

        /// <summary>
        /// Helper Method. Is there an additional 'hint' to provide information outside of the scope of the simple debug report content model.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="hint">apply a string.IndexOf(...)</param>
        /// <returns></returns>
    protected bool HasHint(DebugReport.ReportLine line, string hint)
    {
      if (line == null) return false;
      if (line.Hints == null) return false;
      return line.Hints.IndexOf(hint) >= 0;
    }

        /// <summary>
        /// Literal to use for 1xindent
        /// </summary>
        private string indent = "   ";
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.