'Reading sections of a stdout output and doing UI operations based on the output
I have a WPF application in which I am starting a process of Powershell from a different thread and redirecting the entire output to a textbox in the WPF window. The output of the window looks something like this:
STARTED PRODUCT 1 INSTALLATION
/* some lines here
more lines
*/
PRODUCT 1 INSTALLATION COMPLETE
What I want to do is that if, in between the STARTED and COMPLETE sections of text, any line or text containing "error" is spotted, I would like to update a particular icon and make it visible. Something like this:
if (text.Contains("error")
Product1RedCross.Visibility = Visibility.Visible;
else
Product1GreenTick.Visibility = Visibility.Visible;
This is showing kind of like a status by means of a red or green icon. If no error is spotted then it should display the green icon, showing that everything was fine.
My problem is that I have a bunch of different "Products". I would like to maybe take out chunks of text between "Started Product 1 installation" and "Product 1 installation complete" and check out if there is an error in there.
Otherwise, if an error is spotted, I won't be able to know for which product is the error being shown.
How can I achieve this and make it so that I can effectively determine where the error is and update the UI elements of that product accordingly.
My code for starting the process looks like this:
PowershellProcess.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
StringBuilderOutput.AppendLine(e.Data);
lock (this._myLockToken)
{
Dispatcher.BeginInvoke(
new ThreadStart(() => OutputTextBlock.Text = StringBuilderOutput.ToString()));
if (e.Data.Contains("PRODUCT 1 INSTALLATION STARTED"))
{
}
}
}
});
But here, I'm having trouble how I can work with sections of each product so that I can do UI operations without mixing other products up.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
