CodeSiter

Form1.cs
Form1.Designer.cs
Program.cs
Properties\AssemblyInfo.cs
Properties\Resources.Designer.cs
Properties\Settings.Designer.cs

using

System;

using

System.Collections.Generic;

using

System.ComponentModel;

using

System.Data;

using

System.Drawing;

using

System.Text;

using

System.Windows.Forms;

using

System.Xml;

using

System.IO;

namespace

CodeSiter {

public

partial

class

Form1 : Form {

//private TreeNode root = null;

private

string[] kw = { "abstract", "event", "new", "struct", "as", "explicit", "null", "switch", "base", "extern", "object", "this", "bool", "false", "operator", "throw", "break", "finally", "out", "true", "byte", "fixed", "override", "try", "case", "float", "params", "typeof", "catch", "for", "private", "uint", "char", "foreach", "protected", "ulong", "checked", "goto", "public", "unchecked", "class", "if", "readonly", "unsafe", "const", "implicit", "ref", "ushort", "continue", "in", "return", "using", "decimal", "int", "sbyte", "virtual", "default", "interface", "sealed", "volatile", "delegate", "internal", "short", "void", "do", "is", "sizeof", "while", "double", "lock", "stackalloc", "else", "long", "static", "enum", "namespace", "string", "get", "partial", "set", "value", "where", "yield" };

private

List keywords;

private

string

assembly;

private

string

file;

public

Form1() { InitializeComponent(); keywords =

new

List(); keywords.AddRange(kw); }

private

void

button1_Click(object sender, EventArgs e) { openFileDialog1.Filter = "C# Projects|*.csproj";

if

(openFileDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = openFileDialog1.FileName; file = openFileDialog1.FileName; ReadProject(openFileDialog1.FileName);

//CreatePage(root.FirstNode.Text);

foreach

(ListViewItem lvi

in

listView1.Items) { CreatePage(lvi.Text); } } }

private

void

ReadProject(string filename) { XmlTextReader xtr =

new

XmlTextReader(filename);

while

(xtr.Read()) {

switch

(xtr.NodeType) {

case

XmlNodeType.Element:

if

(xtr.Name == "AssemblyName") {

// //root = new TreeNode(xtr.ReadInnerXml());

// //treeView1.Nodes.Add(root);

// listView1.Items.Add(xtr.ReadInnerXml());

assembly = xtr.ReadInnerXml(); }

if

(xtr.Name == "Compile") { xtr.MoveToAttribute(0); listView1.Items.Add(xtr.Value.ToString());

//root.Nodes.Add(xtr.Value.ToString());

} break; } }

//treeView1.ExpandAll();

}

private

string

CreateHead(string filename) { StringBuilder sb =

new

StringBuilder(); sb.Append("\r\n"); sb.Append(""); sb.Append(""); sb.Append(filename); sb.Append(""); sb.Append("\r\n\r\n"); sb.Append("
"); sb.Append("

"); sb.Append(assembly); sb.Append("

");

foreach

(ListViewItem lvi

in

listView1.Items) {

if

(lvi.Text == filename) { sb.Append(lvi.Text.Replace('\\', '.')); sb.Append("
\r\n"); }

else

{ sb.Append(""); sb.Append(lvi.Text); sb.Append(""); sb.Append("
\r\n"); } } sb.Append("
");

return

sb.ToString(); }

private

void

CreatePage(string filename) { TextReader tr =

new

StreamReader(filename); filename = filename.Replace('\\', '.');

if

(!Directory.Exists("html")) Directory.CreateDirectory("html"); TextWriter tw =

new

StreamWriter("html\\" + filename + ".html"); char[] separators = { ' ' };

// write the html header

tw.WriteLine(CreateHead(filename)); tw.WriteLine("
"); tw.WriteLine("
"); 
 
            

string

line; StringBuilder oline;

while

((line = tr.ReadLine()) != null) { oline =

new

StringBuilder();

if (line.Contains("//"))

{ oline.Append("

"); oline.Append(line); oline.Append("

"); }

else

{ string[] tok = line.Split(separators);

for

(int i = 0; i < tok.Length; i++) {

if

(keywords.Contains(tok[i])) {

//tw.Write("

" + tok[i] + "

");

oline.Append("

"); oline.Append(tok[i]); oline.Append("

"); }

else

{

//tw.Write(tok[i] + " ");

oline.Append(tok[i]); oline.Append(' '); } } }

//tw.Write("
\r\n");

//oline.Append("
\r\n");

tw.WriteLine(oline.ToString()); } tw.WriteLine("
"); tr.Close(); tw.Flush(); tw.Close(); }

private

void

listView1_SelectedIndexChanged(object sender, EventArgs e) {

//MessageBox.Show(listView1.SelectedItems.Count.ToString());

if

(listView1.SelectedItems.Count == 1) {

string

path = file.Remove(file.LastIndexOf('\\'));

string

loc = path + "\\html\\" + listView1.SelectedItems[0].Text.Replace('\\', '.') + ".html"; Uri new_uri;

if

(Uri.TryCreate(loc, UriKind.Absolute,

out

new_uri)) { webBrowser1.Url = new_uri; }

else

{ MessageBox.Show("Can't create URI

for

location:" + loc); } } } } }