Open akshinmustafayev opened 2 years ago
Do you mean that crashes any time it's in a TabControl?
Yes. To be specific, when binding is used
I will have a look and see if I can figure out why. I have to admit I haven't touched this code in years, but I have a PR to review anyway....
I have some ideas regarding improving this control.
More detailed explanation:
By this I mean during testing I was getting custom design in the console. Seemed like it is not a default PowerShell view like this:
During PowerShell scripts` execution output was mixing with previous lines, it was not properly showed as it would be in default PowerShell console.
By this I mean interaction with the control must be as easy as possible. For example these public functions must be implemented:
public void Invoke(string PowerShellCode);
public void Invoke(string PathToPSFile);
public string Invoke(string PowerShellCode);
public string Invoke(string PathToPSFile);
public string Invoke(Command MyCommand);
public bool DisableConsoleOutput(); // false by default
so usage could be:
// in this scenario output goes directly to our console
myPoshConsoleControl.Invoke(@"D:\script.ps1");
or
// in this scenario output does not go to console
myPoshConsoleControl.DisableConsoleOutput = true;
var result = myPoshConsoleControl.Invoke(@"D:\script.ps1");
// Note: Output goes to textbox control as script continues to execute
await foreach (var outputEvent in result.ListenAsync())
{
switch (outputEvent)
{
case StartedOutputEvent started:
{
MessageBox.Show("script started");
}
break;
case StandardOutputEvent stdOut:
{
textBox1.Text += stdOut;
}
break;
case StandardErrorEvent stdErr:
{
if (stdErr.Text != "")
{
textBox2.Text += stdErr;
}
}
break;
case ExitedCommandEvent exited:
{
MessageBox.Show("script ended");
}
break;
}
}
or
// buffers
var stdOutBuffer = new StringBuilder();
var stdErrBuffer = new StringBuilder();
// set result to buffers
myPoshConsoleControl.Invoke(@"D:\script.ps1").WithStandardOutputPipe(stdOutBuffer).WithStandardErrorPipe(stdErrBuffer);
// Set values to textboxes after execution finishes
textBox1.Text = stdOutBuffer;
textBox2.Text = stdErrBuffer;
or using Command class
Nut much to explain, but the following must be considered:
Implementation of such control seems very complicated to me. Don`t know even how to achieve this. I have been looking for such control for my application EasyJob with no luck. In my application I just write output to rich text box, which absolutely does not give any PowerShell console integration experience.
When I try to use control with binding in my TabControl.ContentTemplate application crashes.
Everything is fine if I get it out of TabControl and dont use binding.
My goal is to use separate independent PowerShell console host sessions for each TabItem.