Iam trying to get the status of the script in asp.net, But it doesn't support this keyword in PiplelineExecutor function. I have given my code. below.
pipelineExecutor = new PipelineExecutor(runSpace,this, Script);
pipelineExecutor.OnDataReady += new PipelineExecutor.DataReadyDelegate(pipelineExecutor_OnDataReady);
pipelineExecutor.OnDataEnd += new PipelineExecutor.DataEndDelegate(pipelineExecutor_OnDataEnd);
pipelineExecutor.OnErrorReady += new PipelineExecutor.ErrorReadyDelegate(pipelineExecutor_OnErrorReady);
pipelineExecutor.Start();
private void pipelineExecutor_OnDataEnd(PipelineExecutor sender)
{
if (sender.Pipeline.PipelineStateInfo.State == PipelineState.Failed)
{
AppendLine(string.Format("Error in script: {0}", sender.Pipeline.PipelineStateInfo.Reason));
}
else
{
AppendLine("Ready.");
}
}
private void pipelineExecutor_OnDataReady(PipelineExecutor sender, ICollection<PSObject> data)
{
foreach (PSObject obj in data)
{
AppendLine(obj.ToString());
}
}
void pipelineExecutor_OnErrorReady(PipelineExecutor sender, ICollection<object> data)
{
foreach (object e in data)
{
AppendLine("Error : " + e.ToString());
}
}
PipelineExecutor class file
public PipelineExecutor(Runspace runSpace,ISynchronizeInvoke invoker,string command)
{
this.invoker = invoker;
synchDataReady = new DataReadyDelegate(SynchDataReady);
synchDataEnd = new DataEndDelegate(SynchDataEnd);
synchErrorReady = new ErrorReadyDelegate(SynchErrorReady);
stopEvent = new ManualResetEvent(false);
waitHandles = new WaitHandle[] { null, stopEvent };
pipeline = runSpace.CreatePipeline(command);
pipeline.Output.DataReady += new EventHandler(Output_DataReady);
pipeline.Error.DataReady += new EventHandler(Error_DataReady);
}
void Error_DataReady(object sender, EventArgs e)
{
Collection<object> data = pipeline.Error.NonBlockingRead();
if (data.Count > 0)
{
StoppableInvoke(synchErrorReady, new object[] { this, data });
}
}
public void Start()
{
if (pipeline.PipelineStateInfo.State == PipelineState.NotStarted)
{
pipeline.Input.Close();
pipeline.InvokeAsync();
}
}
What I have tried:
tried same code above. It Throws an error as "
Error 25 The best overloaded method match for 'Codeproject.PowerShell.PipelineExecutor.PipelineExecutor(System.Management.Automation.Runspaces.Runspace, System.ComponentModel.ISynchronizeInvoke, string)' has some invalid arguments
"