Reputation: 14477
I'm working on a little script in LINQPad for automatic batch mailing. Despite having the data being validated by the script, I would like to have it checked by someone and his confirmation. And, the following is my attempt at the sanity check :
var datasource = Enumerable.Range(0, 10) //not actual data
.Dump("Data", true);
var message = string.Format("Please enter {0} to confirm or -1 to cancel : ", datasource.Count());
var container = new DumpContainer(message).Dump("Last Confirmation");
do
{
var result = Console.ReadLine();
container.Content = (container.Content as string) + result;
if (result == "-1") return;
if (result == datasource.Count().ToString()) break;
container.Content = (container.Content as string) + "\n" + message;
} while (true);
//do stuffs...
Most of it work great, except that the datasource
is not being dumped until end of execution which defeat whole purpose of this block of code. How can I make the Data tab display immediately?
Please note that I intended to dump the datasource
into a new DataGrid
tab, as it cannot be easily scanned through nor exported to excel.
Upvotes: 4
Views: 873
Reputation: 30934
This is now fixed in v4.51.03 (in beta at time of writing).
Use the new Util.ReadLineAsync method:
for (int i = 0; i < 10; i++)
{
int x = await Util.ReadLineAsync<int> ("Enter a number");
Enumerable.Range (0, x).Dump (x + " integers", true);
}
Upvotes: 2
Reputation: 14477
Here is a cheat I found to get around this problem : Hyperlinq
void Main()
{
var datasource = Enumerable.Range(0, 10) //not actual data
.Dump("Data", true);
Console.Write("Please confirm everything is correct : "); //couldnt manage to get them to dump on same line
new Hyperlinq(() => DoStuffs(datasource), "Do Stuffs").Dump();
}
// Define other methods and classes here
public void DoStuffs(IEnumerable<int> datasource)
{
datasource.Select(x => 2 * x).Dump("Altered Data", true);
new Hyperlinq(() => DoStuffs(datasource), "Do More Stuffs").Dump();
}
There is also a minor annoyance/bug that is introduced with this cheat. When there isn't enough rows in the datagrid to occupy the entire area an ArgumentOutOfRangeException
is thrown and dump to the result panel, but doesn't break the flow of execution.
Upvotes: 0