Default container for Dump()
I have scripts already working that dumps using LINQPad.Extensions.Dump().
I'd like to "#load" those scripts where each have a dedicated DumpContainer on the "Main interface", is there a way to redirect the default Dump to a specific container
(the ideal would be to have a DC for each load directive)
var dc = new DumpContainer().Dump();
[...]
DumpOptions.Default.Container = dc;
// Wich would make the 2 lines above equivalent
"test".Dump();
dc.AppendContent("test");
Answers
-
Methods in #load-ed scripts are merged via partial class definitions. I'm not sure that it would be possible for the Dump method to reliably identify which script contained the method from which it was called.
If you run another script via Util.Run, it executes independently in a separate process, so it's easy to isolate its output, but I'm not sure that this would do what you want.
-
here is what I came with, not sure this is the best solution
// Just for the example var tokens = new List<string>(); tokens.Add(Quote(@"C:\Program Files\7-Zip\7z.exe")); tokens.Add("a"); // Append tokens.Add("-mx9"); // Maximum compression tokens.Add("-xr!*.pdb"); // No PDB tokens.Add("-bsp1"); // With progress tokens.Add(Quote(zipFile)); foreach (var path in paths) tokens.Add(Quote(path)); RunHelper.Run(string.Join(" ", tokens)); internal static class RunHelper { // Hack to constrain Util.Cmd in a Bordered/Fixed-height/Auto-scrolled DumpContainer internal void Run(string cmd) { var dc = new DumpContainer(); var ctrl = dc.ToControl().AddStyle("border", "1px solid #ccc").AddStyle("max-height", "100px").AddStyle("overflow", "auto").Dump(); foreach (var line in Util.Cmd(cmd, true, true)) { dc.AppendContent(line); ctrl.ScrollToBottom(); } Task.Delay(100).ContinueWith(_ => ctrl.ScrollToBottom()); // This one because I alway miss the last bit } } internal static class ControlEx { extension(Control self) { public void ScrollToBottom() => self.HtmlElement.Run("targetElement.scrollTo(0, targetElement.scrollHeight);"); } }
