void Pipeline_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { switch (e.InvocationStateInfo.State) { case PSInvocationState.Completed: this.SetJobState(JobState.Completed); break; case PSInvocationState.Failed: this.SetJobState(JobState.Failed); break; case PSInvocationState.NotStarted: this.SetJobState(JobState.NotStarted); break; case PSInvocationState.Running: this.SetJobState(JobState.Running); break; case PSInvocationState.Stopped: this.SetJobState(JobState.Stopped); break; case PSInvocationState.Stopping: this.SetJobState(JobState.Stopping); break; } if (e.InvocationStateInfo.State == PSInvocationState.Completed) { Thread t = new Thread(GetData); t.Start(); } }
private void HandlePowerShellInvocationStateChanged( object sender, PSInvocationStateChangedEventArgs eventArgs) { using (ServerPowerShellDriver.tracer.TraceMethod()) { PSInvocationState state = eventArgs.InvocationStateInfo.State; switch (state) { case PSInvocationState.Stopping: this.remoteHost.ServerMethodExecutor.AbortAllCalls(); break; case PSInvocationState.Stopped: case PSInvocationState.Completed: case PSInvocationState.Failed: this.SendRemainingData(); if (state == PSInvocationState.Completed && this.extraPowerShell != null && !this.extraPowerShellAlreadyScheduled) { this.extraPowerShellAlreadyScheduled = true; this.Start(false); break; } this.dsHandler.RaiseRemoveAssociationEvent(); this.dsHandler.SendStateChangedInformationToClient(eventArgs.InvocationStateInfo); break; } } }
private void PowershellHostControl1_InvocationStateChanged(object sender, System.Management.Automation.PSInvocationStateChangedEventArgs e) { switch (e.InvocationStateInfo.State) { case PSInvocationState.Running: break; case PSInvocationState.Failed: Environment.ExitCode = 1; Trace.WriteLine("InvocationStateChanged -> Failed", "Form"); ButtonN.Enabled = true; ButtonN.Text = "Finished"; ButtonN.Focus(); break; case PSInvocationState.Completed: case PSInvocationState.Disconnected: case PSInvocationState.Stopping: case PSInvocationState.NotStarted: case PSInvocationState.Stopped: default: Trace.WriteLine("InvocationStateChanged -> Finished Successfully!", "Form"); Environment.ExitCode = PowershellHostControl1.ExitCode; // Special Case, if the user passed the -silent switch, then just close the form foreach (var Arg in PowershellHostControl1.ParsedParameters) { if (Arg.Name != null) { if (Arg.Name.ToString().ToLower() == "verbose") { if ((bool)Arg.Value) { Trace.WriteLine("User passed in Verbose on the command line, do not auto-exit.", "Form"); ButtonN.Enabled = true; ButtonN.Text = "Finished"; ButtonN.Focus(); return; } } } } Trace.WriteLine("All done, close the form.", "Form"); this.Close(); break; } }
private void PowerShellInstance_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { switch (e.InvocationStateInfo.State) { case PSInvocationState.Completed: case PSInvocationState.Disconnected: case PSInvocationState.Failed: case PSInvocationState.NotStarted: case PSInvocationState.Stopped: base.StatusHandler.TaskCompleted(e.InvocationStateInfo.Reason != null ? e.InvocationStateInfo.Reason.HResult : 0); break; //case PSInvocationState.Running: //case PSInvocationState.Stopping: default: break; } }
private void HandlePowerShellInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs eventArgs) { PSInvocationState state = eventArgs.InvocationStateInfo.State; switch (state) { case PSInvocationState.Stopping: this.remoteHost.ServerMethodExecutor.AbortAllCalls(); return; case PSInvocationState.Stopped: case PSInvocationState.Completed: case PSInvocationState.Failed: if (!this.localPowerShell.RunningExtraCommands) { this.SendRemainingData(); if (((state == PSInvocationState.Completed) && (this.extraPowerShell != null)) && !this.extraPowerShellAlreadyScheduled) { this.extraPowerShellAlreadyScheduled = true; this.Start(false); } else { this.dsHandler.RaiseRemoveAssociationEvent(); this.dsHandler.SendStateChangedInformationToClient(eventArgs.InvocationStateInfo); this.UnregisterPowerShellEventHandlers(this.localPowerShell); if (this.extraPowerShell != null) { this.UnregisterPowerShellEventHandlers(this.extraPowerShell); } this.UnregisterDataStructureHandlerEventHandlers(this.dsHandler); this.UnregisterPipelineOutputEventHandlers(this.localPowerShellOutput); } return; } return; } }
private void HandleInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { SetPipelineState((PipelineState)e.InvocationStateInfo.State, e.InvocationStateInfo.Reason); RaisePipelineStateEvents(); }
void scriptExecuter_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { if (e.InvocationStateInfo.State == PSInvocationState.Completed) { _executePS1Blocker.Set(); } }
/// <summary> /// Handle state changed information from PowerShell /// and send it to the client /// </summary> /// <param name="sender">sender of this event</param> /// <param name="eventArgs">arguments describing state changed /// information for this powershell</param> private void HandlePowerShellInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs eventArgs) { PSInvocationState state = eventArgs.InvocationStateInfo.State; switch (state) { case PSInvocationState.Completed: case PSInvocationState.Failed: case PSInvocationState.Stopped: { if (LocalPowerShell.RunningExtraCommands) { // If completed successfully then allow extra commands to run. if (state == PSInvocationState.Completed) { return; } // For failed or stopped state, extra commands cannot run and // we allow this command invocation to finish. } // send the remaining data before sending in // state information. This is required because // the client side runspace pool will remove // the association with the client side powershell // once the powershell reaches a terminal state. // If the association is removed, then any data // sent to the powershell will be discarded by // the runspace pool data structure handler on the client side SendRemainingData(); if (state == PSInvocationState.Completed && (_extraPowerShell != null) && !_extraPowerShellAlreadyScheduled) { _extraPowerShellAlreadyScheduled = true; Start(false); } else { DataStructureHandler.RaiseRemoveAssociationEvent(); // send the state change notification to the client DataStructureHandler.SendStateChangedInformationToClient( eventArgs.InvocationStateInfo); UnregisterPowerShellEventHandlers(LocalPowerShell); if (_extraPowerShell != null) { UnregisterPowerShellEventHandlers(_extraPowerShell); } UnregisterDataStructureHandlerEventHandlers(DataStructureHandler); UnregisterPipelineOutputEventHandlers(_localPowerShellOutput); // BUGBUG: currently the local powershell cannot // be disposed as raising the events is // not done towards the end. Need to fix // powershell in order to get this enabled //localPowerShell.Dispose(); } } break; case PSInvocationState.Stopping: { // abort all pending host calls _remoteHost.ServerMethodExecutor.AbortAllCalls(); } break; } }
/// <summary> /// This event handler is called when the pipeline state is changed. /// If the state change is to Completed, it issues a message /// asking the user to exit the program. /// </summary> /// <param name="sender">Unused</param> /// <param name="e">The PowerShell state information.</param> static void Powershell_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { Console.WriteLine("PowerShell state changed: state: {0}\n", e.InvocationStateInfo.State); if (e.InvocationStateInfo.State == PSInvocationState.Completed) { Console.WriteLine("Processing completed, press a key to exit!"); } }
private void InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { if (e.InvocationStateInfo.State != this.InvocationState.State || e.InvocationStateInfo.Reason != this.InvocationState.Reason) { NotifyOfPropertyChange(() => InvocationState); } }
/// <summary> /// Raises a PooledJobInvocationStateChanged event when the nested Powershell instance raises an PSInvocationStateChanged event. /// </summary> /// <param name="sender">The nested PowerShell instance that raised the InvocationStateChanged event.</param> /// <param name="e">A PSInvocationStateChangedEventArgs object that represents the new state of the nested PowerShell object.</param> protected virtual void _OnInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { EventHandler<PSInvocationStateChangedEventArgs> handler = PooledJobInvocationStateChanged; if (handler != null) handler(this, e); }
private void HandlePowerShellInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { if (e.InvocationStateInfo.State == PSInvocationState.Completed || e.InvocationStateInfo.State == PSInvocationState.Stopped || e.InvocationStateInfo.State == PSInvocationState.Failed) { PowerShell powershell = sender as PowerShell; powershell.InvocationStateChanged -= HandlePowerShellInvocationStateChanged; Runspace runspace = powershell.GetRunspaceConnection() as Runspace; runspace.Close(); runspace.Dispose(); } }
private void HandleInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { SetPipelineState((PipelineState)e.InvocationStateInfo.State, e.InvocationStateInfo.Reason); RaisePipelineStateEvents(); }
void powerShellCommand_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { if (e.InvocationStateInfo.State == PSInvocationState.Failed) { ErrorRecord err = new ErrorRecord(e.InvocationStateInfo.Reason, "PowerShellDataSource.TerminatingError", ErrorCategory.InvalidOperation, powerShellCommand); powerShellCommand.Streams.Error.Add(err); } if (Dispatcher != null) { RunOnUIThread( new DispatcherOperationCallback( delegate { NotifyInvocationStateChanged(); return null; }), true); } else { NotifyInvocationStateChanged(); } }
private void HandlePowerShellInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs eventArgs) { PSInvocationState state = eventArgs.InvocationStateInfo.State; switch (state) { case PSInvocationState.Stopping: this.remoteHost.ServerMethodExecutor.AbortAllCalls(); return; case PSInvocationState.Stopped: case PSInvocationState.Completed: case PSInvocationState.Failed: if (!this.localPowerShell.RunningExtraCommands) { this.SendRemainingData(); if (((state == PSInvocationState.Completed) && (this.extraPowerShell != null)) && !this.extraPowerShellAlreadyScheduled) { this.extraPowerShellAlreadyScheduled = true; this.Start(false); } else { this.dsHandler.RaiseRemoveAssociationEvent(); this.dsHandler.SendStateChangedInformationToClient(eventArgs.InvocationStateInfo); this.UnregisterPowerShellEventHandlers(this.localPowerShell); if (this.extraPowerShell != null) { this.UnregisterPowerShellEventHandlers(this.extraPowerShell); } this.UnregisterDataStructureHandlerEventHandlers(this.dsHandler); this.UnregisterPipelineOutputEventHandlers(this.localPowerShellOutput); } return; } return; } }
/// <summary> /// Synchronizes Job State with Background Runspace /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void powerShellCommand_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { try { if (e.InvocationStateInfo.State == PSInvocationState.Completed) { runspace.Close(); } if (e.InvocationStateInfo.State == PSInvocationState.Failed) { ErrorRecord err = new ErrorRecord(e.InvocationStateInfo.Reason, "JobFailed", ErrorCategory.OperationStopped, this); Error.Add(err); runspace.Close(); } JobState js = (JobState)Enum.Parse(typeof(JobState), e.InvocationStateInfo.State.ToString(), true); this.SetJobState(js); } catch { } }
private void PowerShellOnInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs psInvocationStateChangedEventArgs) { switch (psInvocationStateChangedEventArgs.InvocationStateInfo.State) { case PSInvocationState.Stopped: ReleasePowerShell(); _pool.ReportStopped(this); break; case PSInvocationState.Completed: case PSInvocationState.Failed: ResetPowerShell(); _pool.ReportAvailable(this); break; } }
private void PowerShellPipeLine_InvocationStateChanged(object sender, PSInvocationStateChangedEventArgs e) { _pipeLineState = e.InvocationStateInfo.State.ToString(); }
/// <summary> /// Handle state changed information from PowerShell /// and send it to the client /// </summary> /// <param name="sender">sender of this event</param> /// <param name="eventArgs">arguments describing state changed /// information for this powershell</param> private void HandlePowerShellInvocationStateChanged(object sender, PSInvocationStateChangedEventArgs eventArgs) { PSInvocationState state = eventArgs.InvocationStateInfo.State; switch (state) { case PSInvocationState.Completed: case PSInvocationState.Failed: case PSInvocationState.Stopped: { if (LocalPowerShell.RunningExtraCommands) { // If completed successfully then allow extra commands to run. if (state == PSInvocationState.Completed) { return; } // For failed or stopped state, extra commands cannot run and // we allow this command invocation to finish. } // send the remaining data before sending in // state information. This is required because // the client side runspace pool will remove // the association with the client side powershell // once the powershell reaches a terminal state. // If the association is removed, then any data // sent to the powershell will be discarded by // the runspace pool data structure handler on the client side SendRemainingData(); if (state == PSInvocationState.Completed && (_extraPowerShell != null) && !_extraPowerShellAlreadyScheduled) { _extraPowerShellAlreadyScheduled = true; Start(false); } else { DataStructureHandler.RaiseRemoveAssociationEvent(); // send the state change notification to the client DataStructureHandler.SendStateChangedInformationToClient( eventArgs.InvocationStateInfo); UnregisterPowerShellEventHandlers(LocalPowerShell); if (_extraPowerShell != null) { UnregisterPowerShellEventHandlers(_extraPowerShell); } UnregisterDataStructureHandlerEventHandlers(DataStructureHandler); UnregisterPipelineOutputEventHandlers(_localPowerShellOutput); // BUGBUG: currently the local powershell cannot // be disposed as raising the events is // not done towards the end. Need to fix // powershell in order to get this enabled //localPowerShell.Dispose(); } } break; case PSInvocationState.Stopping: { // abort all pending host calls _remoteHost.ServerMethodExecutor.AbortAllCalls(); } break; } }