// write all transform outputs to a file. used for debugging. internal void WriteAllOutputs(string outputFolder) { var dir = Directory.CreateDirectory(outputFolder); // clean the directory foreach (var entry in dir.EnumerateFileSystemInfos()) { entry.Delete(); } LanguageWriter languageWriter = new CSharpWriter(); int count = 0; foreach (var transformer in transformers) { if (transformer.OutputEqualsInput) { continue; } count++; string filename = outputFolder + @"\" + count.ToString() + " " + transformer.Transform.Name + ".txt"; using (var writer = new StreamWriter(filename)) { foreach (ITypeDeclaration itd in transformer.transformMap.Values) { SourceNode node = languageWriter.GeneratePartialSource(itd); LanguageWriter.WriteSourceNode(writer, node); } } } }
//if transformer equals null create a file without source code viewer private void WriteFile(string path, string fileName, CodeTransformer transformer = null) { LanguageWriter languageWriter = new CSharpWriter(); HtmlWriteHelper htmlWriter = new HtmlWriteHelper(); htmlWriter.WriteLine("<!DOCTYPE html>"); htmlWriter.WriteLine(); htmlWriter.OpenTag("head"); //link styles htmlWriter.OpenTag("style", "type=\"text/css\""); htmlWriter.WriteLine("a:link { text-decoration: none; }"); htmlWriter.WriteLine("a:visited { text-decoration: none; }"); htmlWriter.WriteLine("a:active { text-decoration: none; }"); htmlWriter.WriteLine("a:active { text-decoration: underline; color: red; }"); htmlWriter.WriteLine("pre { margin: 0px; }"); htmlWriter.WriteLine("code { margin: 0px; }"); htmlWriter.CloseTag(); htmlWriter.CloseTag(); htmlWriter.OpenTag("body", "style=\"overflow-x: hidden; overflow-y: hidden\""); //main grid htmlWriter.OpenTag("div", "style=\"display: grid; grid-template-columns: auto auto; grid-column-gap: 10px; justify-content: start\""); //file names list // "display: grid" makes it expand to fill the vertical space htmlWriter.OpenTag("ol", "style=\"grid-column: 1; display: grid; overflow-y: auto;\""); int count = 1; foreach (var tuple in fileNames) { htmlWriter.OpenTag("li"); if (tuple.Key != transformer) { htmlWriter.OpenTag("a", $"style=\"link\" href=\"{Path.Combine(Path.GetFullPath(path), tuple.Value)}\""); } else { htmlWriter.OpenTag("a", $"style=\"color: red\" href=\"{Path.Combine(Path.GetFullPath(path), tuple.Value)}\""); } htmlWriter.WriteLine(tuple.Key.GetFriendlyName()); htmlWriter.CloseTag(); htmlWriter.CloseTag(); count++; } htmlWriter.CloseTag(); htmlWriter.WriteLine(); //code viewer // height is 99vh to make room for the scrollbar htmlWriter.OpenTag("div", "class=\"container\" style=\"grid-column: 2; display: grid; overflow: auto; max-height: 99vh; max-width: 100vw\""); //write source code if (transformer != null) { htmlWriter.OpenTag("pre"); htmlWriter.OpenTag("code", "class=\"language-csharp\""); if (transformer.Transform.Context.Results.ErrorCount > 0) { foreach (var error in transformer.Transform.Context.Results.ErrorsAndWarnings) { foreach (var line in StringUtil.Lines(error.ToString())) { htmlWriter.Append("// "); htmlWriter.Append(ToHtmlContent(line)); htmlWriter.Append(Environment.NewLine); } htmlWriter.Append(Environment.NewLine); } } foreach (ITypeDeclaration itd in transformer.transformMap.Values) { using (var writer = new StringWriter()) { SourceNode node = languageWriter.GeneratePartialSource(itd); LanguageWriter.WriteSourceNode(writer, node); string code = ToHtmlContent(writer.ToString().Trim()); htmlWriter.Append(code); } } htmlWriter.CloseTag(); htmlWriter.CloseTag(); htmlWriter.CloseTag(); htmlWriter.CloseTag(); //highlighting htmlWriter.OpenTag("link", "rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs2015.min.css\"", true); htmlWriter.OpenTag("script", "src=\"https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js\"", true); htmlWriter.OpenTag("script"); htmlWriter.WriteLine("hljs.initHighlightingOnLoad();"); } else { htmlWriter.CloseTag(); } htmlWriter.CloseTag(); htmlWriter.CloseTag(); htmlWriter.SaveToFile(Path.Combine(path, fileName)); }