Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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;

           // initialize delegates
           synchDataReady = new DataReadyDelegate(SynchDataReady);
           synchDataEnd = new DataEndDelegate(SynchDataEnd);
           synchErrorReady = new ErrorReadyDelegate(SynchErrorReady);

           // initialize event members
           stopEvent = new ManualResetEvent(false);
           waitHandles = new WaitHandle[] { null, stopEvent };
           // create a pipeline and feed it the script text
           pipeline = runSpace.CreatePipeline(command);

           // we'll listen for script output data by way of the DataReady event
           pipeline.Output.DataReady += new EventHandler(Output_DataReady);
           pipeline.Error.DataReady += new EventHandler(Error_DataReady);
       }

       void Error_DataReady(object sender, EventArgs e)
       {
           // fetch all available objects
           Collection<object> data = pipeline.Error.NonBlockingRead();

           // if there were any, invoke the ErrorReady event
           if (data.Count > 0)
           {
               StoppableInvoke(synchErrorReady, new object[] { this, data });
           }
       }

       /// <summary>
       /// Start executing the script in the background.
       /// </summary>
       public void Start()
       {
           if (pipeline.PipelineStateInfo.State == PipelineState.NotStarted)
           {
               // close the pipeline input. If you forget to do
               // this it won't start processing the script.
               pipeline.Input.Close();
               // invoke the pipeline. This will cause it to process the script in the background.
               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	 
"
Posted
Comments
CHill60 10-Apr-17 4:16am    
The error is quite clear - you are attempting to create a new PipelineExecutor but have not supplied the correct parameters
vinodh muthusamy 10-Apr-17 4:52am    
No i have passed Input parameter correctly.

Can you say how parameter mismatch.
CHill60 10-Apr-17 5:17am    
"No i have passed Input parameter correctly." - No, you haven't.
"Can you say how parameter mismatch." - Yes ... 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
vinodh muthusamy 11-Apr-17 2:14am    
private Runspace runSpace;

string Script = "java -jar D:\\jenkins-cli.jar -s http://172.16...:8080/ create-job test12 < C:\\Projects\\sample\\xml\\Test12.xml";

This is the input i have passed for this piplelineExecutor
pipelineExecutor = new PipelineExecutor(runSpace, this, Script);


whether i need to change any code here?
CHill60 11-Apr-17 4:45am    
I'm guess runSpace is a System.Management.Automation.Runspaces.Runspace?
I can see that Script is a string.
Is this a System.ComponentModel.ISynchronizeInvoke ? Probably not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900