HtmlBuilder.cs :  » Game » SokoSolve-Sokoban » SokoSolve » UI » Controls » Web » 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 » UI » Controls » Web » HtmlBuilder.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using SokoSolve.Core;
using SokoSolve.Core.Model;

namespace SokoSolve.UI.Controls.Web{
    /// <summary>
    /// Simple HTML builder for consistency
    /// </summary>
    public class HtmlBuilder
    {
        public string GetHTMLPage()
        {
            StringBuilder result = new StringBuilder();
            result.AppendFormat(header, title, fileCSS);
            result.Append(htmlBody.ToString());
            result.Append(footer);
            return result.ToString();
        }

        public string GetHTMLBody()
        {
            return htmlBody.ToString();
        }

        public void Add(string fragment)
        {
            if (fragment == null) return;

            htmlBody.Append(fragment);
        }

        public void Add(HtmlBuilder body)
        {
            if (body == null) return;

            htmlBody.Append(body.GetHTMLBody());
        }

        public void Add(string fragmentFormat, params object[] parm)
        {
            if (string.IsNullOrEmpty(fragmentFormat)) return;
            Add(string.Format(fragmentFormat, parm));
        }

        public void AddLine(string fragmentFormat, params object[] parm)
        {
            if (string.IsNullOrEmpty(fragmentFormat)) return;
            Add(string.Format(fragmentFormat, parm)+"<br/>");
        }

        public void AddLabel(string label, string format, params object[] parm)
        {
            if (label == null) return;
            if (string.IsNullOrEmpty(format)) return;
            Add("<b>{0}</b>: {1}<br/>{2}", label, format == null ? "" : string.Format(format, parm), Environment.NewLine);
        }

        /// <summary>
        /// Add a temp image, by creating a temp image.
        /// </summary>
        /// <param name="Image"></param>
        public void Add(PuzzleMap PuzzleMap, Image Image, string style)
        {
            string tmpFile = ImageFileCache.Singleton.GetImageURL(PuzzleMap);
            if (tmpFile == null)
            {
                tmpFile = ImageFileCache.Singleton.AddSaveImage(PuzzleMap, Image);
            }
            Add("<img src=\"{0}\" style=\"{1}\" alt=\"SokoSolve\"/>", tmpFile, style);
        }

        public void AddSection(string title)
        {
            if (title != null) Add("<h{0}>{1}</h{0}>", currentDepth, title);

            currentDepth++;
        }

        public void EndSection()
        {
            currentDepth--;
        }

        public override string ToString()
        {
            return GetHTMLPage();
        }


        private string fileCSS = FileManager.GetContent("$html/style.css");
        private string header = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">
<html xmlns=""http://www.w3.org/1999/xhtml"">
  <head>
    <title>{0}</title>
    <link type=""text/css"" rel=""Stylesheet"" href=""{1}"" />
  </head>
  <body>";
        private string footer = @"  </body>
</html>";
        private string title = "SokoSolve";
        private StringBuilder htmlBody = new StringBuilder();
        private int currentDepth = 1;
    }
}


www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.