public GetLineEncoder ( string fileType ) : ILineEncoder | ||
fileType | string | |
return | ILineEncoder |
/// <summary> /// Combines all malevich sources with a particular extension into a single very big file, and runs /// a performance test on it. /// </summary> /// <param name="ext"></param> private static void TestBigFile(string baseDir, string ext, StreamWriter encodedFile, LineEncoderFactory factory) { Console.WriteLine("Testing performance of the encoder for {0}", ext); string bigFileNameTmp = "ReallyBigTest." + ext + ".tmp"; if (File.Exists(bigFileNameTmp)) File.Delete(bigFileNameTmp); StreamWriter bigFile = new StreamWriter(bigFileNameTmp); RecursivelyAddFileContent(bigFile, baseDir, ext); bigFile.Close(); ILineEncoder encoder = factory.GetLineEncoder(ext); StreamReader r = new StreamReader(bigFileNameTmp); int nLines = 0; DateTime start = DateTime.Now; for (; ; ) { string s = r.ReadLine(); if (s == null) break; if ("".Equals(s)) continue; ++nLines; encoder.EncodeLine(s, 80, "\\t"); } double ms = (DateTime.Now - start).TotalMilliseconds; encodedFile.WriteLine("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", ext, nLines, ms.ToString(), nLines == 0 ? 0.0 : (ms / nLines)); r.Close(); File.Delete(bigFileNameTmp); }
/// <summary> /// Test correctness of various encoders. /// </summary> /// <param name="encodedFile"></param> /// <param name="factory"></param> private static void CorrectnessTest(StreamWriter encodedFile, LineEncoderFactory factory) { DateTime now = DateTime.Now; string testFileName = "test.txt"; string baseDir = ""; for (int i = 0; i < 3; ++i) { if (File.Exists(testFileName)) break; testFileName = "..\\" + testFileName; baseDir = "..\\" + baseDir; } if (!File.Exists(testFileName)) { Console.Error.WriteLine( "Could not find file text.txt. It should be either in the same or in a parent directory."); return; } baseDir = "..\\" + baseDir; encodedFile.Write("<h1>Simple correctness test.</h1>"); encodedFile.WriteLine( "<table style=\"table-layout: fixed;border-collapse: collapse; font-family:consolas\">"); StreamReader testFile = new StreamReader(testFileName); StringBuilder css = new StringBuilder(); ILineEncoder encoder = null; for (; ; ) { string s = testFile.ReadLine(); if (s == null) break; if (s.StartsWith("start new file ")) { string ext = s.Substring(15); Console.WriteLine("Starting {0} @ {1}", ext, DateTime.Now - now); encoder = factory.GetLineEncoder(ext); Console.WriteLine("Got encoder for {0} @ {1}", ext, DateTime.Now - now); css.Append(encoder.GetEncoderCssStream().ReadToEnd()); continue; } if ("".Equals(s)) { encodedFile.WriteLine("<tr><td> </td></tr>"); continue; } if (encoder != null) encodedFile.WriteLine("<tr><td>{0}</td></tr>", encoder.EncodeLine(s, 80, "\\t")); } ListFile(baseDir + "notifier\\MailTemplates.cs", factory, encodedFile); ListFile(baseDir + "notifier\\Notifier.csproj", factory, encodedFile); ListFile(baseDir + "notifier\\Iteration.html", factory, encodedFile); ListFile(baseDir + "Database\\Schema Objects\\Schemas\\dbo\\Programmability\\Stored Procedures\\AddComment.proc.sql", factory, encodedFile); Console.WriteLine("All done @ {0}", DateTime.Now - now); if (encoder != null) encoder.Dispose(); encodedFile.WriteLine("</table><style>" + css.ToString() + "</style>"); testFile.Close(); }
/// <summary> /// Prints out a listing for a file. /// </summary> /// <param name="fileName"></param> /// <param name="factory"></param> /// <param name="encodedFile"></param> private static void ListFile(string fileName, LineEncoderFactory factory, StreamWriter encodedFile) { string ext = Path.GetExtension(fileName).Substring(1); string name = Path.GetFileName(fileName); encodedFile.WriteLine("<tr><td> </td></tr>"); encodedFile.WriteLine("<tr><td> </td></tr>"); encodedFile.WriteLine("<tr><td>{0}</td></tr>", name); encodedFile.WriteLine("<tr><td> </td></tr>"); ILineEncoder encoder = factory.GetLineEncoder(ext); StreamReader r = new StreamReader(fileName); for (; ; ) { string s = r.ReadLine(); if (s == null) break; if ("".Equals(s)) { encodedFile.WriteLine("<tr><td> </td></tr>"); continue; } encodedFile.WriteLine("<tr><td>{0}</td></tr>", encoder.EncodeLine(s, 80, "\\t")); } r.Close(); }